def activate(self): self._active = True self._page = None self._theme = g15theme.G15Theme(os.path.join(os.path.dirname(__file__), "default"), auto_dirty = False) self._loaded = 0 self.pie_data = [] # Backend self._account_manager = g15accounts.G15AccountManager(CONFIG_PATH, CONFIG_ITEM_NAME) self._account_manager.add_change_listener(self._accounts_changed) # Menu self._menu = g15theme.Menu("menu") self._menu.focusable = True self._menu.on_selected = self._on_menu_selected # Page self._page = g15theme.G15Page(name, self._screen, theme_properties_callback = self._get_properties, thumbnail_painter = self._paint_thumbnail, originating_plugin = self) self._page.set_title(_("Google Analytics")) self._page.set_theme(self._theme) self._screen.key_handler.action_listeners.append(self) self._page.add_child(G15VisitsGraph("visitsGraph", self)) self._page.add_child(self._menu) self._page.add_child(g15theme.MenuScrollbar("viewScrollbar", self._menu)) self._screen.add_page(self._page) self._schedule_refresh(0)
def __init__(self, conn, plugin): asyncore.dispatcher.__init__(self, sock=conn) self.out_buffer = "" self.img_buffer = None self.buffer_type = None self.buffer_len = 0 self.surface = None self.last_img_buffer = None self.enable_keys = False self.plugin = plugin self.plugin.join(self) self.handshake = False self.keyboard_backlight_value = None self.backlight_value = None self.page = g15theme.G15Page("G15Daemon%d" % self.plugin.screen_index, plugin.screen, painter=self._paint, on_shown=self._on_shown, on_hidden=self._on_hidden, originating_plugin=self) self.page.set_title( _("G15Daemon Screen %d") % self.plugin.screen_index) self.plugin.screen.add_page(self.page) self.plugin.screen_index += 1 self.plugin.screen.redraw(self.page) self.backlight_acquire = None self.keyboard_backlight_acquire = None self.out_buffer += "G15 daemon HELLO" self.oob_buffer = ""
def activate(self): g15plugin.G15Plugin.activate(self) self._active = True self._event_days = None self._calendar_date = None self._page = None self._theme = g15theme.G15Theme(os.path.join(os.path.dirname(__file__), "default"), auto_dirty=False) self._loaded = 0 # Backend self._account_manager = g15accounts.G15AccountManager( CONFIG_PATH, CONFIG_ITEM_NAME) # Calendar self._calendar = Calendar() # Menu self._menu = g15theme.Menu("menu") self._menu.focusable = True self._menu.focused_component = True # Page self._page = g15theme.G15Page( name, self.screen, on_shown=self._on_shown, on_hidden=self._on_hidden, theme_properties_callback=self._get_properties, thumbnail_painter=self._paint_thumbnail, originating_plugin=self) self._page.set_title(_("Calendar")) self._page.set_theme(self._theme) self._page.focused_component = self._calendar self._calendar.set_focused(True) # List for account changes self._account_manager.add_change_listener(self._accounts_changed) self.screen.key_handler.action_listeners.append(self) # Run first load in thread self._page.add_child(self._menu) self._page.add_child(self._calendar) self._page.add_child( g15theme.MenuScrollbar("viewScrollbar", self._menu)) self.screen.add_page(self._page) g15scheduler.schedule("CalendarFirstLoad", 0, self._redraw) # Listen for changes in the network state self.screen.service.network_manager.listeners.append( self._network_state_changed) # Config changes self.watch("twenty_four_hour_times", self._config_changed)
def activate(self): self.page = g15theme.G15Page( id, self.screen, theme_properties_callback=self._get_theme_properties, priority=g15screen.PRI_LOW, title=name, theme=g15theme.G15Theme(self), originating_plugin=plugin) self.window = g15gtk.G15OffscreenWindow("offscreenWindow") self.page.add_child(self.window) GLib.idle_add(self._create_offscreen_window)
def show_page(self): self.load_song_details() self.page = self.screen.get_page(page_id="MPRIS%s" % self.title) if self.page == None: self.page = g15theme.G15Page("MPRIS%s" % self.title, self.screen, on_shown=self.on_shown, \ on_hidden=self.on_hidden, theme_properties_callback = self._get_properties, \ panel_painter = self.paint_panel, thumbnail_painter = self.paint_thumbnail, \ theme = self.theme, title = self.title, originating_plugin = self) self.screen.add_page(self.page) self.screen.redraw(self.page) else: self.screen.set_priority(self.page, g15screen.PRI_HIGH, revert_after = 3.0)
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 activate(self): self._reload_theme() self._page = g15theme.G15Page( "Nexuiz", self._screen, theme_properties_callback=self._get_properties, theme=self._theme, originating_plugin=self) self._page.title = "Nexuiz" self._screen.add_page(self._page) self._redraw() # Add the right profile for the model macro_file = os.path.join(os.path.dirname(__file__), "game-nexuiz.%s.macros") if os.path.exists(macro_file): profile = g15profile.G15Profile(self._screen.device, file_path=macro_file) g15profiles.add_profile(profile)
def _start_recording(self): self._script_model = [] self._key_state = {} self._key_down = None if self._screen.driver.get_bpp() > 0: if self._page == None: self._page = g15theme.G15Page(id, self._screen, priority=g15screen.PRI_EXCLUSIVE,\ title = name, theme_properties_callback = self._get_theme_properties, \ theme = self._theme, originating_plugin = self) self._screen.add_page(self._page) self.icon = "media-record" self._message = None self._redraw() self._record_thread = RecordThread(self._record_callback) self._record_thread.start() self._lights_control = self._screen.driver.acquire_control_with_hint(g15driver.HINT_MKEYS) self._lights_control.set_value(self._screen.get_memory_bank() | g15driver.MKEY_LIGHT_MR) self._lights_control.blink(0, 0.5) self._screen.request_defeat_profile_change()
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 activate(self): ''' The activate function is invoked when gnome15 starts up, or the plugin is re-enabled after it has been disabled. When extending any of the provided base plugin classes, you nearly always want to call the function in the supoer class as well ''' g15plugin.G15Plugin.activate(self) ''' Load our configuration ''' self.timer = None self._load_configuration() ''' We will be drawing text manually in the thumbnail, so it is recommended you use the G15Text class which simplifies drawing and measuring text in an efficient manner ''' self.text = g15text.new_text(self.screen) ''' Most plugins will delegate their drawing to a 'Theme'. A theme usually consists of an SVG file, one for each model that is supported, and optionally a fragment of Python for anything that can't be done with SVG and the built in theme facilities ''' self._reload_theme() ''' Most plugins will usually want to draw on the screen. To do so, a 'page' is created. We also supply a callback here to perform the painting. You can also supply 'on_shown' and 'on_hidden' callbacks here to be notified when your page actually gets shown and hidden. A thumbnail painter function is also provided. This is used by other plugins want a thumbnail representation of the current screen. For example, this could be used in the 'panel', or the 'menu' plugins ''' self.page = g15theme.G15Page( "Clock", self.screen, theme_properties_callback=self._get_properties, thumbnail_painter=self.paint_thumbnail, panel_painter=self.paint_thumbnail, theme=self.theme, originating_plugin=self) self.page.title = "Simple Clock" ''' Add the page to the screen ''' self.screen.add_page(self.page) ''' Once created, we should always ask for the screen to be drawn (even if another higher priority screen is actually active. If the canvas is not displayed immediately, the on_shown function will be invoked when it finally is. ''' self.screen.redraw(self.page) ''' As this is a Clock, we want to redraw at fixed intervals. So, schedule another redraw if appropriate ''' self._schedule_redraw() ''' We want to be notified when the plugin configuration changed, so watch for gconf events. The watch function is used, as this will automatically track the monitor handles and clean them up when the plugin is deactivated ''' self.watch(None, self._config_changed)
def _notify(self): if len(self._message_queue) != 0: logger.debug("Displaying first message in queue of %d", len(self._message_queue)) message = self._message_queue[0] # Which theme variant should we use self._last_variant = "" if message.body == None or message.body == "": self._last_variant = "nobody" self._current_message = message # Get the page if self._page == None: logger.debug("Creating new notification message page") self._control_values = [] for c in self._screen.driver.get_controls(): if c.hint & g15driver.HINT_DIMMABLE != 0: self._control_values.append(c.value) if self._screen.driver.get_bpp() != 0: logger.debug("Creating notification message page") self._page = g15theme.G15Page(id, self._screen, priority=g15screen.PRI_HIGH, title = name, \ theme_properties_callback = self._get_theme_properties, \ theme = g15theme.G15Theme(self, self._last_variant), originating_plugin = self) self._page.on_deleted = self._page_deleted self._screen.add_page(self._page) else: logger.debug("Raising notification message page") self._page.set_theme( g15theme.G15Theme(self, self._last_variant)) self._screen.raise_page(self._page) self._start_timer(message) self._do_redraw() # Play sound if self.enable_sounds and "sound-file" in message.hints and ( not "suppress-sound" in message.hints or not message.hints["suppress-sound"]): logger.debug("Will play sound", message.hints["sound-file"]) os.system("aplay '%s' &" % message.hints["sound-file"]) control = self._screen.driver.get_control_for_hint( g15driver.HINT_DIMMABLE) if control and self.blink_keyboard_backlight: acquired_control = self._screen.driver.acquire_control( control, release_after=3.0, val=self.keyboard_backlight_color if self.change_keyboard_backlight_color else control.value) acquired_control.blink(delay=self.blink_delay / 1000.0) elif control and self.change_keyboard_backlight_color: acquired_control = self._screen.driver.acquire_control( control, release_after=3.0, val=self.keyboard_backlight_color) if self.blink_memory_bank: acquired_control = self._screen.driver.acquire_control_with_hint( g15driver.HINT_MKEYS, release_after=3.0, val=g15driver.MKEY_LIGHT_1 | g15driver.MKEY_LIGHT_2 | g15driver.MKEY_LIGHT_3 | g15driver.MKEY_LIGHT_MR) acquired_control.blink(delay=self.blink_delay / 1000.0)
def _popup(self): if not self._activated: logger.warning( "Cannot popup volume when it is deactivated. This suggests the volume thread has not died." ) return if not self._light_controls: self._light_controls = self._screen.driver.acquire_control_with_hint( g15driver.HINT_MKEYS) if self._lights_timer is not None: self._lights_timer.cancel() if self._light_controls is not None: self._lights_timer = g15scheduler.schedule("ReleaseMKeyLights", 3.0, self._release_lights) page = self._screen.get_page(id) if page == None: if self._screen.driver.get_bpp() != 0: page = g15theme.G15Page(id, self._screen, priority=g15screen.PRI_HIGH, title="Volume", theme = g15theme.G15Theme(self), \ theme_properties_callback = self._get_theme_properties, originating_plugin = self) self._screen.delete_after(3.0, page) self._screen.add_page(page) else: self._screen.raise_page(page) self._screen.delete_after(3.0, page) vol_mixer = self._open_mixer() mute_mixer = None try: # Handle mute mute = False mutes = None try: mutes = vol_mixer.getmute() except alsaaudio.ALSAAudioError as e: logger.debug("Could note get mute channel. Trying PCM", exc_info=e) # Some pulse weirdness maybe? mute_mixer = alsaaudio.Mixer("PCM", cardindex=self.soundcard_index) try: mutes = mute_mixer.getmute() except alsaaudio.ALSAAudioError as e: logger.warning("No mute switch found", exc_info=e) if mutes != None: for ch_mute in mutes: if ch_mute: mute = True # TODO better way than averaging volumes = vol_mixer.getvolume() finally: vol_mixer.close() if mute_mixer: mute_mixer.close() total = 0 for vol in volumes: total += vol volume = total / len(volumes) self._volume = volume if self._light_controls is not None: if self._volume > 90: self._light_controls.set_value(g15driver.MKEY_LIGHT_MR | g15driver.MKEY_LIGHT_1 | g15driver.MKEY_LIGHT_2 | g15driver.MKEY_LIGHT_3) elif self._volume > 75: self._light_controls.set_value(g15driver.MKEY_LIGHT_1 | g15driver.MKEY_LIGHT_2 | g15driver.MKEY_LIGHT_3) elif self._volume > 50: self._light_controls.set_value(g15driver.MKEY_LIGHT_1 | g15driver.MKEY_LIGHT_2) elif self._volume > 25: self._light_controls.set_value(g15driver.MKEY_LIGHT_1) else: self._light_controls.set_value(0) self._mute = mute self._screen.redraw(page)