def register_stock_icons(): ctrlshift = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK icons = [('odml-logo', '_odML', 0, 0, ''), ('odml-add-Section', 'Add _Section', ctrlshift, ord("S"), ''), ('odml-add-Property', 'Add _Property', ctrlshift, ord("P"), ''), ('odml-add-Value', 'Add _Value', ctrlshift, ord("V"), ''), ] gtk.stock_add(icons) # Add our custom icon factory to the list of defaults factory = gtk.IconFactory() factory.add_default() img_dir = get_image_path() for stock_icon in icons: icon_name = stock_icon[0] img_path = os.path.join(img_dir, "%s.png" % icon_name) try: icon = load_pixbuf(img_path) icon_set = gtk.IconSet(icon) for icon in load_icon_pixbufs(icon_name): src = gtk.IconSource() src.set_pixbuf(icon) icon_set.add_source(src) factory.add(icon_name, icon_set) except gobject.GError, error: print 'failed to load icon', icon_name, error
def __reload_image (self): """ Load the image specified by stock ID or icon name so it can be displayed. """ self.__normal_pixbuf = None self.__mouseover_pixbuf = None size = self.__preferred_size () if self.__stock_id is not None: self.__normal_pixbuf = panflute.applet.stock.render_icon_pixel_size (self, self.__stock_id, size) if self.__normal_pixbuf is None: self.log.warn ("Unable to render stock icon '{0}'".format (self.__stock_id)) elif self.__icon_name is not None: try: pixbuf = self.__icon_theme.load_icon (self.__icon_name, size, 0) # Named icons don't automatically have the "disabled widget" effect applied to them, # so do it manually if needed. if not self.props.sensitive: source = gtk.IconSource () source.set_pixbuf (pixbuf) source.set_size (gtk.ICON_SIZE_LARGE_TOOLBAR) source.set_size_wildcarded (False) self.__normal_pixbuf = self.style.render_icon (source, self.get_direction (), self.state, -1, self, "button") else: self.__normal_pixbuf = pixbuf except gobject.GError, e: self.log.warn ("Unable to load icon '{0}': {1}".format (self.__icon_name, e))
def load_icons(): items = [STOCK_ROTATE_LEFT, STOCK_ROTATE_RIGHT, STOCK_MOVE_TO_ORIGIN, STOCK_HOR_MIRROR, STOCK_VERT_MIRROR, STOCK_MULTIPLY] path = '' + os.path.join(config.resource_dir, 'icons') iconfactory = gtk.IconFactory() for item in items: gtk.stock_add([(item, '', 0, 0, ''), ]) pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(path, item + '.png')) source = gtk.IconSource() source.set_pixbuf(pixbuf) source.set_size_wildcarded(True) iconset = gtk.IconSet() iconset.add_source(source) iconfactory.add(item, iconset) #Creating aliased icons items = [(STOCK_CUTTING, _('_Cutting'), 0, 0, None), (STOCK_DONT_SAVE, _("_Don't save"), 0, 0, None), ] aliases = [(STOCK_CUTTING, gtk.STOCK_PRINT), (STOCK_DONT_SAVE, gtk.STOCK_NO), ] gtk.stock_add(items) for item, alias in aliases: iconset = gtk.icon_factory_lookup_default(alias) iconfactory.add(item, iconset) iconfactory.add_default()
def activate(self, shell): self.shell = shell self.db = shell.props.db self.library = self.shell.props.library_source self.player = shell.props.shell_player data = dict() ui_manager = shell.get_ui_manager() icon_file_name = self.find_file("echo_logo_64a.png") iconsource = gtk.IconSource() iconsource.set_filename(icon_file_name) iconset = gtk.IconSet() iconset.add_source(iconsource) iconfactory = gtk.IconFactory() iconfactory.add("genius_icon", iconset) iconfactory.add_default() data['action_group'] = gtk.ActionGroup('GeniusPluginActions') action = gtk.Action('MakeGeniusPlaylist', _('Echo Nest Recommender Playlist'), _("Make an Echo Nest Recommender playlist"), "genius_icon") action.connect('activate', self.make_playlist, shell) data['action_group'].add_action(action) ui_manager.insert_action_group(data['action_group'], 0) data['ui_id'] = ui_manager.add_ui_from_string(ui_toolbar_button) ui_manager.ensure_update() shell.set_data('GeniusPluginInfo', data)
def readImageFromFile(file, width = None, height = None, dither = None, image = None): pixbuf = getPixbuf(file) if pixbuf is None: log.warning("can't find pixmap %s" %(file,)) return None if (width is not None and height is not None and height != pixbuf.get_height() and width != pixbuf.get_width()): pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR) if image is None: p = gtk.Image() else: p = image if dither: (pixmap, mask) = pixbuf.render_pixmap_and_mask() pixmap.draw_pixbuf(gtk.gdk.GC(pixmap), pixbuf, 0, 0, 0, 0, pixbuf.get_width(), pixbuf.get_height(), gtk.gdk.RGB_DITHER_MAX, 0, 0) p = gtk.Image() p.set_from_pixmap(pixmap, mask) else: source = gtk.IconSource() source.set_pixbuf(pixbuf) source.set_size(gtk.ICON_SIZE_DIALOG) source.set_size_wildcarded(False) iconset = gtk.IconSet() iconset.add_source(source) p.set_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG) return p
def register_stock_icons(): # virtual or conda environments as well as local installs might # not have access to the system stock items so we update the IconTheme search path. print("[Info] Updating IconTheme search paths") icon_theme = gtk.icon_theme_get_default() icon_paths = lookup_resource_paths(os.path.join('share', 'icons')) for ipath in icon_paths: icon_theme.prepend_search_path(ipath) ctrlshift = gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK icons = [ ('odml-logo', '_odML', 0, 0, ''), ('odml_addSection', 'Add _Section', ctrlshift, ord("S"), ''), ('odml_addProperty', 'Add _Property', ctrlshift, ord("P"), ''), ('odml_addValue', 'Add _Value', ctrlshift, ord("V"), ''), ('odml_Dustbin', '_Delete', 0, 0, ''), ('INM6-compare-table', 'Compare_entities', ctrlshift, ord("E"), ''), ('INM6-convert-odml', 'Convert_document', ctrlshift, ord("C"), ''), ('INM6-filter-odml', 'Filter_document', ctrlshift, ord("F"), ''), ('INM6-merge-odml', 'Merge_documents', ctrlshift, ord("M"), '') ] # This method is failing (silently) in registering the stock icons. # Passing a list of Gtk.StockItem also has no effects. # To circumvent this, the *stock* and *label* properties of items # have been separated, wherever necessary. gtk.stock_add(icons) # The icons are being registered by the following steps. # Add our custom icon factory to the list of defaults factory = gtk.IconFactory() factory.add_default() for stock_icon in icons: icon_name = stock_icon[0] try: # Dependent on python environment and installation used, default gtk # and custom icons will be found at different locations. name = "%s.%s" % (icon_name, "png") img_dir = get_img_path(name) if not img_dir: print("[Warning] Icon %s not found in supported paths" % name) continue img_path = os.path.join(img_dir, name) icon = load_pixbuf(img_path) icon_set = gtk.IconSet.new_from_pixbuf(icon) for icon in load_icon_pixbufs(icon_name): src = gtk.IconSource() src.set_pixbuf(icon) icon_set.add_source(src) factory.add(icon_name, icon_set) except gobject.GError as error: print('[Warning] Failed to load icon', icon_name, error)
def base_reg_stock_icons(iconpaths, extraiconsize, items): """ Reusable base to register stock icons in Gramps ..attribute iconpaths: list of main directory of the base icon, and extension, eg: [(os.path.join(const.IMAGE_DIR, 'scalable'), '.svg')] ..attribute extraiconsize: list of dir with extra prepared icon sizes and the gtk size to use them for, eg: [(os.path.join(const.IMAGE_DIR, '22x22'), gtk.ICON_SIZE_LARGE_TOOLBAR)] ..attribute items: list of icons to register, eg: [('gramps-db', _('Family Trees'), gtk.gdk.CONTROL_MASK, 0, '')] """ # Register our stock items gtk.stock_add(items) # Add our custom icon factory to the list of defaults factory = gtk.IconFactory() factory.add_default() for data in items: pixbuf = 0 for (dirname, ext) in iconpaths: icon_file = os.path.expanduser(os.path.join( dirname, data[0] + ext)) if os.path.isfile(icon_file): try: pixbuf = gtk.gdk.pixbuf_new_from_file(icon_file) break except: pass if not pixbuf: icon_file = os.path.join(const.IMAGE_DIR, 'gramps.png') pixbuf = gtk.gdk.pixbuf_new_from_file(icon_file) ## FIXME from gtk 2.17.3/2.15.2 change this to ## FIXME pixbuf = pixbuf.add_alpha(True, 255, 255, 255) pixbuf = pixbuf.add_alpha(True, chr(0xff), chr(0xff), chr(0xff)) icon_set = gtk.IconSet(pixbuf) #add different sized icons, always png type! for size in extraiconsize: pixbuf = 0 icon_file = os.path.expanduser( os.path.join(size[0], data[0] + '.png')) if os.path.isfile(icon_file): try: pixbuf = gtk.gdk.pixbuf_new_from_file(icon_file) except: pass if pixbuf: source = gtk.IconSource() source.set_size_wildcarded(False) source.set_size(size[1]) source.set_pixbuf(pixbuf) icon_set.add_source(source) factory.add(data[0], icon_set)
def add_gtk_icon_to_stock(icon_name, label_str_localized): gtk.stock_add([(icon_name, label_str_localized, 0, 0, None)]) iconsource = gtk.IconSource() iconsource.set_icon_name(icon_name) iconset = gtk.IconSet() iconset.add_source(iconsource) icon_factory = gtk.IconFactory() icon_factory.add(icon_name, iconset) icon_factory.add_default()
def __source(abled, size): import SamplerConfig import os.path source = gtk.IconSource() filename = abled + '-' + str(size) + '.png' source.set_filename(os.path.join(SamplerConfig.pixmapsdir, filename)) return source
def icon(factory, icon_name, path): # Either the file or fullpath must be supplied, but not both: sonataset = gtk.IconSet() filename = [path] icons = [gtk.IconSource() for i in filename] for i, iconsource in enumerate(icons): iconsource.set_filename(filename[i]) sonataset.add_source(iconsource) factory.add(icon_name, sonataset) factory.add_default()
def readPixmap(fn): pixbuf = gtk.gdk.pixbuf_new_from_file(fn) source = gtk.IconSource() source.set_pixbuf(pixbuf) source.set_size(gtk.ICON_SIZE_DIALOG) source.set_size_wildcarded(gtk.FALSE) iconset = gtk.IconSet() iconset.add_source(source) p = gtk.image_new_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG) return p
def __init__(self, cell_dimension=32, cell_radius=0.11): self.__gobject_init__() AvatarManager.__init__(self, cell_dimension, cell_radius) #icon source used to render grayed out offline avatar self._icon_source = gtk.IconSource() self._icon_source.set_state(gtk.STATE_INSENSITIVE) self.set_property('xpad', 1) self.set_property('ypad', 1) #set up information of statusTransformation self._set_transformation('corner|gray')
def set_icon_for_button_and_menuitem(icon_name, button=None, menuitem=None): icon_source = gtk.IconSource() icon_source.set_icon_name(icon_name) icon_set = gtk.IconSet() icon_set.add_source(icon_source) if button: image_widget = gtk.image_new_from_icon_set(icon_set, gtk.ICON_SIZE_SMALL_TOOLBAR) button.set_icon_widget(image_widget) if menuitem: image_widget = gtk.image_new_from_icon_set(icon_set, gtk.ICON_SIZE_MENU) menuitem.set_image(image_widget)
def register(name, label, accelerator, icon_name): if accelerator == None: keyval = 0 mask = 0 else: keyval, mask = gtk.accelerator_parse(accelerator) gtk.stock_add([(name, label, mask, keyval, '')]) if icon_name: icon_source = gtk.IconSource() icon_source.set_icon_name(icon_name) icon = gtk.IconSet() icon.add_source(icon_source) icon_factory.add(name, icon) icon_factory.add_default() icons[name] = icon_name
def __init__(self, cellDimention=32, cellRadius=0.11): self.__gobject_init__() self._image = None self._dimention = cellDimention self._radius_factor = cellRadius self._offline = False #icon source used to render grayed out offline avatar self._icon_source = gtk.IconSource() self._icon_source.set_state(gtk.STATE_INSENSITIVE) self.set_property('xpad', 1) self.set_property('ypad', 1) #set up information of statusTransformation self._set_transformation('corner|gray')
def add_stock_from_pixbufs(self, stock_id, pixbufs): """ Registers a stock icon from pixbufs :param stock_id: the stock id for the icon :type stock_id: string :param pixbuf: the pixbufs of images :type pixbuf: list of :class:`gtk.gdk.Pixbuf` """ icon_set = gtk.IconSet() for pixbuf in pixbufs: icon_source = gtk.IconSource() icon_source.set_pixbuf(pixbuf) icon_set.add_source(icon_source) self.icon_factory.add(stock_id, icon_set)
def _get_insensitive_pixbuf(self, pixbuf, widget): if not (widget and widget.style): return pixbuf icon_source = gtk.IconSource() # Special size meaning "don't touch" icon_source.set_size(-1) icon_source.set_pixbuf(pixbuf) icon_source.set_state(gtk.STATE_INSENSITIVE) icon_source.set_direction_wildcarded(False) icon_source.set_size_wildcarded(False) pixbuf = widget.style.render_icon(icon_source, widget.get_direction(), gtk.STATE_INSENSITIVE, -1, widget, 'sugar-icon') return pixbuf
def add_stock_icon(id, icon_dir, icon_files, uml_class=None, option=None): global _uml_to_stock_id_map global _icon_factory set = gtk.IconSet() for icon in icon_files: source = gtk.IconSource() if icon.find('16') != -1: source.set_size(gtk.ICON_SIZE_MENU) elif icon.find('24') != -1: source.set_size(gtk.ICON_SIZE_SMALL_TOOLBAR) elif icon.find('48') != -1: source.set_size(gtk.ICON_SIZE_LARGE_TOOLBAR) source.set_filename(os.path.join(icon_dir, icon)) set.add_source(source) _icon_factory.add(id, set) if uml_class: _uml_to_stock_id_map[(uml_class, option)] = id
def _register_stock_icons(names): ifact = gtk.IconFactory() for stock_name, filenames in names: iset = gtk.IconSet() for filename in filenames: isource = gtk.IconSource() f = os.path.join(configure.imagedir, filename) isource.set_filename(f) if filename.startswith('16x16'): size = gtk.ICON_SIZE_MENU elif filename.startswith('24x24'): size = gtk.ICON_SIZE_SMALL_TOOLBAR else: size = None if size: isource.set_size(size) iset.add_source(isource) ifact.add(stock_name, iset) ifact.add_default()
def get_insensitive_pixbuf(): if not (insensitive_widget and insensitive_widget.style): return pixbuf icon_source = gtk.IconSource() # Special size meaning "don't touch" icon_source.set_size(-1) icon_source.set_pixbuf(pixbuf) icon_source.set_state(gtk.STATE_INSENSITIVE) icon_source.set_direction_wildcarded(False) icon_source.set_size_wildcarded(False) # Please note that the pixbuf returned by this function is leaked # with current stable versions of pygtk. The relevant bug is # http://bugzilla.gnome.org/show_bug.cgi?id=502871 # -- 2007-12-14 Benjamin Berg pixbuf = insensitive_widget.style.render_icon(icon_source, insensitive_widget.get_direction(), gtk.STATE_INSENSITIVE, -1, insensitive_widget, "sugar-icon") return pixbuf
def __init__(self, controller, cellDimention = 32, cellRadius = 0.11): #gobject.GObject._init_(self) self.__gobject_init__() self._pixbuf = None self._status = 'FLN' self._blocked = False self._dimention = cellDimention self._radius_factor = cellRadius #icon source used to render grayed out offline avatar self._icon_source = gtk.IconSource() self._icon_source.set_state(gtk.STATE_INSENSITIVE) self.set_property('xpad', 1) self.set_property('ypad', 1) self._theme = controller.theme self._config = controller.config #set up information of statusTransformation self._set_transformation(self._config.user['statusTransformation']) self.transId = self._config.connect('change::statusTransformation', \ self._transformation_callback)
def register(): import gtk from kiwi.environ import environ from kiwi.ui.pixbufutils import pixbuf_from_string size_dict = { GTK_ICON_SIZE_BUTTON: gtk.ICON_SIZE_BUTTON, GTK_ICON_SIZE_DIALOG: gtk.ICON_SIZE_DIALOG, GTK_ICON_SIZE_DND: gtk.ICON_SIZE_DND, GTK_ICON_SIZE_LARGE_TOOLBAR: gtk.ICON_SIZE_LARGE_TOOLBAR, GTK_ICON_SIZE_MENU: gtk.ICON_SIZE_MENU, GTK_ICON_SIZE_SMALL_TOOLBAR: gtk.ICON_SIZE_SMALL_TOOLBAR, } iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, arg in icon_info: # only load image files when our stock_id is not present if stock_id in stock_ids: continue iconset = gtk.IconSet() for size, filename in arg.items(): iconsource = gtk.IconSource() data = environ.get_resource_string('stoq', 'pixmaps', filename) if filename.endswith('png'): format = 'png' elif filename.endswith('svg'): format = 'svg' else: raise NotImplementedError(format) pixbuf = pixbuf_from_string(data, format) iconsource.set_pixbuf(pixbuf) iconsource.set_size(size_dict[size]) iconset.add_source(iconsource) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def _register_icon_set(self, icon_set, name): source = gtk.IconSource() source.set_icon_name(name) icon_set.add_source(source) self._factory.add(name, icon_set)
def activate(self, shell): self.shell = shell print "activating Hora python plugin" self.db = shell.get_property("db") print "register entry type" if hasattr(self.db, 'entry_register_type'): self.entry_type = self.db.entry_register_type("HoraEntryType") else: self.entry_type = HoraEntryType() self.db.register_entry_type(self.entry_type) group = rb.rb_source_group_get_by_name("shared") self.source = gobject.new(HoraSource, shell=self.shell, entry_type=self.entry_type, source_group=group, plugin=self, name=_("Hora")) self.shell.register_entry_type_for_source(self.source, self.entry_type) self.shell.append_source(self.source, None) self.entry_type.get_playback_uri = self.hora_get_playback_uri print "loading icon and button" icon_file_name = self.find_file("hora.svg") iconsource = gtk.IconSource() iconsource.set_filename(icon_file_name) iconset = gtk.IconSet() iconset.add_source(iconsource) iconfactory = gtk.IconFactory() iconfactory.add("hora-button", iconset) iconfactory.add_default() hora_action = gtk.Action('Hora', _('Hora'), _('Que hora Es?'), "hora-button") #action.connect('activate', self.hora, shell) hora_action.connect('activate', self.hora, shell) self.action_group = gtk.ActionGroup('HoraActionGroup') self.action_group.add_action_with_accel(hora_action, '<Control>h') self.action_group.add_toggle_actions([ ('Cron', None, '_Cron', '<Control>c', 'Activar Cron', self.cron) ]) ui_manager = shell.get_ui_manager() ui_manager.insert_action_group(self.action_group, 0) self.UI_ID = ui_manager.add_ui_from_string(ui_str) ui_manager.ensure_update() # add hora.spx fpath = self.find_file(audio_file) self.uri = fpath gconf.client_get_default().set_string(gconf_keys['button'], "Agregar a la Cola") gconf.client_get_default().set_string(gconf_keys['offset'], "0") gconf.client_get_default().set_string(gconf_keys['crontab'], "Disactivado") #self.gconf.set_string(gconf_keys['button'], "not queue") load_uri = "file://" + self.uri entry = self.db.entry_lookup_by_location(self.uri) if entry == None: print "add entry: " + load_uri entry = self.db.entry_new(self.entry_type, load_uri) self.db.set(entry, rhythmdb.PROP_TITLE, "Didza Lube") self.db.set(entry, rhythmdb.PROP_ALBUM, "HORA") self.db.set(entry, rhythmdb.PROP_ARTIST, "Radio Yaxhil")