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 _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 paint(self, canvas): panel_height = self._get_panel_size() position = self._get_panel_position() # Panel is in one position on the 1 bit display if self.screen.driver.get_bpp() == 1: gap = 1 inset = 1 widget_size = panel_height bg = None position = "top" align = "end" else: inset = 0 align = "start" gap = panel_height / 10.0 bg = g15gconf.get_cairo_rgba_or_default(self.gconf_client, self.gconf_key + "/color", ( 128, 128, 128, 128 )) widget_size = panel_height - ( gap * 2 ) # Paint the panel in memory first so it can be aligned easily if position == "top" or position == "bottom": panel_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.screen.width, panel_height) else: panel_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, panel_height, self.screen.height) panel_canvas = cairo.Context (panel_img) self.screen.configure_canvas(panel_canvas) actual_size = 0 if position == "top" or position == "bottom": panel_canvas.translate(0, gap) for page in self.screen.pages: if page != self.screen.get_visible_page() and page.panel_painter != None: if actual_size > 0: panel_canvas.translate(inset + gap, 0) actual_size += inset + gap panel_canvas.save() panel_canvas.set_source_rgb(*self.screen.driver.get_color_as_ratios(g15driver.HINT_FOREGROUND, ( 0, 0, 0 ))) taken_up = page.panel_painter(panel_canvas, widget_size, True) panel_canvas.restore() if taken_up != None: panel_canvas.translate(taken_up, 0) actual_size += taken_up else: panel_canvas.translate(gap, 0) for page in self.screen.pages: if page != self.screen.get_visible_page() and page.panel_painter != None: if actual_size > 0: panel_canvas.translate(0, inset + gap) actual_size += inset + gap panel_canvas.save() panel_canvas.set_source_rgb(*self.screen.driver.get_color_as_ratios(g15driver.HINT_FOREGROUND, ( 0, 0, 0 ))) taken_up = page.panel_painter(panel_canvas, widget_size, False) panel_canvas.restore() if taken_up != None: panel_canvas.translate(0, taken_up) actual_size += taken_up # Position the panel canvas.save() if position == "bottom": canvas.translate(0 if align == "start" else self.screen.width - actual_size - gap, self.screen.height - panel_height) elif position == "right": canvas.translate(self.screen.width - panel_height, 0 if align == "start" else self.screen.height - actual_size - gap) elif position == "top": canvas.translate(0 if align == "start" else self.screen.width - actual_size - gap, 0) elif position == "left": canvas.translate(0, 0 if align == "start" else self.screen.height - actual_size - gap) # Paint background if bg != None: canvas.set_source_rgba(*bg) if position == "top" or position == "bottom": canvas.rectangle(0, 0, self.screen.width, panel_height) else: canvas.rectangle(0, 0, panel_height, self.screen.height) canvas.fill() # Now actually paint the panel canvas.set_source_surface(panel_img) canvas.paint() canvas.restore()
def paint(self, canvas): panel_height = self._get_panel_size() position = self._get_panel_position() # Panel is in one position on the 1 bit display if self.screen.driver.get_bpp() == 1: gap = 1 inset = 1 widget_size = panel_height bg = None position = "top" align = "end" else: inset = 0 align = "start" gap = panel_height / 10.0 bg = g15gconf.get_cairo_rgba_or_default(self.gconf_client, self.gconf_key + "/color", ( 128, 128, 128, 128 )) widget_size = panel_height - ( gap * 2 ) # Paint the panel in memory first so it can be aligned easily if position == "top" or position == "bottom": panel_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.screen.width, panel_height) else: panel_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, panel_height, self.screen.height) panel_canvas = cairo.Context (panel_img) self.screen.configure_canvas(panel_canvas) actual_size = 0 if position == "top" or position == "bottom": panel_canvas.translate(0, gap) for page in self.screen.pages: if page != self.screen.get_visible_page() and page.panel_painter != None: if actual_size > 0: panel_canvas.translate(inset + gap, 0) actual_size += inset + gap panel_canvas.save() panel_canvas.set_source_rgb(*self.screen.driver.get_color_as_ratios(g15driver.HINT_FOREGROUND, ( 0, 0, 0 ))) taken_up = page.panel_painter(panel_canvas, widget_size, True) panel_canvas.restore() if taken_up != None: panel_canvas.translate(taken_up, 0) actual_size += taken_up else: panel_canvas.translate(gap, 0) for page in self.screen.pages: if page != self.screen.get_visible_page() and page.panel_painter != None: if actual_size > 0: panel_canvas.translate(0, inset + gap) actual_size += inset + gap panel_canvas.save() panel_canvas.set_source_rgb(*self.screen.driver.get_color_as_ratios(g15driver.HINT_FOREGROUND, ( 0, 0, 0 ))) taken_up = page.panel_painter(panel_canvas, widget_size, False) panel_canvas.restore() if taken_up != None: panel_canvas.translate(0, taken_up) actual_size += taken_up # Position the panel canvas.save() if position == "bottom": canvas.translate(0 if align == "start" else self.screen.width - actual_size - gap, self.screen.height - panel_height) elif position == "right": canvas.translate(self.screen.width - panel_height, 0 if align == "start" else self.screen.height - actual_size - gap) elif position == "top": canvas.translate(0 if align == "start" else self.screen.width - actual_size - gap, 0) elif position == "left": canvas.translate(0, 0 if align == "start" else self.screen.height - actual_size - gap) # Paint background if bg != None: canvas.set_source_rgba(*bg) if position == "top" or position == "bottom": canvas.rectangle(0, 0, self.screen.width, panel_height) else: canvas.rectangle(0, 0, panel_height, self.screen.height) canvas.fill() # Now actually paint the panel canvas.set_source_surface(panel_img) canvas.paint() canvas.restore()
def to_cairo_rgba(gconf_client, key, default): return g15gconf.get_cairo_rgba_or_default(gconf_client, key, default)