def talking_status_changed(self, talking): """ Current talking buddy has changed. Keyword arguments: talking -- new buddy talking """ if (self._talking is None and talking is not None) or \ (talking is None and self._talking is not None) or \ (talking is not None and talking != self._talking): self._talking = talking if self._backlight_acq is not None and self._talking is None: self.screen.driver.release_control(self._backlight_acq) self._backlight_acq = None if self._talking is not None: hex_color = g15gconf.get_string_or_default( self.gconf_client, get_backlight_key(self.gconf_key, self._talking), "") if hex_color != "": if self._backlight_acq is None: self._backlight_acq = self.screen.driver.acquire_control( self._backlight_ctrl) self._backlight_acq.set_value(g15convert.to_rgb(hex_color)) self.redraw() if g15gconf.get_bool_or_default( self.gconf_client, "%s/raise_on_talk_status_change" % self.gconf_key, False): self._popup()
def __init__(self, gconf_client, gconf_key, screen, backend, buddy, ctrl, plugin): g15theme.G15Page.__init__(self, _("Backlight"), screen, priority=g15screen.PRI_HIGH, \ theme=g15theme.G15Theme(os.path.join(g15globals.themes_dir, "default"), "menu-screen"), originating_plugin = plugin) self.theme_properties = { "title": _("Backlight"), "icon": backend.get_icon() if buddy.avatar is None else buddy.avatar, "alt_title": buddy.nickname } self.menu = g15theme.Menu("menu") self.get_screen().add_page(self) self.add_child(self.menu) self.ctrl = ctrl self.acq = None sel_color = g15convert.to_rgb( g15gconf.get_string_or_default(gconf_client, get_backlight_key(gconf_key, buddy), "255,255,255")) for i, c in enumerate(colorpicker.COLORS_FULL): c = (c[0], c[1], c[2]) item = ColorMenuItem(gconf_client, gconf_key, c, colorpicker.COLORS_NAMES[i], buddy, backend) self.menu.add_child(item) if c == sel_color: self.menu.set_selected_item(item) self.menu.on_selected = self._handle_selected self.on_deleted = self._release_control self.menu.add_child(ReturnMenuItem()) self.add_child(g15theme.MenuScrollbar("viewScrollbar", self.menu)) self._handle_selected()
def __init__(self, gconf_client, gconf_key, screen, backend, buddy, ctrl, plugin): g15theme.G15Page.__init__(self, _("Backlight"), screen, priority=g15screen.PRI_HIGH, \ theme=g15theme.G15Theme(os.path.join(g15globals.themes_dir, "default"), "menu-screen"), originating_plugin = plugin) self.theme_properties = { "title": _("Backlight"), "icon": backend.get_icon() if buddy.avatar is None else buddy.avatar, "alt_title": buddy.nickname } self.menu = g15theme.Menu("menu") self.get_screen().add_page(self) self.add_child(self.menu) self.ctrl = ctrl self.acq = None sel_color = g15convert.to_rgb(g15gconf.get_string_or_default( gconf_client, get_backlight_key(gconf_key, buddy), "255,255,255")) for i, c in enumerate(colorpicker.COLORS_FULL): c = (c[0], c[1], c[2]) item = ColorMenuItem(gconf_client, gconf_key, c, colorpicker.COLORS_NAMES[i], buddy, backend) self.menu.add_child(item) if c == sel_color: self.menu.set_selected_item(item) self.menu.on_selected = self._handle_selected self.on_deleted = self._release_control self.menu.add_child(ReturnMenuItem()) self.add_child(g15theme.MenuScrollbar("viewScrollbar", self.menu)) self._handle_selected()
def _notify(self): if len(self._message_queue) != 0: message = self._message_queue[0] # Which theme variant should we use self._last_variant = "" if message.body is None or message.body == "": self._last_variant = "nobody" self._current_message = message # Get the page if self._page is None: page_sequence_number = self._service.CreatePage( "NotifyLCD", "Notification Message", g15screen.PRI_HIGH) self._page = self._bus.get_object( 'org.gnome15.Gnome15', '/org/gnome15/Page%d' % page_sequence_number) self._reload_theme() else: self._reload_theme() self._page.Raise() self._page.SetThemeProperties(self._get_properties()) self._start_timer(message) self._do_redraw() # Play sound if self._get_enable_sounds( ) and "sound-file" in message.hints and ( not "suppress-sound" in message.hints or not message.hints["suppress-sound"]): print("WARNING: Will play sound", message.hints["sound-file"]) os.system("aplay '%s' &" % message.hints["sound-file"]) if self._gconf_client.get_bool(self._gconf_key + "/blink_keyboard"): delay = gconf_client.get(gconf_key + "/blink_delay") blink_delay = delay.get_int() if delay is not None else 500 self._driver.BlinkKeyboard( float(blink_delay) / 1000.0, 3.0, []) if self._gconf_client.get_bool(self._gconf_key + "/change_keyboard_color"): color = gconf_client.get_string(gconf_key + "/color") self._driver.BlinkKeyboard( 0.0, 3.0, (128, 128, 128) if color is None else g15convert.to_rgb(color))
def talking_status_changed(self, talking): """ Current talking buddy has changed. Keyword arguments: talking -- new buddy talking """ if (self._talking is None and talking is not None) or \ (talking is None and self._talking is not None) or \ (talking is not None and talking != self._talking): self._talking = talking if self._backlight_acq is not None and self._talking is None: self.screen.driver.release_control(self._backlight_acq) self._backlight_acq = None if self._talking is not None: hex_color = g15gconf.get_string_or_default(self.gconf_client, get_backlight_key(self.gconf_key, self._talking), "") if hex_color != "": if self._backlight_acq is None: self._backlight_acq = self.screen.driver.acquire_control(self._backlight_ctrl) self._backlight_acq.set_value(g15convert.to_rgb(hex_color)) self.redraw() if g15gconf.get_bool_or_default(self.gconf_client, "%s/raise_on_talk_status_change" % self.gconf_key, False): self._popup()
def _notify(self): if len(self._message_queue) != 0: message = self._message_queue[0] # Which theme variant should we use self._last_variant = "" if message.body == None or message.body == "": self._last_variant = "nobody" self._current_message = message # Get the page if self._page == None: page_sequence_number = self._service.CreatePage("NotifyLCD", "Notification Message", g15screen.PRI_HIGH) self._page = self._bus.get_object('org.gnome15.Gnome15', '/org/gnome15/Page%d' % page_sequence_number) self._reload_theme() else: self._reload_theme() self._page.Raise() self._page.SetThemeProperties(self._get_properties()) self._start_timer(message) self._do_redraw() # Play sound if self._get_enable_sounds() and "sound-file" in message.hints and ( not "suppress-sound" in message.hints or not message.hints["suppress-sound"]): print "WARNING: Will play sound",message.hints["sound-file"] os.system("aplay '%s' &" % message.hints["sound-file"]) if self._gconf_client.get_bool(self._gconf_key + "/blink_keyboard"): delay = gconf_client.get(gconf_key + "/blink_delay") blink_delay = delay.get_int() if delay != None else 500 self._driver.BlinkKeyboard(float(blink_delay) / 1000.0, 3.0, []) if self._gconf_client.get_bool(self._gconf_key + "/change_keyboard_color"): color = gconf_client.get_string(gconf_key + "/color") self._driver.BlinkKeyboard(0.0, 3.0, (128, 128, 128) if color == None else g15convert.to_rgb(color))
def load(self, filename = None, fd = None): """ Load the profile from disk """ # Initial values self.macros = { g15driver.KEY_STATE_UP: [], g15driver.KEY_STATE_DOWN: [], g15driver.KEY_STATE_HELD: [] } self.mkey_color = {} # Load macro file if self.id != -1 or filename is not None or fd is not None: if ( isinstance(filename, str) or isinstance(filename, str) ) and os.path.exists(filename): self.read_only = not os.stat(filename)[0] & stat.S_IWRITE self.parser.readfp(codecs.open(filename, "r", "utf8")) elif fd is not None: self.read_only = True self.parser.readfp(fd) else: self.read_only = False # Macro file format version. Try to keep macro files backwardly and # forwardly compatible if self.parser.has_option("DEFAULT", "version"): self.version = float(self.parser.get("DEFAULT", "version").strip()) else: self.version = 1.0 # Info section self.name = self.parser.get("DEFAULT", "name").strip() if self.parser.has_option("DEFAULT", "name") else "" self.icon = self.parser.get("DEFAULT", "icon").strip() if self.parser.has_option("DEFAULT", "icon") else "" self.background = self.parser.get("DEFAULT", "background").strip() if self.parser.has_option("DEFAULT", "background") else "" self.author = self.parser.get("DEFAULT", "author").strip() if self.parser.has_option("DEFAULT", "author") else "" self.window_name = self.parser.get("DEFAULT", "window_name").strip() if self.parser.has_option("DEFAULT", "window_name") else "" self.models = self.parser.get("DEFAULT", "models").strip().split(",") if self.parser.has_option("DEFAULT", "models") else [ self.device.model_id ] self.plugins_mode = self.parser.get("DEFAULT", "plugins_mode").strip() if self.parser.has_option("DEFAULT", "plugins_mode") else ALL_PLUGINS self.selected_plugins = self.parser.get("DEFAULT", "selected_plugins").strip().split(",") \ if self.parser.has_option("DEFAULT", "selected_plugins") else [ ] self.activate_on_focus = self.parser.getboolean("DEFAULT", "activate_on_focus") if self.parser.has_option("DEFAULT", "activate_on_focus") else False self.send_delays = self.parser.getboolean("DEFAULT", "send_delays") if self.parser.has_option("DEFAULT", "send_delays") else False self.fixed_delays = self.parser.getboolean("DEFAULT", "fixed_delays") if self.parser.has_option("DEFAULT", "fixed_delays") else False self.base_profile = self.parser.get("DEFAULT", "base_profile").strip() if self.parser.has_option("DEFAULT", "base_profile") else "" if self.base_profile == "-1": # For version 1.0 profile format compatibility self.base_profile = None self.press_delay = self._get_int("press_delay", 50) self.release_delay = self._get_int("release_delay", 50) # Launch self.launch_pattern = self.parser.get("LAUNCH", "pattern").strip() \ if self.parser.has_option("LAUNCH", "pattern") else None self.monitor = self.parser.get("LAUNCH", "monitor").strip().split(",") \ if self.parser.has_option("LAUNCH", "monitor") else [ "stdout" ] self.activate_on_launch = self.parser.getboolean("LAUNCH", "activate_on_launch") \ if self.parser.has_option("LAUNCH", "activate_on_launch") else False # Bank sections for activate_on in [ g15driver.KEY_STATE_UP, g15driver.KEY_STATE_DOWN, g15driver.KEY_STATE_HELD ]: for i in range(1, 4): section_name = "m%d" % i if activate_on != g15driver.KEY_STATE_UP: section_name = "%s-%s" % ( section_name, activate_on ) if not self.parser.has_section(section_name): self.parser.add_section(section_name) self.mkey_color[i] = g15convert.to_rgb(self.parser.get(section_name, "backlight_color")) if self.parser.has_option(section_name, "backlight_color") else None memory_macros = [] self.macros[activate_on].append(memory_macros) for option in self.parser.options(section_name): if option.startswith("keys_") and option.endswith("_name"): key_list_key = option[5:-5] macro_obj = G15Macro(self, i, key_list_key, activate_on) macro_obj._load() memory_macros.append(macro_obj)
def to_rgb(string_rgb, default=None): return g15convert.to_rgb(string_rgb, default)