def _get_key_help(self, key, state): page = self.screen.get_visible_page() originating_plugin = page.originating_plugin if originating_plugin: import gnome15.g15pluginmanager as g15pluginmanager actions = g15pluginmanager.get_actions( g15pluginmanager.get_module_for_id( originating_plugin.__module__), self.screen.device) active_profile = g15profile.get_active_profile( self.screen.driver.device ) if self.screen.driver is not None else None for action_id in actions: # First try the active profile to see if the action has been re-mapped action_binding = active_profile.get_binding_for_action( state, action_id) if action_binding is None: # No other keys bound to action, try the device defaults device_info = g15devices.get_device_info( self.screen.driver.get_model_name()) if action_id in device_info.action_keys: action_binding = device_info.action_keys[action_id] if action_binding is not None and key in action_binding.keys: return actions[action_id] return "?"
def show_menu(self): active_profile = g15profile.get_active_profile(self.screen.device) g15plugin.G15MenuPlugin.show_menu(self) if active_profile: item = find(lambda m: m.profile == active_profile, self.menu.get_children()) if item: self.menu.set_selected_item(item)
def action_performed(self, binding): if self.page != None: if binding.action == SELECT_PROFILE: self.screen.raise_page(self.page) elif self.page.is_visible(): if binding.action == g15driver.VIEW: active = g15profile.get_active_profile(self.screen.device) if active.id == self.menu.selected.profile.id: g15profile.set_locked( self.screen.device, not g15profile.is_locked(self.screen.device)) else: if g15profile.is_locked(self.screen.device): g15profile.set_locked(self.screen.device, False) self.menu.selected.profile.make_active() g15profile.set_locked(self.screen.device, True) return True elif binding.action == g15driver.CLEAR: profile = self.menu.selected.profile if self.screen.service.active_application_name is not None: self._configure_profile_with_window_name( profile, self.screen.service.active_application_name) profile.save() elif self.screen.service.active_window_title is not None: self._configure_profile_with_window_name( profile, self.screen.service.active_window_title) profile.save() return True
def _done_recording(self, state): if self._record_keys != None: record_keys = self._record_keys self._halt_recorder() active_profile = g15profile.get_active_profile(self._screen.device) key_name = ", ".join(g15driver.get_key_names(record_keys)) if len(self._script_model) == 0: self.icon = "edit-delete" self._message = key_name + " deleted" active_profile.delete_macro(state, self._screen.get_memory_bank(), record_keys) self._screen.redraw(self._page) else: macro_script = "" for row in self._script_model: if len(macro_script) != 0: macro_script += "\n" macro_script += row[0] + " " + row[1] self.icon = "tag-new" self._message = key_name + " created" memory = self._screen.get_memory_bank() macro = active_profile.get_macro(state, memory, record_keys) if macro: macro.type = g15profile.MACRO_SCRIPT macro.macro = macro_script macro.save() else: active_profile.create_macro(memory, record_keys, key_name, g15profile.MACRO_SCRIPT, macro_script, state) self._redraw() self._hide_recorder(3.0) else: self._hide_recorder()
def _get_theme_properties(self): active_profile = g15profile.get_active_profile(self._screen.device) properties = {} properties["icon"] = g15icontools.get_icon_path( self.icon, self._screen.height) properties["memory"] = "M%d" % self._screen.get_memory_bank() if active_profile != None: properties["profile"] = active_profile.name properties["profile_icon"] = active_profile.get_profile_icon_path( self._screen.height) if self._message == None: properties["message"] = _( "Recording on M%s. Type in your macro then press the G-Key to assign it to, or MR to cancel." % self._screen.get_memory_bank()) else: properties["message"] = self._message else: properties["profile"] = _("No Profile") properties["profile_icon"] = "" properties["message"] = _( "You have no profiles configured. Configure one now using the Macro tool" ) return properties
def _get_key_help(self, key, state): page = self.screen.get_visible_page() originating_plugin = page.originating_plugin if originating_plugin: import gnome15.g15pluginmanager as g15pluginmanager actions = g15pluginmanager.get_actions(g15pluginmanager.get_module_for_id(originating_plugin.__module__), self.screen.device) active_profile = g15profile.get_active_profile(self.screen.driver.device) if self.screen.driver is not None else None for action_id in actions: # First try the active profile to see if the action has been re-mapped action_binding = active_profile.get_binding_for_action(state, action_id) if action_binding is None: # No other keys bound to action, try the device defaults device_info = g15devices.get_device_info(self.screen.driver.get_model_name()) if action_id in device_info.action_keys: action_binding = device_info.action_keys[action_id] if action_binding is not None and key in action_binding.keys: return actions[action_id] return "?"
def _get_theme_properties(self): active_profile = g15profile.get_active_profile(self._screen.device) properties = {} properties["icon"] = g15icontools.get_icon_path(self.icon, self._screen.height) properties["memory"] = "M%d" % self._screen.get_memory_bank() if active_profile != None: properties["profile"] = active_profile.name properties["profile_icon"] = active_profile.get_profile_icon_path(self._screen.height) if self._message == None: properties["message"] = _("Recording on M%s. Type in your macro then press the G-Key to assign it to, or MR to cancel." % self._screen.get_memory_bank()) else: properties["message"] = self._message else: properties["profile"] = _("No Profile") properties["profile_icon"] = "" properties["message"] = _("You have no profiles configured. Configure one now using the Macro tool") return properties
def action_performed(self, binding): if self.page != None: if binding.action == SELECT_PROFILE: self.screen.raise_page(self.page) elif self.page.is_visible(): if binding.action == g15driver.VIEW: active = g15profile.get_active_profile(self.screen.device) if active.id == self.menu.selected.profile.id: g15profile.set_locked(self.screen.device, not g15profile.is_locked(self.screen.device)) else: if g15profile.is_locked(self.screen.device): g15profile.set_locked(self.screen.device, False) self.menu.selected.profile.make_active() g15profile.set_locked(self.screen.device, True) return True elif binding.action == g15driver.CLEAR: profile = self.menu.selected.profile if self.screen.service.active_application_name is not None: self._configure_profile_with_window_name(profile, self.screen.service.active_application_name) profile.save() elif self.screen.service.active_window_title is not None: self._configure_profile_with_window_name(profile, self.screen.service.active_window_title) profile.save() return True
def _get_configuration(self): self._mkey = self.screen.get_memory_bank() self._active_profile = g15profile.get_active_profile( self.screen.device)
def _do_config_changed(self): # Get the configuration screen_size = self.screen.size self.bg_img = None bg_type = self.gconf_client.get_string(self.gconf_key + "/type") if bg_type == None: bg_type = "desktop" bg_style = self.gconf_client.get_string(self.gconf_key + "/style") if bg_style == None: bg_style = "zoom" allow_profile_override = g15gconf.get_bool_or_default( self.gconf_client, self.gconf_key + "/allow_profile_override", True) # See if the current profile has a background if allow_profile_override: active_profile = g15profile.get_active_profile(self.screen.device) if active_profile is not None and active_profile.background is not None and active_profile.background != "": self.bg_img = active_profile.background if self.bg_img == None and bg_type == "desktop": # Get the current background the desktop is using if possible desktop_env = g15desktop.get_desktop() if desktop_env in ["gnome", "gnome-shell"]: if self.gnome_dconf_settings is not None: self.bg_img = self.gnome_dconf_settings.get_string( "picture-uri") else: self.bg_img = self.gconf_client.get_string( "/desktop/gnome/background/picture_filename") else: logger.warning( "User request wallpaper from the desktop, but the desktop environment is unknown. Please report this bug to the Gnome15 project" ) if self.bg_img == None: # Use the file self.bg_img = self.gconf_client.get_string(self.gconf_key + "/path") # Fallback to the default provided image if self.bg_img == None: self.bg_img = os.path.join( os.path.dirname(__file__), "background-%dx%d.png" % (screen_size[0], screen_size[1])) # Load the image if self.bg_img != self.this_image or bg_style != self.current_style: self.this_image = self.bg_img self.current_style = bg_style if g15cairo.is_url(self.bg_img) or os.path.exists(self.bg_img): """ TODO handle background themes and transitions from XML files properly For now, just get the first static image """ if self.bg_img.endswith(".xml"): filet = etree.parse( self.bg_img).getroot().findtext('.//file') if filet: self.bg_img = filet img_surface = g15cairo.load_surface_from_file(self.bg_img) if img_surface is not None: sx = float(screen_size[0]) / img_surface.get_width() sy = float(screen_size[1]) / img_surface.get_height() surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, screen_size[0], screen_size[1]) context = cairo.Context(surface) context.save() if bg_style == "zoom": scale = max(sx, sy) context.scale(scale, scale) context.set_source_surface(img_surface) context.paint() elif bg_style == "stretch": context.scale(sx, sy) context.set_source_surface(img_surface) context.paint() elif bg_style == "scale": x = (screen_size[0] - img_surface.get_width() * sy) / 2 context.translate(x, 0) context.scale(sy, sy) context.set_source_surface(img_surface) context.paint() elif bg_style == "center": x = (screen_size[0] - img_surface.get_width()) / 2 y = (screen_size[1] - img_surface.get_height()) / 2 context.translate(x, y) context.set_source_surface(img_surface) context.paint() elif bg_style == "tile": context.set_source_surface(img_surface) context.paint() y = 0 x = img_surface.get_width() while y < screen_size[1] + img_surface.get_height(): if x >= screen_size[1] + img_surface.get_width(): x = 0 y += img_surface.get_height() context.restore() context.save() context.translate(x, y) context.set_source_surface(img_surface) context.paint() x += img_surface.get_width() context.restore() self.painter.background_image = surface else: self.painter.background_image = None else: self.painter.background_image = None self.painter.brightness = self.gconf_client.get_int(self.gconf_key + "/brightness") self.screen.redraw()
def _do_config_changed(self): # Get the configuration screen_size = self.screen.size self.bg_img = None bg_type = self.gconf_client.get_string(self.gconf_key + "/type") if bg_type == None: bg_type = "desktop" bg_style = self.gconf_client.get_string(self.gconf_key + "/style") if bg_style == None: bg_style = "zoom" allow_profile_override = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/allow_profile_override", True) # See if the current profile has a background if allow_profile_override: active_profile = g15profile.get_active_profile(self.screen.device) if active_profile is not None and active_profile.background is not None and active_profile.background != "": self.bg_img = active_profile.background if self.bg_img == None and bg_type == "desktop": # Get the current background the desktop is using if possible desktop_env = g15desktop.get_desktop() if desktop_env in [ "gnome", "gnome-shell" ]: if self.gnome_dconf_settings is not None: self.bg_img = self.gnome_dconf_settings.get_string("picture-uri") else: self.bg_img = self.gconf_client.get_string("/desktop/gnome/background/picture_filename") else: logger.warning("User request wallpaper from the desktop, but the desktop environment is unknown. Please report this bug to the Gnome15 project") if self.bg_img == None: # Use the file self.bg_img = self.gconf_client.get_string(self.gconf_key + "/path") # Fallback to the default provided image if self.bg_img == None: self.bg_img = os.path.join(os.path.dirname(__file__), "background-%dx%d.png" % ( screen_size[0], screen_size[1] ) ) # Load the image if self.bg_img != self.this_image or bg_style != self.current_style: self.this_image = self.bg_img self.current_style = bg_style if g15cairo.is_url(self.bg_img) or os.path.exists(self.bg_img): """ TODO handle background themes and transitions from XML files properly For now, just get the first static image """ if self.bg_img.endswith(".xml"): filet = etree.parse(self.bg_img).getroot().findtext('.//file') if filet: self.bg_img = filet img_surface = g15cairo.load_surface_from_file(self.bg_img) if img_surface is not None: sx = float(screen_size[0]) / img_surface.get_width() sy = float(screen_size[1]) / img_surface.get_height() surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, screen_size[0], screen_size[1]) context = cairo.Context(surface) context.save() if bg_style == "zoom": scale = max(sx, sy) context.scale(scale, scale) context.set_source_surface(img_surface) context.paint() elif bg_style == "stretch": context.scale(sx, sy) context.set_source_surface(img_surface) context.paint() elif bg_style == "scale": x = ( screen_size[0] - img_surface.get_width() * sy ) / 2 context.translate(x, 0) context.scale(sy, sy) context.set_source_surface(img_surface) context.paint() elif bg_style == "center": x = ( screen_size[0] - img_surface.get_width() ) / 2 y = ( screen_size[1] - img_surface.get_height() ) / 2 context.translate(x, y) context.set_source_surface(img_surface) context.paint() elif bg_style == "tile": context.set_source_surface(img_surface) context.paint() y = 0 x = img_surface.get_width() while y < screen_size[1] + img_surface.get_height(): if x >= screen_size[1] + img_surface.get_width(): x = 0 y += img_surface.get_height() context.restore() context.save() context.translate(x, y) context.set_source_surface(img_surface) context.paint() x += img_surface.get_width() context.restore() self.painter.background_image = surface else: self.painter.background_image = None else: self.painter.background_image = None self.painter.brightness = self.gconf_client.get_int(self.gconf_key + "/brightness") self.screen.redraw()
def _get_configuration(self): self._mkey = self.screen.get_memory_bank() self._active_profile = g15profile.get_active_profile(self.screen.device)