def load_configuration(self): self.take_over_macro_keys = g15gconf.get_bool_or_default( self.gconf_client, "%s/take_over_macro_keys" % self.gconf_key, True) if g15gconf.get_bool_or_default( self.gconf_client, "%s/use_custom_foreground" % self.gconf_key, False): col = g15gconf.get_rgb_or_default( self.gconf_client, "%s/custom_foreground" % self.gconf_key, (255, 255, 255)) self.palette = [0 for n in range(768)] self.palette[765] = col[0] self.palette[766] = col[1] self.palette[767] = col[2] else: foreground_control = self.screen.driver.get_control("foreground") if foreground_control is None: self.palette = None else: self.palette = [0 for n in range(768)] self.palette[765] = foreground_control.value[0] self.palette[766] = foreground_control.value[1] self.palette[767] = foreground_control.value[2] backlight_control = self.screen.driver.get_control_for_hint( g15driver.HINT_DIMMABLE) self.default_backlight = backlight_control.value if backlight_control is not None else None lcd_brightness_control = self.screen.driver.get_control_for_hint( g15driver.HINT_SHADEABLE) self.default_lcd_brightness = lcd_brightness_control.value if lcd_brightness_control is not None else None
def _load_configuration(self): self.respect_timeout = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/respect_timeout", False) self.allow_actions = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/allow_actions", False) self.allow_cancel = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/allow_cancel", True) self.on_keyboard_screen = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/on_keyboard_screen", True) self.on_desktop = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/on_desktop", True) self.blink_keyboard_backlight = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/blink_keyboard_backlight", True) self.blink_memory_bank = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/blink_memory_bank", True) self.change_keyboard_backlight_color = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/change_keyboard_backlight_color", False) self.enable_sounds = g15gconf.get_bool_or_default( self._gconf_client, self._gconf_key + "/enable_sounds", True) self.blink_delay = g15gconf.get_int_or_default( self._gconf_client, self._gconf_key + "/blink_delay", 500) self.keyboard_backlight_color = g15gconf.get_rgb_or_default( self._gconf_client, self._gconf_key + "/keyboard_backlight_color", (128, 128, 128))
def _load_surfaces(self): self.display_date = g15gconf.get_bool_or_default(self.gconf_client, "%s/display_date" % self.gconf_key, True) self.display_seconds = g15gconf.get_bool_or_default(self.gconf_client, "%s/display_seconds" % self.gconf_key, True) self.display_date = g15gconf.get_bool_or_default(self.gconf_client, "%s/display_date" % self.gconf_key, True) self.display_year = g15gconf.get_bool_or_default(self.gconf_client, "%s/display_year" % self.gconf_key, True) self.display_digital_time = g15gconf.get_bool_or_default(self.gconf_client, "%s/display_digital_time" % self.gconf_key, True) self.second_sweep = g15gconf.get_bool_or_default(self.gconf_client, "%s/second_sweep" % self.gconf_key, False) self.twenty_four_hour = g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour" % self.gconf_key, False) self.twenty_four_hour_digital = g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_digital" % self.gconf_key, True) self.gconf_client.get_bool(self.gconf_key + "/twenty_four_hour") self.svg_size = None self.width = self.screen.width self.height = self.screen.height theme = self.gconf_client.get_string(self.gconf_key + "/theme") if theme == None: theme = "default" self.clock_theme_dir = get_theme_dir(self.screen.driver.get_model_name(), self.gconf_key, self.gconf_client, theme) if not self.clock_theme_dir: self.clock_theme_dir = get_theme_dir(self.screen.driver.get_model_name(), self.gconf_key, self.gconf_client, "default") if not self.clock_theme_dir: raise Exception("No themes could be found.") self.behind_hands = self._load_surface_list(["clock-drop-shadow", "clock-face", "clock-marks"]) self.hour_surfaces = self._load_surface_list(["clock-hour-hand-shadow", "clock-hour-hand"]) self.minute_surfaces = self._load_surface_list(["clock-minute-hand-shadow", "clock-minute-hand"]) self.second_surfaces = self._load_surface_list(["clock-secondhand-shadow", "clock-second-hand"]) self.above_hands = self._load_surface_list([ "clock-face-shadow", "clock-glass", "clock-frame" ])
def _load_configuration(self): self.respect_timeout = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/respect_timeout", False) self.allow_actions = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/allow_actions", False) self.allow_cancel = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/allow_cancel", True) self.on_keyboard_screen = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/on_keyboard_screen", True) self.on_desktop = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/on_desktop", True) self.blink_keyboard_backlight = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/blink_keyboard_backlight", True) self.blink_memory_bank = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/blink_memory_bank", True) self.change_keyboard_backlight_color = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/change_keyboard_backlight_color", False) self.enable_sounds = g15gconf.get_bool_or_default(self._gconf_client, self._gconf_key + "/enable_sounds", True) self.blink_delay = g15gconf.get_int_or_default(self._gconf_client, self._gconf_key + "/blink_delay", 500) self.keyboard_backlight_color = g15gconf.get_rgb_or_default(self._gconf_client, self._gconf_key + "/keyboard_backlight_color", ( 128, 128, 128 ))
def _popup(self): if not self.page.is_visible() and g15gconf.get_bool_or_default( self.gconf_client, "%s/raise" % self.gconf_key, True): self._raise_timer = self.screen.set_priority(self.page, g15screen.PRI_HIGH, revert_after=4.0) self.screen.redraw(self.page)
def memory_bank_changed(self, new_bank_number): self.plugin._get_configuration() self.plugin._reload() if g15gconf.get_bool_or_default(self.plugin.gconf_client, "%s/raise" % self.plugin.gconf_key, True): self.plugin._popup()
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 _popup(self): self._check_status() if g15gconf.get_bool_or_default(self.gconf_client,"%s/raise" % self.gconf_key, True): if not self.page.is_visible(): self._raise_timer = self.screen.set_priority(self.page, g15screen.PRI_HIGH, revert_after = 4.0) self.screen.redraw(self.page) else: self._reset_raise()
def _set_panel(self, client=None, connection_id=None, entry=None, args=None): self.page.panel_painter = self._paint_panel \ if g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/show_cpu_on_panel", True) \ else None
def is_locked(device): """ Get if the active profile is "locked" or if it may be changed for the specified device. Keyword arguments: device -- device associated with profile """ return g15gconf.get_bool_or_default(conf_client, "/apps/gnome15/%s/locked" % device.uid, False)
def _check_page(self): if self._in_screensaver: if self._screen.driver.get_bpp() != 0 and self._page == None: self._reload_theme() self._page = g15theme.G15Page(id, self._screen, priority = g15screen.PRI_EXCLUSIVE, \ title = name, theme = self._theme, theme_properties_callback = self._get_theme_properties, originating_plugin = self) self._page.key_handlers.append(self) self._screen.add_page(self._page) self._screen.redraw(self._page) if not self.dimmed and g15gconf.get_bool_or_default(self._gconf_client, "%s/dim_keyboard" % self._gconf_key, True): self._dim_keyboard() else: if self._screen.driver.get_bpp() != 0: self._remove_page() if self.dimmed and g15gconf.get_bool_or_default(self._gconf_client,"%s/dim_keyboard" % self._gconf_key, True): self._light_keyboard()
def _load_configuration(self): self.use_vnstat = g15gconf.get_bool_or_default( self.gconf_client, self.gconf_key + "/use_vnstat", os.path.isfile("/usr/bin/vnstat")) self.networkdevice = g15gconf.get_string_or_default( self.gconf_client, self.gconf_key + "/networkdevice", 'lo') self.loadpage = g15gconf.get_string_or_default( self.gconf_client, self.gconf_key + "/vnstat_view", "vnstat_daily") self.refresh_interval = g15gconf.get_float_or_default( self.gconf_client, self.gconf_key + "/refresh_interval", 10.0)
def reload_model(self): self.sensor_model.clear() ss = get_sensor_sources() for source in ss: sa = source.get_sensors() for sensor in sa: sense_key = "%s/sensors/%s" % (self._gconf_key, gconf.escape_key(sensor.name, len(sensor.name))) if sensor.sense_type in TYPE_NAMES: self.sensor_model.append([ sensor.name, g15gconf.get_bool_or_default(self._gconf_client, "%s/enabled" % (sense_key), True), g15gconf.get_string_or_default(self._gconf_client, "%s/label" % (sense_key), sensor.name), TYPE_NAMES[sensor.sense_type] ]) source.stop()
def _load_surfaces(self): self.display_date = g15gconf.get_bool_or_default( self.gconf_client, "%s/display_date" % self.gconf_key, True) self.display_seconds = g15gconf.get_bool_or_default( self.gconf_client, "%s/display_seconds" % self.gconf_key, True) self.display_date = g15gconf.get_bool_or_default( self.gconf_client, "%s/display_date" % self.gconf_key, True) self.display_year = g15gconf.get_bool_or_default( self.gconf_client, "%s/display_year" % self.gconf_key, True) self.display_digital_time = g15gconf.get_bool_or_default( self.gconf_client, "%s/display_digital_time" % self.gconf_key, True) self.second_sweep = g15gconf.get_bool_or_default( self.gconf_client, "%s/second_sweep" % self.gconf_key, False) self.twenty_four_hour = g15gconf.get_bool_or_default( self.gconf_client, "%s/twenty_four_hour" % self.gconf_key, False) self.twenty_four_hour_digital = g15gconf.get_bool_or_default( self.gconf_client, "%s/twenty_four_hour_digital" % self.gconf_key, True) self.gconf_client.get_bool(self.gconf_key + "/twenty_four_hour") self.svg_size = None self.width = self.screen.width self.height = self.screen.height theme = self.gconf_client.get_string(self.gconf_key + "/theme") if theme is None: theme = "default" self.clock_theme_dir = get_theme_dir( self.screen.driver.get_model_name(), self.gconf_key, self.gconf_client, theme) if not self.clock_theme_dir: self.clock_theme_dir = get_theme_dir( self.screen.driver.get_model_name(), self.gconf_key, self.gconf_client, "default") if not self.clock_theme_dir: raise Exception("No themes could be found.") self.behind_hands = self._load_surface_list( ["clock-drop-shadow", "clock-face", "clock-marks"]) self.hour_surfaces = self._load_surface_list( ["clock-hour-hand-shadow", "clock-hour-hand"]) self.minute_surfaces = self._load_surface_list( ["clock-minute-hand-shadow", "clock-minute-hand"]) self.second_surfaces = self._load_surface_list( ["clock-secondhand-shadow", "clock-second-hand"]) self.above_hands = self._load_surface_list( ["clock-face-shadow", "clock-glass", "clock-frame"])
def _get_properties(self): now = datetime.datetime.now() calendar_date = self._get_calendar_date() properties = {} properties["icon"] = self._icon_path properties["title"] = _('Calendar') if g15gconf.get_bool_or_default( self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True): properties["time"] = g15locale.format_time_24hour( now, self.gconf_client, False) properties["full_time"] = g15locale.format_time_24hour( now, self.gconf_client, True) else: properties["full_time"] = g15locale.format_time( now, self.gconf_client, True) properties["time"] = g15locale.format_time(now, self.gconf_client, False) properties["time_24"] = now.strftime("%H:%M") properties["full_time_24"] = now.strftime("%H:%M:%S") properties["time_12"] = now.strftime("%I:%M %p") properties["full_time_12"] = now.strftime("%I:%M:%S %p") properties["short_date"] = now.strftime("%a %d %b") properties["full_date"] = now.strftime("%A %d %B") properties["date"] = g15locale.format_date(now, self.gconf_client) properties["locale_date"] = now.strftime("%x") properties["locale_time"] = now.strftime("%X") properties["year"] = now.strftime("%Y") properties["short_year"] = now.strftime("%y") properties["week"] = now.strftime("%W") properties["month"] = now.strftime("%m") properties["month_name"] = now.strftime("%B") properties["short_month_name"] = now.strftime("%b") properties["day_name"] = now.strftime("%A") properties["short_day_name"] = now.strftime("%a") properties["day_of_year"] = now.strftime("%d") properties["cal_year"] = calendar_date.strftime("%Y") properties["cal_month"] = calendar_date.strftime("%m") properties["cal_month_name"] = calendar_date.strftime("%B") properties["cal_short_month_name"] = calendar_date.strftime("%b") properties["cal_year"] = calendar_date.strftime("%Y") properties["cal_short_year"] = calendar_date.strftime("%y") properties["cal_locale_date"] = calendar_date.strftime("%x") if self._event_days is None or not str( calendar_date.day) in self._event_days: properties["message"] = "No events" properties["events"] = False else: properties["events"] = True properties["message"] = "" return properties
def load_configuration(self): self.take_over_macro_keys = g15gconf.get_bool_or_default(self.gconf_client, "%s/take_over_macro_keys" % self.gconf_key, True) if g15gconf.get_bool_or_default(self.gconf_client, "%s/use_custom_foreground" % self.gconf_key, False): col = g15gconf.get_rgb_or_default(self.gconf_client, "%s/custom_foreground" % self.gconf_key, (255,255,255)) self.palette = [0 for n in range(768)] self.palette[765] = col[0] self.palette[766] = col[1] self.palette[767] = col[2] else: foreground_control = self.screen.driver.get_control("foreground") if foreground_control is None: self.palette = None else: self.palette = [0 for n in range(768)] self.palette[765] = foreground_control.value[0] self.palette[766] = foreground_control.value[1] self.palette[767] = foreground_control.value[2] backlight_control = self.screen.driver.get_control_for_hint(g15driver.HINT_DIMMABLE) self.default_backlight = backlight_control.value if backlight_control is not None else None lcd_brightness_control = self.screen.driver.get_control_for_hint(g15driver.HINT_SHADEABLE) self.default_lcd_brightness = lcd_brightness_control.value if lcd_brightness_control is not None else None
def get_theme_properties(self): use_twenty_four_hour = g15gconf.get_bool_or_default( self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True) element_properties = g15theme.MenuItem.get_theme_properties(self) element_properties["ent_title"] = self.entry.title element_properties["ent_link"] = self.entry.link if g15pythonlang.attr_exists(self.entry, "description"): element_properties["ent_description"] = self.entry.description if hasattr(self.entry, 'date_parsed'): dt = self.entry.date_parsed elif hasattr(self.entry, 'published_parsed'): logger.debug( "Could not get date_parsed attribute. Trying published_parsed") dt = self.entry.published_parsed else: logger.debug( "Could not get publish_parsed attribute. Using current time.") dt = time.localtime() element_properties["ent_locale_date_time"] = time.strftime("%x %X", dt) element_properties["ent_locale_time"] = time.strftime("%X", dt) element_properties["ent_locale_date"] = time.strftime("%x", dt) element_properties["ent_time_24"] = time.strftime("%H:%M", dt) if use_twenty_four_hour: element_properties["ent_time"] = g15locale.format_time_24hour( time, self.gconf_client, False) else: element_properties["ent_time"] = g15locale.format_time( time, self.gconf_client, False) element_properties["ent_full_time_24"] = time.strftime("%H:%M:%S", dt) if use_twenty_four_hour: element_properties["ent_full_time"] = g15locale.format_time_24hour( time, self.gconf_client, True) else: element_properties["ent_full_time"] = g15locale.format_time( time, self.gconf_client, True) element_properties["ent_time_12"] = time.strftime("%I:%M %p", dt) element_properties["ent_full_time_12"] = time.strftime( "%I:%M:%S %p", dt) element_properties["ent_short_date"] = time.strftime("%a %d %b", dt) element_properties["ent_full_date"] = time.strftime("%A %d %B", dt) element_properties["ent_month_year"] = time.strftime("%m/%y", dt) return element_properties
def populate_page(self): self._menu = g15theme.Menu("menu") g15plugin.G15RefreshingPlugin.populate_page(self) enabled_sensors = [] for c in self.sensor_sources: for s in c.get_sensors(): sense_key = "%s/sensors/%s" % ( self.gconf_key, GConf.escape_key(s.name, len(s.name))) if g15gconf.get_bool_or_default(self.gconf_client, "%s/enabled" % (sense_key), True): enabled_sensors.append(s) # If there are no sensors enabled, display the 'none' variant # which shows a message if len(enabled_sensors) == 0: self.page.theme.set_variant("none") else: self.page.theme.set_variant(None) def menu_selected(): self.page.theme.set_variant( VARIANT_NAMES[self._menu.selected.sensor.sense_type]) self._menu.on_selected = menu_selected self.page.add_child(self._menu) self.page.theme.svg_processor = self._process_svg self.page.add_child( g15theme.MenuScrollbar("viewScrollbar", self._menu)) i = 0 for s in enabled_sensors: if s.sense_type in TYPE_NAMES: sense_key = "%s/sensors/%s" % ( self.gconf_key, GConf.escape_key(s.name, len(s.name))) sense_label = g15gconf.get_string_or_default( self.gconf_client, "%s/label" % (sense_key), s.name) menu_item = SensorMenuItem("menuitem-%d" % i, s, sense_label) self.sensor_dict[s.name] = menu_item self._menu.add_child(menu_item) # If this is the first child, change the theme variant if self._menu.get_child_count() == 1: self.page.theme.set_variant( VARIANT_NAMES[menu_item.sensor.sense_type]) i += 1
def message_received(self, sender, message, highlight = False): """ Add a message to the message list Keyword arguments: sender -- sender message -- message """ if self.message_menu is not None: while self.message_menu.get_child_count() > 20: self.message_menu.remove_child_at(0) self.message_menu.add_child(MessageMenuItem(sender, message, highlight)) self.message_menu.select_last_item() self.page.mark_dirty() if g15gconf.get_bool_or_default(self.gconf_client, "%s/raise_on_chat_message" % self.gconf_key, False): self._popup()
def _translate_icon(self, icon, fallback_icon): theme_icon = icon if theme_icon == None or theme_icon == "": return None else: if not g15gconf.get_bool_or_default(self.gconf_client, "%s/use_theme_icons" % self.gconf_key, True): return fallback_icon if theme_icon != None: icon_path = g15icontools.get_icon_path(theme_icon, warning = False, include_missing = False) if icon_path == None and theme_icon.endswith("-night"): icon_path = g15icontools.get_icon_path(theme_icon[:len(theme_icon) - 6], include_missing = False) if icon_path != None: return icon_path return g15icontools.get_icon_path(icon)
def _get_properties(self): now = datetime.datetime.now() calendar_date = self._get_calendar_date() properties = {} properties["icon"] = self._icon_path properties["title"] = _('Calendar') if g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True): properties["time"] = g15locale.format_time_24hour(now, self.gconf_client, False) properties["full_time"] = g15locale.format_time_24hour(now, self.gconf_client, True) else: properties["full_time"] = g15locale.format_time(now, self.gconf_client, True) properties["time"] = g15locale.format_time(now, self.gconf_client, False) properties["time_24"] = now.strftime("%H:%M") properties["full_time_24"] = now.strftime("%H:%M:%S") properties["time_12"] = now.strftime("%I:%M %p") properties["full_time_12"] = now.strftime("%I:%M:%S %p") properties["short_date"] = now.strftime("%a %d %b") properties["full_date"] = now.strftime("%A %d %B") properties["date"] = g15locale.format_date(now, self.gconf_client) properties["locale_date"] = now.strftime("%x") properties["locale_time"] = now.strftime("%X") properties["year"] = now.strftime("%Y") properties["short_year"] = now.strftime("%y") properties["week"] = now.strftime("%W") properties["month"] = now.strftime("%m") properties["month_name"] = now.strftime("%B") properties["short_month_name"] = now.strftime("%b") properties["day_name"] = now.strftime("%A") properties["short_day_name"] = now.strftime("%a") properties["day_of_year"] = now.strftime("%d") properties["cal_year"] = calendar_date.strftime("%Y") properties["cal_month"] = calendar_date.strftime("%m") properties["cal_month_name"] = calendar_date.strftime("%B") properties["cal_short_month_name"] = calendar_date.strftime("%b") properties["cal_year"] = calendar_date.strftime("%Y") properties["cal_short_year"] = calendar_date.strftime("%y") properties["cal_locale_date"] = calendar_date.strftime("%x") if self._event_days is None or not str(calendar_date.day) in self._event_days: properties["message"] = "No events" properties["events"] = False else: properties["events"] = True properties["message"] = "" return properties
def message_received(self, sender, message, highlight=False): """ Add a message to the message list Keyword arguments: sender -- sender message -- message """ if self.message_menu is not None: while self.message_menu.get_child_count() > 20: self.message_menu.remove_child_at(0) self.message_menu.add_child( MessageMenuItem(sender, message, highlight)) self.message_menu.select_last_item() self.page.mark_dirty() if g15gconf.get_bool_or_default( self.gconf_client, "%s/raise_on_chat_message" % self.gconf_key, False): self._popup()
def populate_page(self): self._menu = g15theme.Menu("menu") g15plugin.G15RefreshingPlugin.populate_page(self) enabled_sensors = [] for c in self.sensor_sources: for s in c.get_sensors(): sense_key = "%s/sensors/%s" % (self.gconf_key, gconf.escape_key(s.name, len(s.name))) if g15gconf.get_bool_or_default(self.gconf_client, "%s/enabled" % (sense_key), True): enabled_sensors.append(s) # If there are no sensors enabled, display the 'none' variant # which shows a message if len(enabled_sensors) == 0: self.page.theme.set_variant("none") else: self.page.theme.set_variant(None) def menu_selected(): self.page.theme.set_variant(VARIANT_NAMES[self._menu.selected.sensor.sense_type]) self._menu.on_selected = menu_selected self.page.add_child(self._menu) self.page.theme.svg_processor = self._process_svg self.page.add_child(g15theme.MenuScrollbar("viewScrollbar", self._menu)) i = 0 for s in enabled_sensors: if s.sense_type in TYPE_NAMES: sense_key = "%s/sensors/%s" % (self.gconf_key, gconf.escape_key(s.name, len(s.name))) sense_label = g15gconf.get_string_or_default(self.gconf_client, "%s/label" % (sense_key), s.name) menu_item = SensorMenuItem("menuitem-%d" % i, s, sense_label) self.sensor_dict[s.name] = menu_item self._menu.add_child(menu_item) # If this is the first child, change the theme variant if self._menu.get_child_count() == 1: self.page.theme.set_variant(VARIANT_NAMES[menu_item.sensor.sense_type]) i += 1
def get_theme_properties(self): use_twenty_four_hour = g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True) element_properties = g15theme.MenuItem.get_theme_properties(self) element_properties["ent_title"] = self.entry.title element_properties["ent_link"] = self.entry.link if g15pythonlang.attr_exists(self.entry, "description"): element_properties["ent_description"] = self.entry.description if hasattr(self.entry, 'date_parsed'): dt = self.entry.date_parsed elif hasattr(self.entry, 'published_parsed'): logger.debug("Could not get date_parsed attribute. Trying published_parsed") dt = self.entry.published_parsed else: logger.debug("Could not get publish_parsed attribute. Using current time.") dt = time.localtime() element_properties["ent_locale_date_time"] = time.strftime("%x %X", dt) element_properties["ent_locale_time"] = time.strftime("%X", dt) element_properties["ent_locale_date"] = time.strftime("%x", dt) element_properties["ent_time_24"] = time.strftime("%H:%M", dt) if use_twenty_four_hour: element_properties["ent_time"] = g15locale.format_time_24hour(time, self.gconf_client, False) else: element_properties["ent_time"] = g15locale.format_time(time, self.gconf_client, False) element_properties["ent_full_time_24"] = time.strftime("%H:%M:%S", dt) if use_twenty_four_hour: element_properties["ent_full_time"] = g15locale.format_time_24hour(time, self.gconf_client, True) else: element_properties["ent_full_time"] = g15locale.format_time(time, self.gconf_client, True) element_properties["ent_time_12"] = time.strftime("%I:%M %p", dt) element_properties["ent_full_time_12"] = time.strftime("%I:%M:%S %p", dt) element_properties["ent_short_date"] = time.strftime("%a %d %b", dt) element_properties["ent_full_date"] = time.strftime("%A %d %B", dt) element_properties["ent_month_year"] = time.strftime("%m/%y", dt) return element_properties
def _translate_icon(self, icon, fallback_icon): theme_icon = icon if theme_icon == None or theme_icon == "": return None else: if not g15gconf.get_bool_or_default( self.gconf_client, "%s/use_theme_icons" % self.gconf_key, True): return fallback_icon if theme_icon != None: icon_path = g15icontools.get_icon_path(theme_icon, warning=False, include_missing=False) if icon_path == None and theme_icon.endswith("-night"): icon_path = g15icontools.get_icon_path( theme_icon[:len(theme_icon) - 6], include_missing=False) if icon_path != None: return icon_path return g15icontools.get_icon_path(icon)
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 get_bool_or_default(gconf_client, key, default=None): return g15gconf.get_bool_or_default(gconf_client, key, default)
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 IsCyclingEnabled(self): return g15gconf.get_bool_or_default( self._service.conf_client, "/apps/gnome15/%s/cycle_screens" % self._screen.device.uid, True)
def _load_configuration(self): self.use_vnstat = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/use_vnstat", os.path.isfile("/usr/bin/vnstat")) self.networkdevice = g15gconf.get_string_or_default(self.gconf_client, self.gconf_key + "/networkdevice", 'lo') self.loadpage = g15gconf.get_string_or_default(self.gconf_client, self.gconf_key + "/vnstat_view", "vnstat_daily") self.refresh_interval = g15gconf.get_float_or_default(self.gconf_client, self.gconf_key + "/refresh_interval", 10.0)
def _reload_and_popup(self): self._reload() if g15gconf.get_bool_or_default(self.gconf_client, "%s/raise" % self.gconf_key, True): self._popup()
def _load_config(self): logger.info("Reloading configuration") self.audio_source_index = get_source_index( self.gconf_client.get_string(self.gconf_key + "/audio_source_name")) gobject.idle_add(self.set_audio_source) self.mode = self.gconf_client.get_string(self.gconf_key + "/mode") self.disco = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/disco", False) self.refresh_interval = 1.0 / g15gconf.get_float_or_default( self.gconf_client, self.gconf_key + "/frame_rate", 25.0) self.gain = g15gconf.get_float_or_default(self.gconf_client, self.gconf_key + "/gain", 1.0) logger.info("Refresh interval is %f", self.refresh_interval) self.animate_mkeys = g15gconf.get_bool_or_default( self.gconf_client, self.gconf_key + "/animate_mkeys", False) if self.mode is None or self.mode == "" or self.mode == "spectrum" or self.mode == "scope": self.mode = "default" self.paint_mode = self.gconf_client.get_string(self.gconf_key + "/paint") if self.paint_mode is None or self.mode == "": self.paint_mode = "screen" self._on_load_theme() self.bars = self.gconf_client.get_int(self.gconf_key + "/bars") if self.bars == 0: self.bars = 16 self.bar_width = self.gconf_client.get_int(self.gconf_key + "/bar_width") if self.bar_width == 0: self.bar_width = 16 self.bar_height = self.gconf_client.get_int(self.gconf_key + "/bar_height") if self.bar_height == 0: self.bar_height = 2 self.rows = self.gconf_client.get_int(self.gconf_key + "/rows") if self.rows == 0: self.rows = 16 self.spacing = self.gconf_client.get_int(self.gconf_key + "/spacing") self.col1 = g15gconf.get_cairo_rgba_or_default( self.gconf_client, self.gconf_key + "/col1", (255, 0, 0, 255)) self.col2 = g15gconf.get_cairo_rgba_or_default( self.gconf_client, self.gconf_key + "/col2", (0, 0, 255, 255)) self.peak_heights = [0 for i in range(self.bars)] paint = self.gconf_client.get_string(self.gconf_key + "/paint") if paint != self.last_paint and self.screen.driver.get_bpp() != 0: self.last_paint = paint self._clear_painter() if paint == "screen": if self.page is None: self.page = g15theme.G15Page(id, self.screen, title=name, painter=self.painter.paint, on_shown=self.on_shown, on_hidden=self.on_hidden, originating_plugin=self) self.screen.add_page(self.page) else: self.screen.set_priority(self.page, g15screen.PRI_HIGH, revert_after=3.0) elif paint == "foreground": self.painter.place = g15screen.FOREGROUND_PAINTER self._activate_painter() self.hide_page() elif paint == "background": self.painter.place = g15screen.BACKGROUND_PAINTER self._activate_painter() self.hide_page() # Acquire the backlight control if appropriate control = self.screen.driver.get_control_for_hint( g15driver.HINT_DIMMABLE) if control: if self.disco and self.painter.backlight_acquisition is None: self.painter.backlight_acquisition = self.screen.driver.acquire_control( control) elif not self.disco and self.painter.backlight_acquisition is not None: self.painter._release_backlight_acquisition() # Acquire the M-Key lights control if appropriate if self.animate_mkeys and self.painter.mkey_acquisition is None: self.painter.mkey_acquisition = self.screen.driver.acquire_control_with_hint( g15driver.HINT_MKEYS) elif not self.animate_mkeys and self.painter.mkey_acquisition is not None: self.painter._release_mkey_acquisition()
def _check_page_priority(self): self._priority = g15screen.PRI_EXCLUSIVE if self._is_any_timer_active() and g15gconf.get_bool_or_default(self.gconf_client, "%s/keep_page_visible" % self.gconf_key, True) \ else g15screen.PRI_NORMAL if self.page: self.page.set_priority(self._priority)
def _build_properties(self): properties = {} attributes = {} use_twenty_four_hour = g15gconf.get_bool_or_default( self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True) if self._weather is None: properties["message"] = _("No weather source configuration") else: current = self._weather['current_conditions'] if len(current) == 0: properties["message"] = _("No weather data for location:-\n%s" ) % self._weather['location'] else: properties["location"] = self._weather['location'] dt = self._weather['datetime'] if use_twenty_four_hour: properties["time"] = g15locale.format_time_24hour( dt, self.gconf_client, False) else: properties["time"] = g15locale.format_time( dt, self.gconf_client, False) properties["date"] = g15locale.format_date( dt, self.gconf_client) properties["datetime"] = g15locale.format_date_time( dt, self.gconf_client, False) properties["message"] = "" c_icon, f_icon, t_icon = self._get_icons(current) if t_icon != None: attributes["icon"] = g15cairo.load_surface_from_file( t_icon) properties["icon"] = g15icontools.get_embedded_image_url( attributes["icon"]) else: logger.warning("No translated weather icon for %s", c_icon) mono_thumb = self._get_mono_thumb_icon(c_icon) if mono_thumb != None: attributes[ "mono_thumb_icon"] = g15cairo.load_surface_from_file( os.path.join( os.path.join(os.path.dirname(__file__), "default"), mono_thumb)) properties["condition"] = current['condition'] temp_c = g15pythonlang.to_float_or_none(current['temp_c']) if temp_c is not None: temp_f = c_to_f(temp_c) temp_k = c_to_k(temp_c) low_c = g15pythonlang.to_float_or_none( current['low']) if 'low' in current else None if low_c is not None: low_f = c_to_f(low_c) low_k = c_to_k(low_c) high_c = g15pythonlang.to_float_or_none( current['high']) if 'high' in current else None if high_c is not None: high_f = c_to_f(high_c) high_k = c_to_k(high_c) properties[ "temp_c"] = "%3.1f°C" % temp_c if temp_c is not None else "" properties[ "hi_c"] = "%3.1f°C" % high_c if high_c is not None else "" properties[ "lo_c"] = "%3.1f°C" % low_c if low_c is not None else "" properties[ "temp_f"] = "%3.1f°F" % temp_f if temp_c is not None else "" properties[ "lo_f"] = "%3.1f°F" % low_f if low_c is not None else "" properties[ "high_f"] = "%3.1f°F" % high_f if high_c is not None else "" properties[ "temp_k"] = "%3.1f°K" % temp_k if temp_c is not None else "" properties[ "lo_k"] = "%3.1f°K" % low_k if low_c is not None else "" properties[ "high_k"] = "%3.1f°K" % high_k if high_c is not None else "" units = self.gconf_client.get_int(self.gconf_key + "/units") if units == CELSIUS: unit = "C" properties["temp"] = properties["temp_c"] properties[ "temp_short"] = "%2.0f°" % temp_c if temp_c else "" properties["hi"] = properties["hi_c"] properties[ "hi_short"] = "%2.0f°" % high_c if high_c else "" properties["lo"] = properties["lo_c"] properties["lo_short"] = "%2.0f°" % low_c if low_c else "" elif units == FARANHEIT: unit = "F" properties["lo"] = properties["lo_f"] properties[ "lo_short"] = "%2.0f°" % low_f if low_c is not None else "" properties["hi"] = properties["high_f"] properties[ "hi_short"] = "%2.0f°" % high_f if high_c is not None else "" properties["temp"] = properties["temp_f"] properties[ "temp_short"] = "%2.0f°" % temp_f if temp_c is not None else "" else: unit = "K" properties["lo"] = properties["lo_k"] properties[ "lo_short"] = "%2.0f°" % low_k if low_c is not None else "" properties["hi"] = properties["high_k"] properties[ "hi_short"] = "%2.0f°" % high_k if high_c is not None else "" properties["temp"] = properties["temp_k"] properties[ "temp_short"] = "%2.0f°" % temp_k if temp_c is not None else "" # Wind wind = g15pythonlang.append_if_exists(current, "wind_chill", "", "%sC") wind = g15pythonlang.append_if_exists(current, "wind_speed", wind, "%sKph") wind = g15pythonlang.append_if_exists(current, "wind_direction", wind, "%sdeg") properties["wind"] = wind # Visibility visibility = g15pythonlang.append_if_exists( current, "visibility", "", "%sM") properties["visibility"] = visibility # Pressure pressure = g15pythonlang.append_if_exists( current, "pressure", "", "%smb") properties["pressure"] = pressure # Humidity humidity = g15pythonlang.append_if_exists( current, "humidity", "", "%s%%") properties["humidity"] = humidity # Sunrise dt = current['sunrise'] if 'sunrise' in current else None if dt is None: properties["sunrise_time"] = "" elif use_twenty_four_hour: properties["sunrise_time"] = g15locale.format_time_24hour( dt, self.gconf_client, False) else: properties["sunrise_time"] = g15locale.format_time( dt, self.gconf_client, False) # Sunset dt = current['sunset'] if 'sunset' in current else None if dt is None: properties["sunset_time"] = "" elif use_twenty_four_hour: properties["sunset_time"] = g15locale.format_time_24hour( dt, self.gconf_client, False) else: properties["sunset_time"] = g15locale.format_time( dt, self.gconf_client, False) # Blank all the forecasts by default for y in range(1, 10): properties["condition" + str(y)] = "" properties["hi" + str(y)] = "" properties["lo" + str(y)] = "" properties["day" + str(y)] = "" properties["day_letter" + str(y)] = "" properties["icon" + str(y)] = "" # Forecasts y = 1 if 'forecasts' in self._weather: for forecast in self._weather['forecasts']: properties["condition" + str(y)] = forecast['condition'] lo_c = g15pythonlang.to_float_or_none(forecast['low']) if lo_c is not None: lo_f = c_to_f(temp_c) lo_k = c_to_k(temp_c) hi_c = g15pythonlang.to_float_or_none(forecast['high']) if hi_c is not None: hi_f = c_to_f(hi_c) hi_k = c_to_k(hi_c) if units == CELSIUS: properties["hi" + str(y)] = "%3.0f°C" % hi_c properties["lo" + str(y)] = "%3.0f°C" % lo_c elif units == FARANHEIT: properties["hi" + str(y)] = "%3.0f°F" % hi_f properties["lo" + str(y)] = "%3.0f°F" % lo_f else: properties["hi" + str(y)] = "%3.0f°K" % hi_k properties["lo" + str(y)] = "%3.0f°K" % lo_k properties["day" + str(y)] = forecast['day_of_week'] properties["day_letter" + str(y)] = forecast['day_of_week'][:1] c_icon, f_icon, t_icon = self._get_icons(forecast) properties[ "icon" + str(y)] = g15icontools.get_embedded_image_url( g15cairo.load_surface_from_file(t_icon)) y += 1 return properties, attributes
def _build_properties(self): properties = {} attributes = {} use_twenty_four_hour = g15gconf.get_bool_or_default(self.gconf_client, "%s/twenty_four_hour_times" % self.gconf_key, True) if self._weather is None: properties["message"] = _("No weather source configuration") else: current = self._weather['current_conditions'] if len(current) == 0: properties["message"] = _("No weather data for location:-\n%s") % self._weather['location'] else: properties["location"] = self._weather['location'] dt = self._weather['datetime'] if use_twenty_four_hour: properties["time"] = g15locale.format_time_24hour(dt, self.gconf_client, False) else: properties["time"] = g15locale.format_time(dt, self.gconf_client, False) properties["date"] = g15locale.format_date(dt, self.gconf_client) properties["datetime"] = g15locale.format_date_time(dt, self.gconf_client, False) properties["message"] = "" c_icon, f_icon, t_icon = self._get_icons(current) if t_icon != None: attributes["icon"] = g15cairo.load_surface_from_file(t_icon) properties["icon"] = g15icontools.get_embedded_image_url(attributes["icon"]) else: logger.warning("No translated weather icon for %s", c_icon) mono_thumb = self._get_mono_thumb_icon(c_icon) if mono_thumb != None: attributes["mono_thumb_icon"] = g15cairo.load_surface_from_file(os.path.join(os.path.join(os.path.dirname(__file__), "default"), mono_thumb)) properties["condition"] = current['condition'] temp_c = g15pythonlang.to_float_or_none(current['temp_c']) if temp_c is not None: temp_f = c_to_f(temp_c) temp_k = c_to_k(temp_c) low_c = g15pythonlang.to_float_or_none(current['low']) if 'low' in current else None if low_c is not None : low_f = c_to_f(low_c) low_k = c_to_k(low_c) high_c = g15pythonlang.to_float_or_none(current['high']) if 'high' in current else None if high_c is not None : high_f = c_to_f(high_c) high_k = c_to_k(high_c) properties["temp_c"] = "%3.1f°C" % temp_c if temp_c is not None else "" properties["hi_c"] = "%3.1f°C" % high_c if high_c is not None else "" properties["lo_c"] = "%3.1f°C" % low_c if low_c is not None else "" properties["temp_f"] = "%3.1f°F" % temp_f if temp_c is not None else "" properties["lo_f"] = "%3.1f°F" % low_f if low_c is not None else "" properties["high_f"] = "%3.1f°F" % high_f if high_c is not None else "" properties["temp_k"] = "%3.1f°K" % temp_k if temp_c is not None else "" properties["lo_k"] = "%3.1f°K" % low_k if low_c is not None else "" properties["high_k"] = "%3.1f°K" % high_k if high_c is not None else "" units = self.gconf_client.get_int(self.gconf_key + "/units") if units == CELSIUS: unit = "C" properties["temp"] = properties["temp_c"] properties["temp_short"] = "%2.0f°" % temp_c if temp_c else "" properties["hi"] = properties["hi_c"] properties["hi_short"] = "%2.0f°" % high_c if high_c else "" properties["lo"] = properties["lo_c"] properties["lo_short"] = "%2.0f°" % low_c if low_c else "" elif units == FARANHEIT: unit = "F" properties["lo"] = properties["lo_f"] properties["lo_short"] = "%2.0f°" % low_f if low_c is not None else "" properties["hi"] = properties["high_f"] properties["hi_short"] = "%2.0f°" % high_f if high_c is not None else "" properties["temp"] = properties["temp_f"] properties["temp_short"] = "%2.0f°" % temp_f if temp_c is not None else "" else: unit = "K" properties["lo"] = properties["lo_k"] properties["lo_short"] = "%2.0f°" % low_k if low_c is not None else "" properties["hi"] = properties["high_k"] properties["hi_short"] = "%2.0f°" % high_k if high_c is not None else "" properties["temp"] = properties["temp_k"] properties["temp_short"] = "%2.0f°" % temp_k if temp_c is not None else "" # Wind wind = g15pythonlang.append_if_exists(current, "wind_chill", "", "%sC") wind = g15pythonlang.append_if_exists(current, "wind_speed", wind, "%sKph") wind = g15pythonlang.append_if_exists(current, "wind_direction", wind, "%sdeg") properties["wind"] = wind # Visibility visibility = g15pythonlang.append_if_exists(current, "visibility", "", "%sM") properties["visibility"] = visibility # Pressure pressure = g15pythonlang.append_if_exists(current, "pressure", "", "%smb") properties["pressure"] = pressure # Humidity humidity = g15pythonlang.append_if_exists(current, "humidity", "", "%s%%") properties["humidity"] = humidity # Sunrise dt = current['sunrise'] if 'sunrise' in current else None if dt is None: properties["sunrise_time"] = "" elif use_twenty_four_hour: properties["sunrise_time"] = g15locale.format_time_24hour(dt, self.gconf_client, False) else: properties["sunrise_time"] = g15locale.format_time(dt, self.gconf_client, False) # Sunset dt = current['sunset'] if 'sunset' in current else None if dt is None: properties["sunset_time"] = "" elif use_twenty_four_hour: properties["sunset_time"] = g15locale.format_time_24hour(dt, self.gconf_client, False) else: properties["sunset_time"] = g15locale.format_time(dt, self.gconf_client, False) # Blank all the forecasts by default for y in range(1, 10): properties["condition" + str(y)] = "" properties["hi" + str(y)] = "" properties["lo" + str(y)] = "" properties["day" + str(y)] = "" properties["day_letter" + str(y)] = "" properties["icon" + str(y)] = "" # Forecasts y = 1 if 'forecasts' in self._weather: for forecast in self._weather['forecasts']: properties["condition" + str(y)] = forecast['condition'] lo_c = g15pythonlang.to_float_or_none(forecast['low']) if lo_c is not None: lo_f = c_to_f(temp_c) lo_k = c_to_k(temp_c) hi_c = g15pythonlang.to_float_or_none(forecast['high']) if hi_c is not None: hi_f = c_to_f(hi_c) hi_k = c_to_k(hi_c) if units == CELSIUS: properties["hi" + str(y)] = "%3.0f°C" % hi_c properties["lo" + str(y)] = "%3.0f°C" % lo_c elif units == FARANHEIT: properties["hi" + str(y)] = "%3.0f°F" % hi_f properties["lo" + str(y)] = "%3.0f°F" % lo_f else: properties["hi" + str(y)] = "%3.0f°K" % hi_k properties["lo" + str(y)] = "%3.0f°K" % lo_k properties["day" + str(y)] = forecast['day_of_week'] properties["day_letter" + str(y)] = forecast['day_of_week'][:1] c_icon, f_icon, t_icon = self._get_icons(forecast) properties["icon" + str(y)] = g15icontools.get_embedded_image_url(g15cairo.load_surface_from_file(t_icon)) y += 1 return properties, attributes
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 _load_config(self): logger.info("Reloading configuration") self.audio_source_index = get_source_index(self.gconf_client.get_string(self.gconf_key + "/audio_source_name")) gobject.idle_add(self.set_audio_source) self.mode = self.gconf_client.get_string(self.gconf_key + "/mode") self.disco = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/disco", False) self.refresh_interval = 1.0 / g15gconf.get_float_or_default(self.gconf_client, self.gconf_key + "/frame_rate", 25.0) self.gain = g15gconf.get_float_or_default(self.gconf_client, self.gconf_key + "/gain", 1.0) logger.info("Refresh interval is %f", self.refresh_interval) self.animate_mkeys = g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/animate_mkeys", False) if self.mode == None or self.mode == "" or self.mode == "spectrum" or self.mode == "scope": self.mode = "default" self.paint_mode = self.gconf_client.get_string(self.gconf_key + "/paint") if self.paint_mode == None or self.mode == "": self.paint_mode = "screen" self._on_load_theme() self.bars = self.gconf_client.get_int(self.gconf_key + "/bars") if self.bars == 0: self.bars = 16 self.bar_width = self.gconf_client.get_int(self.gconf_key + "/bar_width") if self.bar_width == 0: self.bar_width = 16 self.bar_height = self.gconf_client.get_int(self.gconf_key + "/bar_height") if self.bar_height == 0: self.bar_height = 2 self.rows = self.gconf_client.get_int(self.gconf_key + "/rows") if self.rows == 0: self.rows = 16 self.spacing = self.gconf_client.get_int(self.gconf_key + "/spacing") self.col1 = g15gconf.get_cairo_rgba_or_default(self.gconf_client, self.gconf_key + "/col1", ( 255, 0, 0, 255 )) self.col2 = g15gconf.get_cairo_rgba_or_default(self.gconf_client, self.gconf_key + "/col2", ( 0, 0, 255, 255 )) self.peak_heights = [ 0 for i in range( self.bars ) ] paint = self.gconf_client.get_string(self.gconf_key + "/paint") if paint != self.last_paint and self.screen.driver.get_bpp() != 0: self.last_paint = paint self._clear_painter() if paint == "screen": if self.page == None: self.page = g15theme.G15Page(id, self.screen, title = name, painter = self.painter.paint, on_shown = self.on_shown, on_hidden = self.on_hidden, originating_plugin = self) self.screen.add_page(self.page) else: self.screen.set_priority(self.page, g15screen.PRI_HIGH, revert_after = 3.0) elif paint == "foreground": self.painter.place = g15screen.FOREGROUND_PAINTER self._activate_painter() self.hide_page() elif paint == "background": self.painter.place = g15screen.BACKGROUND_PAINTER self._activate_painter() self.hide_page() # Acquire the backlight control if appropriate control = self.screen.driver.get_control_for_hint(g15driver.HINT_DIMMABLE) if control: if self.disco and self.painter.backlight_acquisition is None: self.painter.backlight_acquisition = self.screen.driver.acquire_control(control) elif not self.disco and self.painter.backlight_acquisition is not None: self.painter._release_backlight_acquisition() # Acquire the M-Key lights control if appropriate if self.animate_mkeys and self.painter.mkey_acquisition is None: self.painter.mkey_acquisition = self.screen.driver.acquire_control_with_hint(g15driver.HINT_MKEYS) elif not self.animate_mkeys and self.painter.mkey_acquisition is not None: self.painter._release_mkey_acquisition()
def _set_panel(self, client = None, connection_id = None, entry = None, args = None): self.page.panel_painter = self._paint_panel if g15gconf.get_bool_or_default(self.gconf_client, self.gconf_key + "/show_cpu_on_panel", True) else None