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 _read_config(self): self.soundcard_name = g15gconf.get_string_or_default(self._gconf_client, \ self._gconf_key + "/soundcard", \ str(alsaaudio.cards()[0])) self.soundcard_index = alsaaudio.cards().index(self.soundcard_name) self.mixer_name = g15gconf.get_string_or_default(self._gconf_client, \ self._gconf_key + "/mixer", \ str(alsaaudio.mixers(self.soundcard_index)[0])) if not self.mixer_name in alsaaudio.mixers(self.soundcard_index): self.mixer_name = str(alsaaudio.mixers(self.soundcard_index)[0]) self._gconf_client.set_string(self._gconf_key + "/mixer", self.mixer_name)
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 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_weather_data(self): station_id = g15gconf.get_string_or_default(self.gconf_client, "%s/station_id" % self.gconf_key, "KPEO") p = pywapi.get_weather_from_noaa(station_id) tm = email.utils.parsedate_tz(p["observation_time_rfc822"])[:9] data = { "location": p["location"], "datetime": datetime.datetime.fromtimestamp(time.mktime(tm)), "current_conditions": { "wind_speed": g15pythonlang.to_int_or_none(weather.mph_to_kph(float(p["wind_mph"]))) if "wind_mph" in p else None, "wind_direction": g15pythonlang.to_int_or_none(p["wind_degrees"]) if "wind_degrees" in p else None, "pressure": p["pressure_mb"] if "pressure_mb" in p else None, "humidity": p["relative_humidity"] if "relative_humidity" in p else None, "condition": p["weather"] if "weather" in p else None, "temp_c": p["temp_c"] if "temp_c" in p else None, "icon": self._get_icon(p["icon_url_name"]) if "icon_url_name" in p else None, "fallback_icon": "http://w1.weather.gov/images/fcicons/%s" % ("%s.jpg" % os.path.splitext(p["icon_url_name"])[0]) if "icon_url_name" in p else None, }, } return data
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 format_time_24hour(time_val, gconf_client, display_seconds=True, show_timezone=False): """ Format a given time / datetime as a time in the 24hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object / tuple gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format_24hr", locale.nl_langinfo(locale.T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def get_visualisation(plugin): """ Get the currently configured visualisation. Keyword arguments: plugin -- plugin instance """ return g15gconf.get_string_or_default( plugin.gconf_client, "%s/visualisation" % plugin.gconf_key, "goom")
def _find_next_free_filename(self, ext, title): dir_path = g15gconf.get_string_or_default(self._gconf_client, "%s/folder" % \ self._gconf_key, os.path.expanduser("~/Desktop")) for i in range(1, 9999): path = "%s/%s-%s-%d.%s" % ( dir_path, \ g15globals.name, title, i, ext ) if not os.path.exists(path): return path raise Exception("Too many screenshots/videos in destination directory")
def _do_refresh(self): if self._page: self._load_site_data() self._page.redraw() self._schedule_refresh(get_update_time(self._gconf_client, self._gconf_key) * 60.0) selected = g15gconf.get_string_or_default(self._gconf_client, "%s/selected_site" % self._gconf_key, None) if selected: for m in self._menu.get_children(): if m.id == selected: self._menu.set_selected_item(m)
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 action_performed(self, binding): # TODO better key if binding.action == SCREENSHOT: mode = g15gconf.get_string_or_default(self._gconf_client, "%s/mode" % self._gconf_key, "still") if mode == "still": return self._take_still() else: if self._recording: self._stop_recording() else: self._start_recording()
def show_preferences(parent, driver, gconf_client, gconf_key): def refresh_devices(widget): new_soundcard_name = soundcard_model[widget.get_active()][0] new_soundcard_index = alsa_soundcards.index(new_soundcard_name) ''' We temporarily block the handler for the mixer_combo 'changed' signal, since we are going to change the combobox contents. ''' mixer_combo.handler_block(changed_handler_id) mixer_model.clear() for mixer in alsaaudio.mixers(new_soundcard_index): mixer_model.append([mixer]) # Now we can unblock the handler mixer_combo.handler_unblock(changed_handler_id) # And since the list of mixers has changed, we select the first one by default mixer_combo.set_active(0) widget_tree = gtk.Builder() widget_tree.add_from_file( os.path.join(os.path.dirname(__file__), "volume.ui")) dialog = widget_tree.get_object("VolumeDialog") soundcard_combo = widget_tree.get_object('SoundcardCombo') mixer_combo = widget_tree.get_object('MixerCombo') soundcard_model = widget_tree.get_object("SoundcardModel") mixer_model = widget_tree.get_object("MixerModel") alsa_soundcards = alsaaudio.cards() soundcard_name = g15gconf.get_string_or_default(gconf_client, gconf_key + "/soundcard", str(alsa_soundcards[0])) soundcard_index = alsa_soundcards.index(soundcard_name) soundcard_mixers = alsaaudio.mixers(soundcard_index) for card in alsa_soundcards: soundcard_model.append([card]) for mixer in soundcard_mixers: mixer_model.append([mixer]) g15uigconf.configure_combo_from_gconf(gconf_client, \ gconf_key + "/soundcard", \ "SoundcardCombo", \ str(alsa_soundcards[0]), \ widget_tree) changed_handler_id = g15uigconf.configure_combo_from_gconf(gconf_client, \ gconf_key + "/mixer", \ "MixerCombo", \ str(soundcard_mixers[0]), \ widget_tree) soundcard_combo.connect('changed', refresh_devices) dialog.set_transient_for(parent) dialog.run() dialog.hide()
def __init__(self, parent, driver, gconf_client, gconf_key): self.gconf_client = gconf_client self.gconf_key = gconf_key widget_tree = gtk.Builder() widget_tree.add_from_file( os.path.join(os.path.dirname(__file__), "lcdshot.ui")) dialog = widget_tree.get_object("LCDShotDialog") dialog.set_transient_for(parent) chooser = gtk.FileChooserDialog("Open..", None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) chooser_button = widget_tree.get_object("FileChooserButton") chooser_button.dialog = chooser chooser_button.connect("file-set", self._file_set) chooser_button.connect("file-activated", self._file_activated) chooser_button.connect("current-folder-changed", self._file_activated) bg_img = g15gconf.get_string_or_default( self.gconf_client, "%s/folder" % self.gconf_key, os.path.expanduser("~/Desktop")) chooser_button.set_current_folder(bg_img) # Reset the value of the mode setting to 'still' if mencoder is not installed mencoder_is_installed = g15os.is_program_in_path('mencoder') if not mencoder_is_installed: gconf_client.set_string("%s/mode" % self.gconf_key, "still") # Initialize the mode combobox content modes = widget_tree.get_object("ModeModel") modes.clear() modes.append(('still', 'Still', True)) modes.append(('video', 'Video', mencoder_is_installed)) # Display a warning message to the user if mencoder is not installed warning = widget_tree.get_object("NoVideoMessage") warning.set_visible(not mencoder_is_installed) g15uigconf.configure_combo_from_gconf(self.gconf_client, "%s/mode" % self.gconf_key, "Mode", "still", widget_tree) mode = widget_tree.get_object("Mode") mode.connect("changed", self._mode_changed) g15uigconf.configure_spinner_from_gconf(self.gconf_client, "%s/fps" % gconf_key, "FPS", 10, widget_tree, False) self._spinner = widget_tree.get_object("FPS") self._mode_changed(mode) dialog.run() dialog.hide()
def show_preferences(parent, driver, gconf_client, gconf_key): def refresh_devices(widget): new_soundcard_name = soundcard_model[widget.get_active()][0] new_soundcard_index = alsa_soundcards.index(new_soundcard_name) ''' We temporarily block the handler for the mixer_combo 'changed' signal, since we are going to change the combobox contents. ''' mixer_combo.handler_block(changed_handler_id) mixer_model.clear() for mixer in alsaaudio.mixers(new_soundcard_index): mixer_model.append([mixer]) # Now we can unblock the handler mixer_combo.handler_unblock(changed_handler_id) # And since the list of mixers has changed, we select the first one by default mixer_combo.set_active(0) widget_tree = gtk.Builder() widget_tree.add_from_file(os.path.join(os.path.dirname(__file__), "volume.ui")) dialog = widget_tree.get_object("VolumeDialog") soundcard_combo = widget_tree.get_object('SoundcardCombo') mixer_combo = widget_tree.get_object('MixerCombo') soundcard_model = widget_tree.get_object("SoundcardModel") mixer_model = widget_tree.get_object("MixerModel") alsa_soundcards = alsaaudio.cards() soundcard_name = g15gconf.get_string_or_default(gconf_client, gconf_key + "/soundcard", str(alsa_soundcards[0])) soundcard_index = alsa_soundcards.index(soundcard_name) soundcard_mixers = alsaaudio.mixers(soundcard_index) for card in alsa_soundcards: soundcard_model.append([card]) for mixer in soundcard_mixers: mixer_model.append([mixer]) g15uigconf.configure_combo_from_gconf(gconf_client, \ gconf_key + "/soundcard", \ "SoundcardCombo", \ str(alsa_soundcards[0]), \ widget_tree) changed_handler_id = g15uigconf.configure_combo_from_gconf(gconf_client, \ gconf_key + "/mixer", \ "MixerCombo", \ str(soundcard_mixers[0]), \ widget_tree) soundcard_combo.connect('changed', refresh_devices) dialog.set_transient_for(parent) dialog.run() dialog.hide()
def refresh(self): try : backend_type = g15gconf.get_string_or_default(self.gconf_client, "%s/source" % self.gconf_key, None) if backend_type: backend = get_backend(backend_type).create_backend(self.gconf_client, "%s/%s" % (self.gconf_key, backend_type) ) self._weather = backend.get_weather_data() else: self._weather = None self._page_properties, self._page_attributes = self._build_properties() except Exception as e: logger.debug("Error while refreshing", exc_info = e) self._weather = None self._page_properties = {} self._page_attributes = {} self._page_properties['message'] = _("Error parsing weather data!")
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 format_date(date_val, gconf_client): """ Format a datetime as a date (without time). GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: date_val -- date / datetime object gconf_client -- gconf client instance """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/date_format", locale.nl_langinfo(locale.D_FMT)) if isinstance(date_val, tuple): return datetime.date.strftime(fmt, date_val) else: return date_val.strftime(fmt)
def __init__(self, parent, driver, gconf_client, gconf_key): self.gconf_client = gconf_client self.gconf_key = gconf_key widget_tree = gtk.Builder() widget_tree.add_from_file(os.path.join(os.path.dirname(__file__), "lcdshot.ui")) dialog = widget_tree.get_object("LCDShotDialog") dialog.set_transient_for(parent) chooser = gtk.FileChooserDialog("Open..", None, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) chooser.set_default_response(gtk.RESPONSE_OK) chooser_button = widget_tree.get_object("FileChooserButton") chooser_button.dialog = chooser chooser_button.connect("file-set", self._file_set) chooser_button.connect("file-activated", self._file_activated) chooser_button.connect("current-folder-changed", self._file_activated) bg_img = g15gconf.get_string_or_default(self.gconf_client, "%s/folder" % self.gconf_key, os.path.expanduser("~/Desktop")) chooser_button.set_current_folder(bg_img) # Reset the value of the mode setting to 'still' if mencoder is not installed mencoder_is_installed = g15os.is_program_in_path('mencoder') if not mencoder_is_installed: gconf_client.set_string("%s/mode" % self.gconf_key, "still") # Initialize the mode combobox content modes = widget_tree.get_object("ModeModel") modes.clear() modes.append(('still','Still', True)) modes.append(('video','Video', mencoder_is_installed)) # Display a warning message to the user if mencoder is not installed warning = widget_tree.get_object("NoVideoMessage") warning.set_visible(not mencoder_is_installed) g15uigconf.configure_combo_from_gconf(self.gconf_client, "%s/mode" % self.gconf_key, "Mode", "still", widget_tree) mode = widget_tree.get_object("Mode") mode.connect("changed", self._mode_changed) g15uigconf.configure_spinner_from_gconf(self.gconf_client, "%s/fps" % gconf_key, "FPS", 10, widget_tree, False) self._spinner = widget_tree.get_object("FPS") self._mode_changed(mode) dialog.run() dialog.hide()
def refresh(self): try: backend_type = g15gconf.get_string_or_default( self.gconf_client, "%s/source" % self.gconf_key, None) if backend_type: backend = get_backend(backend_type).create_backend( self.gconf_client, "%s/%s" % (self.gconf_key, backend_type)) self._weather = backend.get_weather_data() else: self._weather = None self._page_properties, self._page_attributes = self._build_properties( ) except Exception as e: logger.debug("Error while refreshing", exc_info=e) self._weather = None self._page_properties = {} self._page_attributes = {} self._page_properties['message'] = _("Error parsing weather data!")
def format_date_time(date_val, gconf_client, display_seconds=True): """ Format a datetime as a date and a time. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: date_val -- date / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/date_time_format", locale.nl_langinfo(locale.D_T_FMT)) if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(date_val, tuple): return datetime.datetime.strftime(fmt, date_val) else: return date_val.strftime(fmt)
def format_time(time_val, gconf_client, display_seconds=True, show_timezone=False, compact=True): """ Format a given time / datetime as a time in the 12hour format. GConf is checked for custom format, otherwise the default for the locale is used. Keyword arguments: time_val -- time / datetime object gconf_client -- gconf client instance display_seconds -- if false, seconds will be stripped from result """ fmt = g15gconf.get_string_or_default(gconf_client, "/apps/gnome15/time_format", locale.nl_langinfo(locale.T_FMT_AMPM)) # For some locales T_FMT_AMPM is empty. # Set the format to a default value if this is the case. if fmt == "": fmt = "%r" if not display_seconds: fmt = __strip_seconds(fmt) if isinstance(time_val, time.struct_time): time_val = datetime.datetime(*time_val[:6]) if not show_timezone: fmt = fmt.replace("%Z", "") if compact: fmt = fmt.replace(" %p", "%p") fmt = fmt.replace(" %P", "%P") fmt = fmt.strip() if isinstance(time_val, tuple): return time.strftime(fmt, time_val) else: return time_val.strftime(fmt)
def get_weather_data(self): station_id = g15gconf.get_string_or_default(self.gconf_client, "%s/station_id" % self.gconf_key, "KPEO") p = pywapi.get_weather_from_noaa(station_id) tm = email.utils.parsedate_tz(p["observation_time_rfc822"])[:9] data = { "location" : p["location"], "datetime" : datetime.datetime.fromtimestamp(time.mktime(tm)), "current_conditions" : { "wind_speed" : g15pythonlang.to_int_or_none(weather.mph_to_kph(float(p["wind_mph"]))) if "wind_mph" in p else None, "wind_direction" : g15pythonlang.to_int_or_none(p["wind_degrees"]) if "wind_degrees" in p else None, "pressure" : p["pressure_mb"] if "pressure_mb" in p else None, "humidity" : p["relative_humidity"] if "relative_humidity" in p else None, "condition" : p["weather"] if "weather" in p else None, "temp_c" : p["temp_c"] if "temp_c" in p else None, "icon" : self._get_icon(p["icon_url_name"]) if "icon_url_name" in p else None, "fallback_icon" : "http://w1.weather.gov/images/fcicons/%s" % ( "%s.jpg" % os.path.splitext(p["icon_url_name"])[0] ) if "icon_url_name" in p else None } } return data
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 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 _do_get_weather_data_xml(self): location_id = g15gconf.get_string_or_default( self.gconf_client, "%s/location_id" % self.gconf_key, "2487956") p = self._get_weather_from_yahoo(location_id) if p is None: return None # Get location location_el = p["location"] location = g15pythonlang.append_if_exists(location_el, "city", "") location = g15pythonlang.append_if_exists(location_el, "region", location) location = g15pythonlang.append_if_exists(location_el, "country", location) # Get current condition condition_el = p["condition"] wind_el = p["wind"] if "wind" in p else None # Observed date try: observed_datetime = datetime.datetime.strptime( condition_el["date"], "%a, %d %b %Y %H:%M %p %Z") except ValueError as v: logger.debug("Error parsing date, trying alternative method.", exc_info=v) import email.utils dxt = email.utils.parsedate_tz(condition_el["date"]) class TZ(datetime.tzinfo): def dst(self, dt): return datetime.timedelta(0) def tzname(self, dt): return dxt[9] def utcoffset(self, dt): return datetime.timedelta(seconds=dxt[9]) observed_datetime = datetime.datetime(*dxt[:7], tzinfo=TZ()) # Forecasts (we only get 2 from yahoo) forecasts_el = p["forecasts"] forecasts = [] today_low = None today_high = None for f in forecasts_el: condition_code = g15pythonlang.to_int_or_none(f["code"]) high = g15pythonlang.to_float_or_none(f["high"]) low = g15pythonlang.to_float_or_none(f["low"]) if today_low is None: today_low = low today_high = high forecasts.append({ "condition": f["text"], "high": high, "low": low, "day_of_week": f["day"], "icon": self._translate_icon(condition_code), "fallback_icon": "http://l.yimg.com/a/i/us/we/52/%s.gif" % condition_code }) # Sunset and sunrise sunset = None sunrise = None if "astronomy" in p: astronomy = p["astronomy"] if "sunset" in astronomy: sunset = g15locale.parse_US_time_or_none(astronomy["sunset"]) if "sunrise" in astronomy: sunrise = g15locale.parse_US_time_or_none(astronomy["sunrise"]) # Pressure, Visibility and Humidity pressure = None if "atmosphere" in p: atmosphere = p["atmosphere"] if "pressure" in atmosphere: pressure = g15pythonlang.to_float_or_none( atmosphere["pressure"]) if "visibility" in atmosphere: visibility = g15pythonlang.to_float_or_none( atmosphere["visibility"]) if "humidity" in atmosphere: humidity = g15pythonlang.to_float_or_none( atmosphere["humidity"]) # Build data structure condition_code = g15pythonlang.to_int_or_none(condition_el["code"]) data = { "location": location, "forecasts": forecasts, "datetime": observed_datetime, "current_conditions": { "wind_chill": wind_el["chill"] if wind_el is not None and "chill" in wind_el else None, "wind_direction": wind_el["direction"] if wind_el is not None and "direction" in wind_el else None, "wind_speed": wind_el["speed"] if wind_el is not None and "speed" in wind_el else None, "condition": condition_el["text"], "sunset": sunset, "sunrise": sunrise, "pressure": pressure, "visibility": visibility, "humidity": humidity, "low": today_low, "high": today_high, "temp_c": g15pythonlang.to_float_or_none(condition_el["temp"]), "icon": self._translate_icon(condition_code), "fallback_icon": "http://l.yimg.com/a/i/us/we/52/%s.gif" % condition_code if condition_code is not None else None } } return data
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 get_theme_properties(self): p = g15theme.MenuItem.get_theme_properties(self) p["item_radio"] = True p["item_radio_selected"] = self._mode == g15gconf.get_string_or_default(self._gconf_client, "%s/mode" % self._gconf_key, MODE_ONLINE) return p
def _do_get_weather_data_xml(self): location_id = g15gconf.get_string_or_default(self.gconf_client, "%s/location_id" % self.gconf_key, "2487956") p = self._get_weather_from_yahoo(location_id) if p is None: return None # Get location location_el = p["location"] location = g15pythonlang.append_if_exists(location_el, "city", "") location = g15pythonlang.append_if_exists(location_el, "region", location) location = g15pythonlang.append_if_exists(location_el, "country", location) # Get current condition condition_el = p["condition"] wind_el = p["wind"] if "wind" in p else None # Observed date try: observed_datetime = datetime.datetime.strptime(condition_el["date"], "%a, %d %b %Y %H:%M %p %Z") except ValueError as v: logger.debug("Error parsing date, trying alternative method.", exc_info = v) import email.utils dxt = email.utils.parsedate_tz(condition_el["date"]) class TZ(datetime.tzinfo): def dst(self, dt): return datetime.timedelta(0) def tzname(self, dt): return dxt[9] def utcoffset(self, dt): return datetime.timedelta(seconds=dxt[9]) observed_datetime = datetime.datetime(*dxt[:7], tzinfo=TZ()) # Forecasts (we only get 2 from yahoo) forecasts_el = p["forecasts"] forecasts = [] today_low = None today_high = None for f in forecasts_el: condition_code = g15pythonlang.to_int_or_none(f["code"]) high = g15pythonlang.to_float_or_none(f["high"]) low = g15pythonlang.to_float_or_none(f["low"]) if today_low is None: today_low = low today_high = high forecasts.append({ "condition" : f["text"], "high" : high, "low" : low, "day_of_week" : f["day"], "icon" : self._translate_icon(condition_code), "fallback_icon" : "http://l.yimg.com/a/i/us/we/52/%s.gif" % condition_code }) # Sunset and sunrise sunset = None sunrise = None if "astronomy" in p: astronomy = p["astronomy"] if "sunset" in astronomy: sunset = g15locale.parse_US_time_or_none(astronomy["sunset"]) if "sunrise" in astronomy: sunrise = g15locale.parse_US_time_or_none(astronomy["sunrise"]) # Pressure, Visibility and Humidity pressure = None if "atmosphere" in p: atmosphere = p["atmosphere"] if "pressure" in atmosphere: pressure = g15pythonlang.to_float_or_none(atmosphere["pressure"]) if "visibility" in atmosphere: visibility = g15pythonlang.to_float_or_none(atmosphere["visibility"]) if "humidity" in atmosphere: humidity = g15pythonlang.to_float_or_none(atmosphere["humidity"]) # Build data structure condition_code = g15pythonlang.to_int_or_none(condition_el["code"]) data = { "location" : location, "forecasts" : forecasts, "datetime": observed_datetime, "current_conditions" : { "wind_chill": wind_el["chill"] if wind_el is not None and "chill" in wind_el else None, "wind_direction": wind_el["direction"] if wind_el is not None and "direction" in wind_el else None, "wind_speed": wind_el["speed"] if wind_el is not None and "speed" in wind_el else None, "condition" : condition_el["text"], "sunset" : sunset, "sunrise" : sunrise, "pressure" : pressure, "visibility" : visibility, "humidity" : humidity, "low" : today_low, "high" : today_high, "temp_c" : g15pythonlang.to_float_or_none(condition_el["temp"]), "icon" : self._translate_icon(condition_code), "fallback_icon" : "http://l.yimg.com/a/i/us/we/52/%s.gif" % condition_code if condition_code is not None else None } } return data
def get_theme_properties(self): p = g15theme.MenuItem.get_theme_properties(self) p["item_radio"] = True p["item_radio_selected"] = self._mode == g15gconf.get_string_or_default( self._gconf_client, "%s/mode" % self._gconf_key, MODE_ONLINE) return p
def get_string_or_default(gconf_client, key, default=None): return g15gconf.get_string_or_default(gconf_client, key, default)