71 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
| # pass
 | |
| 
 | |
| from . import (notify, status_icon, main_window, pair_window, action)
 | |
| 
 | |
| from gi.repository import (GObject, Gtk)
 | |
| GObject.threads_init()
 | |
| 
 | |
| 
 | |
| from solaar import NAME as _NAME
 | |
| _APP_ICONS = (_NAME + '-fail', _NAME + '-init', _NAME)
 | |
| def appicon(receiver_status):
 | |
| 	return (_APP_ICONS[0] if receiver_status < 0 else
 | |
| 			_APP_ICONS[1] if receiver_status < 1 else
 | |
| 			_APP_ICONS[2])
 | |
| 
 | |
| 
 | |
| _ICON_THEME = Gtk.IconTheme.get_default()
 | |
| 
 | |
| def get_icon(name, fallback):
 | |
| 	return name if name and _ICON_THEME.has_icon(name) else fallback
 | |
| 
 | |
| def icon_file(name):
 | |
| 	if name and _ICON_THEME.has_icon(name):
 | |
| 		return _ICON_THEME.lookup_icon(name, 0, 0).get_filename()
 | |
| 	return None
 | |
| 
 | |
| 
 | |
| def show_permissions_warning(window):
 | |
| 	text = ('Found a possible Unifying Receiver device,\n'
 | |
| 			'but did not have permission to open it.')
 | |
| 
 | |
| 	m = Gtk.MessageDialog(window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, text)
 | |
| 	m.set_title('Permissions error')
 | |
| 	m.run()
 | |
| 	m.destroy()
 | |
| 
 | |
| 
 | |
| def find_children(container, *child_names):
 | |
| 	assert container is not None
 | |
| 
 | |
| 	def _iterate_children(widget, names, result, count):
 | |
| 		wname = widget.get_name()
 | |
| 		if wname in names:
 | |
| 			index = names.index(wname)
 | |
| 			names[index] = None
 | |
| 			result[index] = widget
 | |
| 			count -= 1
 | |
| 
 | |
| 		if count > 0 and isinstance(widget, Gtk.Container):
 | |
| 			for w in widget:
 | |
| 				count = _iterate_children(w, names, result, count)
 | |
| 				if count == 0:
 | |
| 					break
 | |
| 
 | |
| 		return count
 | |
| 
 | |
| 	names = list(child_names)
 | |
| 	count = len(names)
 | |
| 	result = [None] * count
 | |
| 	_iterate_children(container, names, result, count)
 | |
| 	return tuple(result) if count > 1 else result[0]
 | |
| 
 | |
| 
 | |
| def update(receiver, icon, window, reason):
 | |
| 	assert receiver is not None
 | |
| 	assert reason is not None
 | |
| 	if window:
 | |
| 		GObject.idle_add(main_window.update, window, receiver, reason)
 | |
| 	if icon:
 | |
| 		GObject.idle_add(status_icon.update, icon, receiver)
 |