def __init__(self, model=None): # TODO: add logic to flag open notebook italic - needs daemon if model is None: model = NotebookTreeModel() GObject.GObject.__init__(self) self.set_model(model) self.get_selection().set_mode(Gtk.SelectionMode.BROWSE) self.set_rules_hint(True) self.set_reorderable(True) cell_renderer = Gtk.CellRendererPixbuf() column = Gtk.TreeViewColumn(None, cell_renderer, pixbuf=PIXBUF_COL) column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) w, h = strip_boolean_result(Gtk.icon_size_lookup(Gtk.IconSize.MENU)) column.set_fixed_width(w * 2) self.append_column(column) cell_renderer = Gtk.CellRendererText() cell_renderer.set_property('ellipsize', Pango.EllipsizeMode.END) cell_renderer.set_fixed_height_from_font(2) column = Gtk.TreeViewColumn(_('Notebook'), cell_renderer, markup=TEXT_COL) # T: Column heading in 'open notebook' dialog column.set_sort_column_id(NAME_COL) self.append_column(column)
def __init__(self, label, expand_width=False, size_group=None, dep_key=None, tooltip=""): super(IconChooser, self).__init__(dep_key=dep_key) valid, self.width, self.height = Gtk.icon_size_lookup( Gtk.IconSize.BUTTON) self.label = SettingsLabel(label) self.content_widget = Gtk.Box() self.bind_object = Gtk.Entry() self.image_button = Gtk.Button() self.preview = Gtk.Image.new() self.image_button.set_image(self.preview) self.content_widget.pack_start(self.bind_object, expand_width, expand_width, 2) self.content_widget.pack_start(self.image_button, False, False, 5) self.pack_start(self.label, False, False, 0) self.pack_end(self.content_widget, expand_width, expand_width, 0) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.bind_object.connect("changed", self.set_icon) self.set_tooltip_text(tooltip) if size_group: self.add_to_size_group(size_group)
def __init__(self): Gtk.Window.__init__(self) self.set_decorated(False) self.set_resizable(False) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.set_border_width(0) self.props.accept_focus = False # Setup estimate of width, height valid_, w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) self._width = w self._height = h screen = self.get_screen() screen.connect("size-changed", self._screen_size_changed_cb) self._button = Gtk.Button() self._button.set_relief(Gtk.ReliefStyle.NONE) self._icon = Icon(icon_name="view-return", icon_size=Gtk.IconSize.LARGE_TOOLBAR) self._icon.show() self._button.add(self._icon) self._button.show() self.add(self._button)
def load_icon(icon, size): if (icon, size) in icon_cache: return icon_cache[(icon, size)] icon_size = Gtk.icon_size_lookup(size) if icon_size[0]: icon_size = icon_size[1] pixbuf = None try: pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon) w, h = pixbuf.get_width(), pixbuf.get_height() rate = max(w, h) / float(icon_size) w = int(w / rate) h = int(h / rate) pixbuf = pixbuf.scale_simple(w, h, GdkPixbuf.InterpType.BILINEAR) except: # import traceback # traceback.print_exc() pass if pixbuf == None: try: theme = Gtk.IconTheme.get_default() pixbuf = theme.load_icon(icon, icon_size, 0) except: # import traceback # traceback.print_exc() pass icon_cache[(icon, size)] = pixbuf return pixbuf
def set_animation(self, name, fallback=None, size=None): """Show and start the animation of the given name and size""" if name == self.icon_name: return if size is not None: self._icon_size = size self.stop_animation() animation = [] (width, height) = Gtk.icon_size_lookup(self._icon_size) theme = Gtk.IconTheme.get_default() if name is not None and theme.has_icon(name): pixbuf = theme.load_icon(name, width, 0) rows = pixbuf.get_height() / height cols = pixbuf.get_width() / width for r in range(rows): for c in range(cols): animation.append(pixbuf.subpixbuf(c * width, r * height, width, height)) if len(animation) > 0: self.animation = animation self.iter = 0 self.set_from_pixbuf(self.animation[0]) self.start_animation() else: self.set_from_pixbuf(pixbuf) self.icon_name = name elif fallback is not None and theme.has_icon(fallback): self.set_from_icon_name(fallback, self._icon_size) self.icon_name = fallback else: self.set_from_icon_name(Gtk.STOCK_MISSING_IMAGE)
def __init__(self, label, expand_width=True, size_group=None, dep_key=None, tooltip=""): super().__init__(dep_key=dep_key) valid, self.width, self.height = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON) self.set_spacing(5, 5) self.label = SettingsLabel(label) self.content_widget = BaseGrid(orientation=Gtk.Orientation.HORIZONTAL) self.content_widget.set_spacing(5, 0) self.content_widget.set_hexpand(True) self.bind_object = Gtk.Entry() self.bind_object.set_hexpand(True) self.image_button = Gtk.Button() self.preview = Gtk.Image.new() self.image_button.set_image(self.preview) self.content_widget.attach(self.bind_object, 0, 0, 1, 1) self.content_widget.attach(self.image_button, 1, 0, 1, 1) self.attach(self.label, 0, 0, 1, 1) self.attach(self.content_widget, 1, 0, 1, 1) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.bind_object.connect("changed", self.set_icon) self.set_tooltip_text(tooltip) if size_group: self.add_to_size_group(size_group)
def __init__(self, key, settings_obj, uuid): BaseWidget.__init__(self, key, settings_obj, uuid) super(IconFileChooser, self).__init__() valid, self.width, self.height = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON) self.label = Gtk.Label(self.get_desc()) self.entry = Gtk.Entry() self.image_button = Gtk.Button() if self.get_desc() != "": self.pack_start(self.label, False, False, 2) self.preview = Gtk.Image.new() self.setup_image() self.image_button.set_image(self.preview) self.pack_start(self.entry, True, True, 2) self.pack_start(self.image_button, False, False, 5) self.entry.set_text(self.get_val()) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.entry.connect("changed", self.on_entry_changed) self._value_changed_timer = None set_tt(self.get_tooltip(), self.label, self.image_button, self.entry)
def __init__(self): Gtk.Window.__init__(self) self.set_decorated(False) self.set_resizable(False) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.set_border_width(0) self.props.accept_focus = False # Setup estimate of width, height valid_, w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) self._width = w self._height = h screen = self.get_screen() screen.connect('size-changed', self._screen_size_changed_cb) self._button = Gtk.Button() self._button.set_relief(Gtk.ReliefStyle.NONE) self._icon = Icon(icon_name='view-return', pixel_size=style.STANDARD_ICON_SIZE) self._icon.show() self._button.add(self._icon) self._button.show() self.add(self._button)
def __init__(self, label): super(IconChooser, self).__init__() valid, self.width, self.height = Gtk.icon_size_lookup( Gtk.IconSize.BUTTON) self.set_spacing(5, 5) self.label = SettingsLabel(label) self.content_widget = BaseGrid(orientation=Gtk.Orientation.HORIZONTAL) self.content_widget.set_spacing(5, 0) self.content_widget.set_hexpand(True) self.bind_object = Gtk.Entry() self.bind_object.set_hexpand(True) self.image_button = Gtk.Button() self.preview = Gtk.Image.new() self.image_button.set_image(self.preview) self.content_widget.attach(self.bind_object, 0, 0, 1, 1) self.content_widget.attach(self.image_button, 1, 0, 1, 1) self.attach(self.label, 0, 0, 1, 1) self.attach(self.content_widget, 1, 0, 1, 1) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.bind_object.connect("changed", self.set_icon)
def append_item(self, action_id, text, icon_name=None, size=None, pixbuf=None): if (icon_name or pixbuf): self._icon_renderer = Gtk.CellRendererPixbuf() settings = self.get_settings() _, w, h = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.MENU) self._icon_renderer.props.stock_size = w self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) #if text: #self._text_renderer = Gtk.CellRendererText() #self.pack_start(self._text_renderer, True) #self.add_attribute(self._text_renderer, 'text', 1) if not pixbuf: if icon_name: if not size: size = Gtk.IconSize.LARGE_TOOLBAR width, height = Gtk.icon_size_lookup(size) else: width, height = size if icon_name[0:6] == "theme:": icon_name = self._get_real_name_from_theme(icon_name[6:], size) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_name, width, height) else: pixbuf = None self.model.append([action_id, text])
def __init__(self, label, expand_width=False, size_group=None, dep_key=None, tooltip=""): super(IconChooser, self).__init__(dep_key=dep_key) valid, self.width, self.height = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON) self.label = SettingsLabel(label) self.content_widget = Gtk.Box() self.bind_object = Gtk.Entry() self.image_button = Gtk.Button() self.preview = Gtk.Image.new() self.image_button.set_image(self.preview) self.content_widget.pack_start(self.bind_object, expand_width, expand_width, 2) self.content_widget.pack_start(self.image_button, False, False, 5) self.pack_start(self.label, False, False, 0) self.pack_end(self.content_widget, expand_width, expand_width, 0) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.bind_object.connect("changed", self.set_icon) self.set_tooltip_text(tooltip) if size_group: self.add_to_size_group(size_group)
def append_item(self, action_id, text, icon_name=None, file_name=None): if not self._icon_renderer and (icon_name or file_name): self._icon_renderer = Gtk.CellRendererPixbuf() settings = self.get_settings() valid_, w, h = Gtk.icon_size_lookup_for_settings( settings, Gtk.IconSize.MENU) self._icon_renderer.props.stock_size = max(w, h) self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) if not self._text_renderer and text: self._text_renderer = Gtk.CellRendererText() self.pack_end(self._text_renderer, True) self.add_attribute(self._text_renderer, 'text', 1) if icon_name or file_name: if text: size = Gtk.IconSize.MENU else: size = Gtk.IconSize.LARGE_TOOLBAR valid_, width, height = Gtk.icon_size_lookup(size) if icon_name: file_name = self._get_real_name_from_theme(icon_name, size) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( file_name, width, height) else: pixbuf = None self._model.append([action_id, text, pixbuf, False])
def do_activate(self): self.shell = self.object self.player = self.shell.props.shell_player # create and register an entry type self.db = self.shell.props.db self.entry_type = DoubanFMEntryType() self.db.register_entry_type(self.entry_type) self.entry_type.can_sync_metadata = True self.entry_type.sync_metadata = None # find and load doubanfm icon theme = Gtk.IconTheme.get_default() width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)[1:] icon = theme.load_icon('doubanfm', width, 0) # create a source under 'stores' group group = RB.DisplayPageGroup.get_by_id ('stores') self.source = GObject.new(DoubanFMSource, shell=self.shell, entry_type=self.entry_type, pixbuf=icon, plugin=self) self.shell.register_entry_type_for_source(self.source, self.entry_type) self.shell.append_display_page(self.source, group) # create ui, connect ui to actions, and add them to ui manager self.ui_manager = self.shell.props.ui_manager self.build_actions() self.ui_manager.insert_action_group(self.action_group) self.ui_merge_id = self.ui_manager.add_ui_from_file(PLUGIN_DIR + UI_FILE) self.change_menu_item_state(False) self.ui_manager.ensure_update() # connect signals self.player.connect('playing-source-changed', self.on_playing_source_changed) self.set_handle_signals(True)
def get_tab_icon_size(tab): if log.query(log.INFO): debug_plugin_message(log.format("%s", tab)) is_valid_size, icon_size_width, icon_size_height = Gtk.icon_size_lookup(Gtk.IconSize.MENU) return icon_size_height
def _tool_widget_get_icon(widget, icon_size): """Returns the pixbuf or icon name to use for a tool widget :param widget: a tool widget :param icon_size: a registered Gtk.IconSize :returns: a pixbuf or an icon name: as a pair, one of which is None :rtype: (GdkPixbuf.Pixbuf, str) Use whichever of the return values is not None. To get the pixbuf or icon name, one or both of * ``widget.tool_widget_get_icon_pixbuf(pixel_size)`` * ``widget.tool_widget_icon_name`` are tried, in that order. The former should create and return a new pixbuf, the latter should be an icon name string. """ # Try the pixbuf method first. # Only brush group tool widgets will define this, typically. size_valid, width_px, height_px = Gtk.icon_size_lookup(icon_size) if not size_valid: return None size_px = min(width_px, height_px) if hasattr(widget, "tool_widget_get_icon_pixbuf"): pixbuf = widget.tool_widget_get_icon_pixbuf(size_px) if pixbuf: return (pixbuf, None) # Try the icon name property. Fallback is a name we know will work. icon_name = getattr(widget, "tool_widget_icon_name", 'missing-image') return (None, icon_name)
def _icon_from_stock(self, stock): theme = Gtk.icon_theme_get_default() size = Gtk.icon_size_lookup(Gtk.IconSize.MENU) pixbuf = theme.load_icon(stock, size[0], Gtk.IconLookupFlags.USE_BUILTIN) return pixbuf
def __init__(self, key, label, tooltip=""): BaseGrid.__init__(self, tooltip) self.set_spacing(10, 10) self._key = key valid, self.width, self.height = Gtk.icon_size_lookup( Gtk.IconSize.BUTTON) self.label = SettingsLabel(label) self.entry = Gtk.Entry() self.entry.set_property("hexpand", True) self.button = Gtk.Button() self.preview = Gtk.Image.new() self.button.set_image(self.preview) self.entry.set_text(Settings().get_settings().get_string(self._key)) self.button.connect("clicked", self.on_button_pressed) self.handler = self.entry.connect("changed", self.set_icon) self.attach(self.label, 0, 1, 1, 1) self.attach(self.entry, 1, 1, 1, 1) self.attach(self.button, 2, 1, 1, 1) self.set_icon()
def set_animation(self, name, fallback=None, size=None): """Show and start the animation of the given name and size""" if name == self.icon_name: return if size is not None: self._icon_size = size self.stop_animation() animation = [] (width, height) = Gtk.icon_size_lookup(self._icon_size) theme = Gtk.IconTheme.get_default() if name is not None and theme.has_icon(name): pixbuf = theme.load_icon(name, width, 0) rows = pixbuf.get_height() / height cols = pixbuf.get_width() / width for r in range(rows): for c in range(cols): animation.append( pixbuf.subpixbuf(c * width, r * height, width, height)) if len(animation) > 0: self.animation = animation self.iter = 0 self.set_from_pixbuf(self.animation[0]) self.start_animation() else: self.set_from_pixbuf(pixbuf) self.icon_name = name elif fallback is not None and theme.has_icon(fallback): self.set_from_icon_name(fallback, self._icon_size) self.icon_name = fallback else: self.set_from_icon_name(Gtk.STOCK_MISSING_IMAGE)
def __init__(self, key, settings_obj, uuid): BaseWidget.__init__(self, key, settings_obj, uuid) super(IconFileChooser, self).__init__() valid, self.width, self.height = Gtk.icon_size_lookup( Gtk.IconSize.BUTTON) self.label = Gtk.Label(self.get_desc()) self.entry = Gtk.Entry() self.image_button = Gtk.Button() if self.get_desc() != "": self.pack_start(self.label, False, False, 2) self.preview = Gtk.Image.new() self.setup_image() self.image_button.set_image(self.preview) self.pack_start(self.entry, True, True, 2) self.pack_start(self.image_button, False, False, 5) self.entry.set_text(self.get_val()) self.image_button.connect("clicked", self.on_button_pressed) self.handler = self.entry.connect("changed", self.on_entry_changed) self._value_changed_timer = None set_tt(self.get_tooltip(), self.label, self.image_button, self.entry)
def get_pixbuf(self, size): '''Get the application icon as a C{GdkPixbuf.Pixbuf}. @param size: the icon size as gtk constant @returns: a pixbuf object or C{None} ''' icon = self['Desktop Entry'].get('Icon', None) if not icon: return None if isinstance(icon, File): icon = icon.path w, h = strip_boolean_result(Gtk.icon_size_lookup(size)) if '/' in icon or '\\' in icon: if os.path.isfile(icon): return GdkPixbuf.Pixbuf.new_from_file_at_size(icon, w, h) else: return None else: theme = Gtk.IconTheme.get_default() try: pixbuf = theme.load_icon(icon, w, 0) except Exception as error: #~ logger.exception('Foo') return None return pixbuf
def do_activate(self): print "activating vk plugin" #connecting to GSettings schema_source = Gio.SettingsSchemaSource.new_from_directory( self.plugin_info.get_data_dir(), Gio.SettingsSchemaSource.get_default(), False, ) schema = schema_source.lookup('org.gnome.rhythmbox.plugins.vk', False) self.settings = Gio.Settings.new_full(schema, None, None) #system settings shell = self.object db = shell.props.db #model = RB.RhythmDBQueryModel.new_empty(db) vk_entry_type = VKEntryType() self.entry_type = vk_entry_type db.register_entry_type(vk_entry_type) #icon what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) icon = GdkPixbuf.Pixbuf.new_from_file_at_size( self.plugin_info.get_data_dir() + "/vk.png", width, height) #create Source (aka tab) self.source = GObject.new(VKSource, shell=shell, name="VK " + _("Music"), entry_type=vk_entry_type, plugin=self, pixbuf=icon) #query_model=model, self.source.setup(db, self.settings) shell.register_entry_type_for_source(self.source, vk_entry_type) #append source to the library group = RB.DisplayPageGroup.get_by_id("library") shell.append_display_page(self.source, group)
def do_activate(self): print "CoverArtBrowser DEBUG - do_activate" self.shell = self.object self.db = self.shell.props.db try: entry_type = CoverArtBrowserEntryType() self.db.register_entry_type(entry_type) except NotImplementedError: entry_type = db.entry_register_type("CoverArtBrowserEntryType") entry_type.category = RB.RhythmDBEntryCategory.NORMAL # load plugin icon theme = Gtk.IconTheme.get_default() rb.append_plugin_source_path(theme, "/icons") what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) pxbf = GdkPixbuf.Pixbuf.new_from_file_at_size(rb.find_plugin_file(self, "covermgr.png"), width, height) group = RB.DisplayPageGroup.get_by_id ("library") self.source = GObject.new ( CoverArtBrowserSource, shell=self.shell, name=_("CoverArt"), entry_type=entry_type, plugin=self, pixbuf=pxbf) self.shell.register_entry_type_for_source(self.source, entry_type) self.shell.append_display_page(self.source, group) print "CoverArtBrowser DEBUG - end do_activate"
def pixbuf_from_icon_name( self, icon_name: str, size: Union[int, Gtk.IconSize] = Gtk.IconSize.BUTTON ) -> Optional[GdkPixbuf.Pixbuf]: """ Generates a pixbuf from an icon name :param icon_name: an icon name :param size: the size of the icon, will be tried to converted to a GTK icon size :returns: the generated pixbuf """ if isinstance(size, Gtk.IconSize): icon_size = Gtk.icon_size_lookup(size) size = icon_size[1] if icon_name.endswith('-symbolic'): fallback_name = icon_name[:-9] else: fallback_name = icon_name + '-symbolic' icon_info = self.icon_theme.choose_icon( [icon_name, fallback_name], size, Gtk.IconLookupFlags.USE_BUILTIN | Gtk.IconLookupFlags.FORCE_SIZE, ) if icon_info: try: return icon_info.load_icon() except GLib.GError as e: logger.warning('Failed to load icon "%s": %s', icon_name, e.message) else: logger.warning('Icon "%s" not found', icon_name) return None
def do_activate(self): """Activate the pandora plugin. Called when checked within the Rhythmbox plugin pane.""" print("Activating pandora plugin.") shell = self.object db = shell.props.db entry_type = PandoraEntryType() db.register_entry_type(entry_type) _, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) pandora_icon = GdkPixbuf.Pixbuf.new_from_file_at_size(rb.find_plugin_file(self, "pandora.png"), width, height) self.source = GObject.new( PandoraSource, shell=shell, name="Pandora", plugin=self, icon=pandora_icon, entry_type=entry_type) library_group = RB.DisplayPageGroup.get_by_id("library") shell.append_display_page(self.source, library_group) shell.register_entry_type_for_source(self.source, entry_type) # hack, should be done within gobject constructor self.source.init(); self.pec_id = shell.props.shell_player.connect_after('playing-song-changed', self.playing_entry_changed) self.psc_id = shell.props.shell_player.connect_after('playing-source-changed', self.playing_source_changed)
def _set_icon(self, icon): """Set button icon. Parameters ---------- icon : str The icon name or path. Returns ------- bool Remove source. """ if icon: # NOTE: Check for the existence of "/" first so os.path.isfile() is not # called unnecessarily. if "/" in icon and os.path.isfile(icon): valid, width, height = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON) img = GdkPixbuf.Pixbuf.new_from_file_at_size(icon, width, height) self._icon.set_from_pixbuf(img) else: self._icon.set_from_icon_name(icon, Gtk.IconSize.BUTTON) self.icon = icon self.notify("icon") self.emit("icon-selected", self.icon) else: self._icon.set_from_icon_name("edit-find-symbolic", Gtk.IconSize.BUTTON) self._timer = None return GLib.SOURCE_REMOVE
def pixbuf_from_icon_name(self, icon_name, size=Gtk.IconSize.BUTTON): """ Generates a pixbuf from an icon name :param icon_name: an icon name :type icon_name: string :param size: the size of the icon, will be tried to converted to a GTK icon size :type size: int or GtkIconSize :returns: the generated pixbuf :rtype: :class:`GdkPixbuf.Pixbuf` or None """ if isinstance(size, Gtk.IconSize): icon_size = Gtk.icon_size_lookup(size) size = icon_size[1] try: pixbuf = self.icon_theme.load_icon( icon_name, size, Gtk.IconLookupFlags.NO_SVG | Gtk.IconLookupFlags.FORCE_SIZE, ) except GLib.GError as e: logger.warning( 'Failed to get pixbuf from "{icon_name}": {error}'.format( icon_name=icon_name, error=e.message ) ) pixbuf = None # TODO: Check if fallbacks are necessary return pixbuf
def pixbuf_from_icon_name(self, icon_name, size=Gtk.IconSize.BUTTON): """ Generates a pixbuf from an icon name :param stock_id: an icon name :type stock_id: string :param size: the size of the icon, will be tried to converted to a GTK icon size :type size: int or GtkIconSize :returns: the generated pixbuf :rtype: :class:`GdkPixbuf.Pixbuf` or None """ if type(size) != int: icon_size = Gtk.icon_size_lookup(size) size = icon_size[1] try: pixbuf = self.icon_theme.load_icon(icon_name, size, Gtk.IconLookupFlags.NO_SVG) except GLib.GError as e: logger.warning( 'Failed to get pixbuf from "{icon_name}": {error}'.format( icon_name=icon_name, error=e.message)) pixbuf = None # TODO: Check if fallbacks are necessary return pixbuf
def do_activate(self): ''' Called by Rhythmbox when the plugin is activated. It creates the plugin's source and connects signals to manage the plugin's preferences. ''' print("CoverArtBrowser DEBUG - do_activate") self.shell = self.object self.db = self.shell.props.db try: entry_type = CoverArtBrowserEntryType() self.db.register_entry_type(entry_type) except NotImplementedError: entry_type = self.db.entry_register_type( 'CoverArtBrowserEntryType') cl = CoverLocale() cl.switch_locale(cl.Locale.LOCALE_DOMAIN) entry_type.category = RB.RhythmDBEntryCategory.NORMAL group = RB.DisplayPageGroup.get_by_id('library') # load plugin icon theme = Gtk.IconTheme.get_default() rb.append_plugin_source_path(theme, '/icons') # lets assume that python3 versions of RB only has the new icon attribute in the source if rb3compat.PYVER >=3: iconfile = Gio.File.new_for_path( rb.find_plugin_file(self, 'img/' + Theme(self).current\ + '/covermgr.png')) self.source = CoverArtBrowserSource( shell=self.shell, name=_("CoverArt"), entry_type=entry_type, plugin=self, icon=Gio.FileIcon.new(iconfile), query_model=self.shell.props.library_source.props.base_query_model) else: what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) pxbf = GdkPixbuf.Pixbuf.new_from_file_at_size( rb.find_plugin_file(self, 'img/' + Theme(self).current\ + '/covermgr.png'), width, height) self.source = CoverArtBrowserSource( shell=self.shell, name=_("CoverArt"), entry_type=entry_type, plugin=self, pixbuf=pxbf, query_model=self.shell.props.library_source.props.base_query_model) self.shell.register_entry_type_for_source(self.source, entry_type) self.shell.append_display_page(self.source, group) self.source.props.query_model.connect('complete', self.load_complete) print("CoverArtBrowser DEBUG - end do_activate")
def _get_icon_name_from_gicon(gicon): assert type(gicon) == Gio.ThemedIcon name = "image-missing" theme = Gtk.IconTheme.get_default() for n in gicon.get_names(): if theme.lookup_icon(n, Gtk.icon_size_lookup(Gtk.IconSize.MENU, 0, 0), 0): name = n break return n
def _get_real_name_from_theme(self, name, size): icon_theme = Gtk.IconTheme.get_default() valid_, width, height = Gtk.icon_size_lookup(size) info = icon_theme.lookup_icon(name, max(width, height), 0) if not info: raise ValueError('Icon %r not found.' % name) fname = info.get_filename() del info return fname
class IconMenuItem(Gtk.ImageMenuItem): icon_size = Gtk.icon_size_lookup(Gtk.IconSize.MENU)[0] def __init__(self, icon, text): GObject.GObject.__init__(self) self.set_image(iconfactory.get_image(icon, self.icon_size)) label = Gtk.Label(label=text) label.set_alignment(0.0, 0.5) self.add(label) self.show_all()
def set_active(self, aboolean): if aboolean: pos = self.ICON_HEIGHT - Gtk.icon_size_lookup(Gtk.IconSize.MENU)[1] if self.muted_image not in self.get_children(): self.put(self.muted_image, pos, pos) self.muted_image.show() else: if self.muted_image in self.get_children(): self.muted_image.hide() self.mute.set_active(aboolean)
def do_activate(self): shell = self.object self.db = shell.props.db self.entry_type = MagnatuneEntryType() self.db.register_entry_type(self.entry_type) self.settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune") theme = Gtk.IconTheme.get_default() rb.append_plugin_source_path(theme, "/icons") what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) icon = rb.try_load_icon(theme, "magnatune", width, 0) group = RB.DisplayPageGroup.get_by_id ("stores") settings = Gio.Settings("org.gnome.rhythmbox.plugins.magnatune") self.source = GObject.new(MagnatuneSource, shell=shell, entry_type=self.entry_type, pixbuf=icon, plugin=self, settings=settings.get_child("source"), name=_("Magnatune"), toolbar_path="/MagnatuneToolBar") shell.register_entry_type_for_source(self.source, self.entry_type) shell.append_display_page(self.source, group) manager = shell.props.ui_manager # Add the popup menu actions self.action_group = Gtk.ActionGroup(name='MagnatunePluginActions') action = Gtk.Action(name='MagnatuneDownloadAlbum', label=_("Download Album"), tooltip=_("Download this album from Magnatune"), stock_id='gtk-save') action.connect('activate', lambda a: shell.props.selected_page.download_album()) self.action_group.add_action(action) action = Gtk.Action(name='MagnatuneArtistInfo', label=_("Artist Information"), tooltip=_("Get information about this artist"), stock_id='gtk-info') action.connect('activate', lambda a: shell.props.selected_page.display_artist_info()) self.action_group.add_action(action) action = Gtk.Action(name='MagnatuneCancelDownload', label=_("Cancel Downloads"), tooltip=_("Stop album downloads"), stock_id='gtk-stop') action.connect('activate', lambda a: shell.props.selected_page.cancel_downloads()) action.set_sensitive(False) self.action_group.add_action(action) manager.insert_action_group(self.action_group, 0) self.ui_id = manager.add_ui_from_string(popup_ui) self.pec_id = shell.props.shell_player.connect('playing-song-changed', self.playing_entry_changed) manager.ensure_update()
def get_icon_cursor(self, icon_name, cursor_name=Name.ARROW): """Returns an overlay cursor for a named icon. Cached. :param icon_name: themed icon system name. :param cursor_name: name of a pixmaps/ image to use, minus the .png The icon will be overlaid at a small size to the bottom and right of the cursor image. """ # Return from cache, if we have an entry cache_key = ("actions", icon_name, cursor_name) if cache_key in self.cache: return self.cache[cache_key] if icon_name is not None: if "symbolic" in icon_name: icon_pixbuf = gui.drawutils.load_symbolic_icon( icon_name, 18, fg=(1, 1, 1, 1), outline=(0, 0, 0, 1), ) else: # Look up icon via the user's current theme icon_theme = Gtk.IconTheme.get_default() size_range = [Gtk.IconSize.SMALL_TOOLBAR, Gtk.IconSize.MENU] for icon_size in size_range: valid, width, height = Gtk.icon_size_lookup(icon_size) if not valid: continue size = min(width, height) if size > 24: continue flags = 0 icon_pixbuf = icon_theme.load_icon(icon_name, size, flags) if icon_pixbuf: break if not icon_pixbuf: logger.warning( "Can't find icon %r for cursor. Search path: %r", icon_name, icon_theme.get_search_path(), ) else: icon_pixbuf = None # Build cursor cursor = self._get_overlay_cursor(icon_pixbuf, cursor_name) # Cache and return self.cache[cache_key] = cursor return cursor
def __icon_cell_data_cb(self, celllayout, renderer, model, it, data): engine = self.__model.get_value(it, 0) # When append_engine() is called, self.__model.append(None) # is called internally and engine == None could happen in # a slow system. if engine == None: return icon_size = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)[0] pixbuf = load_icon(engine.get_icon(), Gtk.IconSize.LARGE_TOOLBAR) renderer.set_property("pixbuf", pixbuf)
def get_icon_cursor(self, icon_name, cursor_name=Name.ARROW): """Returns an overlay cursor for a named icon. Cached. :param icon_name: themed icon system name. :param cursor_name: name of a pixmaps/ image to use, minus the .png The icon will be overlaid at a small size to the bottom and right of the cursor image. """ # Return from cache, if we have an entry cache_key = ("actions", icon_name, cursor_name) if cache_key in self.cache: return self.cache[cache_key] if icon_name is not None: if "symbolic" in icon_name: icon_pixbuf = gui.drawutils.load_symbolic_icon( icon_name, 18, fg=(1,1,1,1), outline=(0,0,0,1), ) else: # Look up icon via the user's current theme icon_theme = Gtk.IconTheme.get_default() size_range = [Gtk.IconSize.SMALL_TOOLBAR, Gtk.IconSize.MENU] for icon_size in size_range: valid, width, height = Gtk.icon_size_lookup(icon_size) if not valid: continue size = min(width, height) if size > 24: continue flags = 0 icon_pixbuf = icon_theme.load_icon(icon_name, size, flags) if icon_pixbuf: break if not icon_pixbuf: logger.warning( "Can't find icon %r for cursor. Search path: %r", icon_name, icon_theme.get_search_path(), ) else: icon_pixbuf = None # Build cursor cursor = self._get_overlay_cursor(icon_pixbuf, cursor_name) # Cache and return self.cache[cache_key] = cursor return cursor
def __init__(self): ''' Initialises the object. ''' super(AltToolbarShared, self).__init__() # Prepare Album Art Displaying self.album_art_db = GObject.new(RB.ExtDB, name="album-art") what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.SMALL_TOOLBAR) self.icon_width = width self.cover_pixbuf = None
def do_activate(self): ''' Called by Rhythmbox when the plugin is activated. It creates the plugin's source and connects signals to manage the plugin's preferences. ''' # define .plugin text strings used for translation plugin = _('CoverArt Browser') desc = _('Browse and play your albums through their covers') print "CoverArtBrowser DEBUG - do_activate" self.shell = self.object self.db = self.shell.props.db try: entry_type = CoverArtBrowserEntryType() self.db.register_entry_type(entry_type) except NotImplementedError: entry_type = self.db.entry_register_type( 'CoverArtBrowserEntryType') cl = CoverLocale() cl.switch_locale(cl.Locale.LOCALE_DOMAIN) entry_type.category = RB.RhythmDBEntryCategory.NORMAL # load plugin icon theme = Gtk.IconTheme.get_default() rb.append_plugin_source_path(theme, '/icons') what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) pxbf = GdkPixbuf.Pixbuf.new_from_file_at_size( rb.find_plugin_file(self, 'img/' + Theme(self).current\ + '/covermgr.png'), width, height) group = RB.DisplayPageGroup.get_by_id('library') self.source = CoverArtBrowserSource( shell=self.shell, name=_("CoverArt"), entry_type=entry_type, plugin=self, pixbuf=pxbf, query_model=self.shell.props.library_source.props.base_query_model) self.shell.register_entry_type_for_source(self.source, entry_type) self.shell.append_display_page(self.source, group) self.source.props.query_model.connect('complete', self.load_complete) print "CoverArtBrowser DEBUG - end do_activate"
def do_activate(self): shell = self.object db = shell.props.db model = RB.RhythmDBQueryModel.new_empty(db) entry_type = VkontakteEntryType() db.register_entry_type(entry_type) what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) icon = GdkPixbuf.Pixbuf.new_from_file_at_size(rb.find_plugin_file(self, "icon.ico"), width, height) source_group = RB.DisplayPageGroup.get_by_id("library") self.source = GObject.new(VkontakteSource, name=_("Vkontakte"), shell=shell, query_model=model, plugin=self, pixbuf=icon, entry_type=entry_type) shell.append_display_page(self.source, source_group) shell.register_entry_type_for_source(self.source, entry_type) self.source.initialise()
def __icon_cell_data_cb(self, celllayout, renderer, model, it, data): engine = self.__model.get_value(it, 0) icon_size = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)[0] pixbuf = load_icon(engine.get_icon(), Gtk.IconSize.LARGE_TOOLBAR) if pixbuf == None: pixbuf = load_icon("ibus-engine", Gtk.IconSize.LARGE_TOOLBAR) if pixbuf == None: pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE, Gtk.IconSize.LARGE_TOOLBAR) renderer.set_property("pixbuf", pixbuf)
def _sync_image_properties(self): if self._buffer.icon_name != self.props.icon_name: self._buffer.icon_name = self.props.icon_name if self._buffer.file_name != self.props.file: self._buffer.file_name = self.props.file if self.props.pixel_size == -1: valid_, width, height = Gtk.icon_size_lookup(self.props.icon_size) else: width = height = self.props.pixel_size if self._buffer.width != width or self._buffer.height != height: self._buffer.width = width self._buffer.height = height
def do_activate(self): shell = self.object db = shell.props.db model = RB.RhythmDBQueryModel.new_empty(db) entry_type = PleerEntryType() db.register_entry_type(entry_type) what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) # iconfile = Gio.File.new_for_path(self.plugin_info.get_data_dir()+"/icon.ico") iconfile = Gio.File.new_for_path(self.plugin_info.get_data_dir()+"/vk-symbolic.svg") source_group = RB.DisplayPageGroup.get_by_id("library") self.source = GObject.new(PleerSource, name=_("Pleer"), shell=shell, query_model=model, plugin=self, entry_type=entry_type, icon=Gio.FileIcon.new(iconfile)) shell.append_display_page(self.source, source_group) shell.register_entry_type_for_source(self.source, entry_type) self.source.initialise()
def do_activate(self): ''' Called by Rhythmbox when the plugin is activated. It creates the plugin's source and connects signals to manage the plugin's preferences. ''' # define .plugin text strings used for translation plugin = _('CoverArt Browser') desc = _('Browse and play your albums through their covers') print("CoverArtBrowser DEBUG - do_activate") self.shell = self.object self.db = self.shell.props.db try: entry_type = CoverArtBrowserEntryType() self.db.register_entry_type(entry_type) except NotImplementedError: entry_type = self.db.entry_register_type( 'CoverArtBrowserEntryType') cl = CoverLocale() cl.switch_locale(cl.Locale.LOCALE_DOMAIN) entry_type.category = RB.RhythmDBEntryCategory.NORMAL # load plugin icon theme = Gtk.IconTheme.get_default() rb.append_plugin_source_path(theme, '/icons') what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) pxbf = GdkPixbuf.Pixbuf.new_from_file_at_size( rb.find_plugin_file(self, 'img/' + Theme(self).current\ + '/covermgr.png'), width, height) group = RB.DisplayPageGroup.get_by_id('library') self.source = CoverArtBrowserSource(shell=self.shell, name=_("CoverArt"), entry_type=entry_type, plugin=self, pixbuf=pxbf, query_model=self.shell.props.library_source.props.base_query_model) self.shell.register_entry_type_for_source(self.source, entry_type) self.shell.append_display_page(self.source, group) self.source.props.query_model.connect('complete', self.load_complete) print("CoverArtBrowser DEBUG - end do_activate")
def __init__(self, name, language_id, handler): GObject.Object.__init__(self) self.name = name self.info_widget = None self.proposals = [] self.language_id = language_id self.handler = handler self.info_widget = None self.mark = None theme = Gtk.IconTheme.get_default() f, w, h = Gtk.icon_size_lookup(Gtk.IconSize.MENU) self.icon = theme.load_icon(Gtk.STOCK_JUSTIFY_LEFT, w, 0)
def do_activate(self): shell = self.object db = shell.props.db model = RB.RhythmDBQueryModel.new_empty(db) what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) self.source = GObject.new( ChromecastSource.ChromecastSource, name=_("Chromecast"), shell=shell, query_model=model, plugin=self ) # source_group = RB.DisplayPageGroup.get_by_id("library") # shell.append_display_page(self.source, source_group) self.source.setup()
def __init__(self): """ Initialises the object. """ super(AltToolbarShared, self).__init__() # Prepare Album Art Displaying self.album_art_db = GObject.new(RB.ExtDB, name="album-art") what, width, height = Gtk.icon_size_lookup(Gtk.IconSize.SMALL_TOOLBAR) self.icon_width = width self.cover_pixbuf = None self._controllers = {} self._tooltip_exceptions = ['album_cover'] self._moved_controls = []
def _append(self, info): path = File(info.uri).path text = '<b>%s</b>\n<span foreground="#5a5a5a" size="small">%s</span>' % \ (encode_markup_text(info.name), encode_markup_text(path)) # T: Path label in 'open notebook' dialog if info.icon and File(info.icon).exists(): w, h = strip_boolean_result( Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( File(info.icon).path, w, h) else: pixbuf = None self.append((False, info.name, text, pixbuf, info))
def append_item(self, value, text, icon_name=None, file_name=None): ''' This function adds another item to the bottom of the combo box list. If either `icon_name` or `file_name` are supplied and icon column will be added to the combo box list. Args: value (object): the value that will be returned by `get_value`, when this item is selected text (str): the user visible label for the item icon_name (str): the name of the icon in the theme to use for this item, optional and conflicting with `file_name` file_name (str): the path to a sugar (svg) icon to use for this item, optional and conflicting with `icon_name` ''' if not self._icon_renderer and (icon_name or file_name): self._icon_renderer = Gtk.CellRendererPixbuf() settings = self.get_settings() valid_, w, h = Gtk.icon_size_lookup_for_settings( settings, Gtk.IconSize.MENU) self._icon_renderer.props.stock_size = max(w, h) self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) if not self._text_renderer and text: self._text_renderer = Gtk.CellRendererText() self.pack_end(self._text_renderer, True) self.add_attribute(self._text_renderer, 'text', 1) if icon_name or file_name: if text: size = Gtk.IconSize.MENU else: size = Gtk.IconSize.LARGE_TOOLBAR valid_, width, height = Gtk.icon_size_lookup(size) if icon_name: file_name = self._get_real_name_from_theme(icon_name, size) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( file_name, width, height) else: pixbuf = None self._model.append([value, text, pixbuf, False])