def __init__(self, label=None, stock=None, use_underline=True, icon_size=None): if stock is not None and stock in gtk.stock_list_ids(): stock_tmp = stock else: stock_tmp = gtk.STOCK_ABOUT super(self.__class__, self).__init__(stock=stock_tmp, use_underline=use_underline) if label is not None: self.set_markup(label) if stock is None: self.set_icon('') elif stock not in gtk.stock_list_ids(): self.set_icon(stock) if icon_size is not None: self.set_icon(stock, icon_size)
def make_icons_model(): import os, glob stock_icon_ls = gtk.stock_list_ids() # coot icons pixbuf_dir = os.getenv('COOT_PIXMAPS_DIR') if (not pixbuf_dir): pixbuf_dir = get_pkgdatadir() patt = os.path.normpath(pixbuf_dir + '/*.svg') coot_icon_filename_ls = glob.glob(patt) model = gtk.ListStore(gtk.gdk.Pixbuf, str, str) for icon_filename in coot_icon_filename_ls: if (not ('phenixed' in icon_filename)): if os.path.isfile(icon_filename): icon = os.path.basename(icon_filename) pixbuf = gtk.gdk.pixbuf_new_from_file( icon_filename) model.append([pixbuf, icon, icon_filename]) # build in default gtk icons icon_theme = gtk.icon_theme_get_default() for icon in stock_icon_ls: try: pixbuf = icon_theme.load_icon( icon, 16, gtk.ICON_LOOKUP_USE_BUILTIN) model.append([pixbuf, icon, None]) except: pass return model
def _load_stock_items(self): groups = { "a": gtk.ToolItemGroup("Stock Icons (A-F)"), "g": gtk.ToolItemGroup("Stock Icons (G-N)"), "o": gtk.ToolItemGroup("Stock Icons (O-R)"), "s": gtk.ToolItemGroup("Stock Icons (S-Z)") } group = groups["a"] for g in groups.values(): self.palette.add(g) items = gtk.stock_list_ids() items.sort() for i in items: #stock id names are in form gtk-foo, sort into one of the groups above try: group = groups[i[4]] except KeyError: pass b = gtk.ToolButton(i) b.set_tooltip_text(i) b.set_is_important(True) info = gtk.stock_lookup(i) if info: b.set_label(info[1].replace("_", "")) else: b.set_label(i) group.insert(b, -1)
def _load_stock_items(self): groups = { "a": gtk.ToolItemGroup("Stock Icons (A-F)"), "g": gtk.ToolItemGroup("Stock Icons (G-N)"), "o": gtk.ToolItemGroup("Stock Icons (O-R)"), "s": gtk.ToolItemGroup("Stock Icons (S-Z)"), } group = groups["a"] for g in groups.values(): self.palette.add(g) items = gtk.stock_list_ids() items.sort() for i in items: # stock id names are in form gtk-foo, sort into one of the groups above try: group = groups[i[4]] except KeyError: pass b = gtk.ToolButton(i) b.set_tooltip_text(i) b.set_is_important(True) info = gtk.stock_lookup(i) if info: b.set_label(info[1].replace("_", "")) else: b.set_label(i) group.insert(b, -1)
def set_stock_icons(st_req, st_path): import pkg_resources as pr icon_names = pr.resource_listdir(st_req, st_path) stock_ids = set(gtk.stock_list_ids()) iconfactory = gtk.IconFactory() theme = gtk.icon_theme_get_default() listed = theme.list_icons() for icon in icon_names: if icon.startswith('.'): continue iconname = icon.split('.', 1)[0] if iconname not in listed: iconres = '/'.join(['data', 'icons', icon]) iconpath = pr.resource_filename(st_req, iconres) try: pixbuf = gtk.gdk.pixbuf_new_from_file(iconpath) iconset = gtk.IconSet(pixbuf) iconfactory.add(iconname, iconset) gtk.icon_theme_add_builtin_icon(iconname, 128, pixbuf) except gobject.GError: # icon could not be loaded pass iconfactory.add_default() return theme, iconfactory
def make_icons_model(): import os, glob stock_icon_ls = gtk.stock_list_ids() # coot icons pixbuf_dir = os.getenv("COOT_PIXMAPS_DIR") if not pixbuf_dir: pixbuf_dir = os.path.join(get_pkgdatadir(), "pixmaps") patt = os.path.normpath(pixbuf_dir + "/*.svg") coot_icon_filename_ls = glob.glob(patt) model = gtk.ListStore(gtk.gdk.Pixbuf, str, str) for icon_filename in coot_icon_filename_ls: if os.path.isfile(icon_filename): icon = os.path.basename(icon_filename) pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_filename, 16, 16) model.append([pixbuf, icon, icon_filename]) # build in default gtk icons icon_theme = gtk.icon_theme_get_default() for icon in stock_icon_ls: try: pixbuf = icon_theme.load_icon(icon, 16, gtk.ICON_LOOKUP_USE_BUILTIN) model.append([pixbuf, icon, None]) except: pass return model
def get_stock_icons(): """ Get a sorted list of all available stock icons @returns: a list of tuples; (stock_label, stock_id) """ global _stock_icons if _stock_icons: return _stock_icons icons = [] for stock_id in gtk.stock_list_ids(): # Do not list stock ids starting with gazpacho-, they # are considered private if stock_id.startswith('gazpacho-'): continue stock_info = gtk.stock_lookup(stock_id) if not stock_info: # gtk-new -> New if stock_id.startswith('gtk-'): stock_label = stock_id[4:].replace('-', ' ') else: stock_label = stock_id stock_label = stock_label.capitalize() else: stock_label = stock_info[1].replace('_', '') icons.append((stock_label, stock_id)) icons.sort() _stock_icons = icons return icons
def __init_attributes(self, manager, editor): self.__manager = manager self.__editor = editor from gtk import stock_list_ids self.__image_ids = [name[4:] for name in stock_list_ids()] self.__scribes_image_ids = ("error", "pass", "fail", "scribes", "busy", "run") self.__image_dictionary = self.__map_scribes_ids() return False
def register_iconsets(self, icon_info): iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in icon_info: ## only load image files when our stock_id is not present if stock_id not in stock_ids: pixbuf = gtk.gdk.pixbuf_new_from_file(file) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def __create_model(self): store = gtk.ListStore( gobject.TYPE_PYOBJECT, gobject.TYPE_STRING) ids = gtk.stock_list_ids() ids.sort() for data in ids: info = StockItemInfo(stock_id=data) stock_item = gtk.stock_lookup(data) if stock_item: info.stock_item = stock_item else: # stock_id, label, modifier, keyval, translation_domain info.stock_item =('', '', 0, 0, '') # only show icons for stock IDs that have default icons icon_set = gtk.icon_factory_lookup_default(info.stock_id) if icon_set is None: info.small_icon = None else: # See what sizes this stock icon really exists at sizes = icon_set.get_sizes() n_sizes = len(sizes) # Use menu size if it exists, otherwise first size found size = sizes[0]; i = 0; while(i < n_sizes): if(sizes[i] == gtk.ICON_SIZE_MENU): size = gtk.ICON_SIZE_MENU break i += 1 info.small_icon = self.render_icon(info.stock_id, size) if(size != gtk.ICON_SIZE_MENU): # Make the result the proper size for our thumbnail w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) scaled = info.small_icon.scale_simple(w, h, 'bilinear') info.small_icon = scaled if info.stock_item[3] == 0: info.accel_str = "" else: info.accel_str = \ gtk.accelerator_name(info.stock_item[3], info.stock_item[2]) iter = store.append() store.set(iter, 0, info, 1, info.stock_id) return store
def __init__(self, label=None, stock=None, tooltip=None): super(self.__class__, self).__init__() if stock is not None: if stock in gtk.stock_list_ids(): if stock is not None: self.set_stock_id(stock) else: self.set_icon_name(stock) if label is not None: self.set_label(label) if tooltip is not None: self.set_tooltip_text(tooltip)
def __create_model(self): store = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING) ids = gtk.stock_list_ids() ids.sort() for data in ids: info = StockItemInfo(stock_id=data) stock_item = gtk.stock_lookup(data) if stock_item: info.stock_item = stock_item else: # stock_id, label, modifier, keyval, translation_domain info.stock_item = ('', '', 0, 0, '') # only show icons for stock IDs that have default icons icon_set = gtk.icon_factory_lookup_default(info.stock_id) if icon_set is None: info.small_icon = None else: # See what sizes this stock icon really exists at sizes = icon_set.get_sizes() n_sizes = len(sizes) # Use menu size if it exists, otherwise first size found size = sizes[0] i = 0 while (i < n_sizes): if (sizes[i] == gtk.ICON_SIZE_MENU): size = gtk.ICON_SIZE_MENU break i += 1 info.small_icon = self.render_icon(info.stock_id, size) if (size != gtk.ICON_SIZE_MENU): # Make the result the proper size for our thumbnail w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU) scaled = info.small_icon.scale_simple(w, h, 'bilinear') info.small_icon = scaled if info.stock_item[3] == 0: info.accel_str = "" else: info.accel_str = \ gtk.accelerator_name(info.stock_item[3], info.stock_item[2]) iter = store.append() store.set(iter, 0, info, 1, info.stock_id) return store
def register_iconsets(imgdir, icon_info): import os iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in icon_info.iteritems(): # only load image files when our stock_id is not present if stock_id not in stock_ids: file = os.path.join(imgdir, file) print "loading image %s" % file pixbuf = gtk.gdk.pixbuf_new_from_file(file) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def register_icons(): """Adds custom icons to the list of stock IDs.""" icon_info = {'pondus_plot': parameters.plot_button_path} iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id in icon_info: # only load image files when our stock_id is not present if stock_id not in stock_ids: icon_file = icon_info[stock_id] pixbuf = gtk.gdk.pixbuf_new_from_file(icon_file) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def register_iconset(icon_info): iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in icon_info: # only load image files when our stock_id is not present if stock_id not in stock_ids: try: pixbuf = gtk.gdk.pixbuf_new_from_file(icon_path+file) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) except: pass iconfactory.add_default() return iconfactory
def register_iconset(icon_info): iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in icon_info: # only load image files when our stock_id is not present if stock_id not in stock_ids: try: pixbuf = gtk.gdk.pixbuf_new_from_file(icon_path + file) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) except: pass iconfactory.add_default() return iconfactory
def _fillRow(self, parent, elem): #print "filling", elem #for j in elem.rows(): for r in elem.rows(): #r = elem.rows()[j] if len(r.auxId()) > 2: self._columns[1 + DflatGUINode._startcol].set_visible(True) if len(r.flagIcon()) > 0: self._columns[2 + DflatGUINode._startcol].set_visible(True) if r.costs() > 0: #print r.costs() self._columns[3 + DflatGUINode._startcol].set_visible(True) #ic =gtk.StatusIcon() #ic.set_from_file(r.flagIcon()) #piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), gtk.from_file(r.flagIcon()), r.costs()]) #piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), ic.get_gicon(), r.costs()]) #icon = None #pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale("gnome-image.png", 64, 128, False)# if r.flagIcon().endswith("png"): # icon = gtk.gdk.pixbuf_new_from_file(r.flagIcon()) #icon = gtk.image_new_from_file(r.flagIcon()) try: stock_ids = gtk.stock_list_ids() if r.flagIcon() not in stock_ids: factory = gtk.IconFactory() pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.dirname(os.path.realpath(__file__)) + "/" + r.flagIcon()) iconset = gtk.IconSet(pixbuf) factory.add(r.flagIcon(), iconset) factory.add_default() except Exception: pass # else: # icon = self.getView().render_icon(r.flagIcon(), gtk.ICON_SIZE_MENU) #icon = gtk.image_new_from_stock(r.flagIcon(), gtk.ICON_SIZE_MENU) #print r.flagIcon(), icon #print icon.get_gicon() #print icon.get_pixbuf() piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), r.flagIcon(), r.costs()]) #piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), icon.get_gicon(), r.costs()]) #piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), icon.get_pixbuf(), r.costs()]) #piter = self._treestore.append(parent, [r, r.content(), r.auxContent(), icon, r.costs()]) #print self._treestore[self._treestore.get_path()] #r.setNode(self._treestore[-1]) #r.setNode(piter) #provide treeview + rowreference within the row (as guinode) r.setNode(self) r.setRowNode(gtk.TreeRowReference(self._treestore, self._treestore.get_path(piter))) self._fillRow(piter, r)
def _register_iconsets(self): icon_info = [('com-uit', 'com-uit.png'), ('com-alarm', 'com-alarm.png'), ('com-nullast', 'com-nullast.png'), ('com-vollast', 'com-vollast.png')] iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in icon_info: if stock_id not in stock_ids: pixbuf = gtk.gdk.pixbuf_new_from_file( os.path.join(self._dir, file)) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def register_stock_icons(imgdir, prefix=""): logger.debug("Register png icons from dir '%s'" % imgdir) filelist = map(lambda fn: ("%s%s" % (prefix, fn.split(os.path.sep)[-1][:-4]), fn), \ glob.glob(os.path.join(imgdir,'*.png'))) iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in filelist: # only load image files when our stock_id is not present if stock_id not in stock_ids: #logger.debug( " [%s]" % stock_id ) pixbuf = gtk.gdk.pixbuf_new_from_file(file) pixbuf = pixbuf.scale_simple(48,48,gtk.gdk.INTERP_BILINEAR) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def register_iconsets(icon_info): try: iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() img_dir = os.path.join(os.path.dirname(__file__), 'images') for stock_id, file in icon_info: # only load image files when our stock_id is not present img_path = os.path.join(img_dir, file) if stock_id not in stock_ids: pixbuf = gtk.gdk.pixbuf_new_from_file(img_path) transparent = pixbuf.add_alpha(True, chr(255), chr(255),chr(255)) icon_set = gtk.IconSet(transparent) iconfactory.add(stock_id, icon_set) iconfactory.add_default() except gobject.GError, error: print 'failed to load GTK logo for toolbar'
def submenu(self): if self.icon: menu = gtk.ImageMenuItem(self.name) menu.set_always_show_image (True) #The defined icon stands for a STOCK_ICON if self.icon in gtk.stock_list_ids(): menu.set_image(gtk.image_new_from_stock(self.icon, gtk.ICON_SIZE_MENU)) #Else it stands for a image file else: menu.set_image(self.icon) else: menu = gtk.MenuItem(self.name) #FIXME: This raises GtkWarning: gtk_menu_attach_to_widget() menu.set_submenu(self.toplevel_widget) menu.show() return menu
def set_item_image(self, menuitem, image, size=gtk.ICON_SIZE_MENU): if image in gtk.stock_list_ids(): # StockIcon img = gtk.Image() img.set_from_stock(image, gtk.ICON_SIZE_MENU) menuitem.set_image(img) else: # from file w, h = gtk.icon_size_lookup(size) img = gtk.Image() if not os.path.exists(image): image = os.path.join(functions.install_dir(), "images", image) if not os.path.exists(image): print ("Image not found") return -1 pix = gtk.gdk.pixbuf_new_from_file_at_size(image, w, h) img.set_from_pixbuf(pix) menuitem.set_image(img)
def __init__(self, icon_file=None): import pkg_resources as pr pidareq = pr.Requirement.parse('pida') icon_names = pr.resource_listdir(pidareq, 'icons') stock_ids = set(gtk.stock_list_ids()) iconfactory = gtk.IconFactory() self.__theme = gtk.icon_theme_get_default() listed = self.__theme.list_icons() for icon in icon_names: iconname = icon.split('.', 1)[0] if iconname not in listed: iconres = '/'.join(['icons', icon]) iconpath = pr.resource_filename(pidareq, iconres) pixbuf = gtk.gdk.pixbuf_new_from_file(iconpath) iconset = gtk.IconSet(pixbuf) iconfactory.add(iconname, iconset) gtk.icon_theme_add_builtin_icon(iconname, 128, pixbuf) iconfactory.add_default() self.__iconfactory = iconfactory
def __init__(self): super(stockItems,self).__init__() self.set_title("Hello Buttons!") self.set_size_request(1000,100) list =gtk.stock_list_ids() print list[89] print list[38] toolbar =gtk.Toolbar() box1 = gtk.HBox(False, 0) print len(list) #105 for i in range(len(list)): toolbutton =gtk.ToolButton(list[i]) toolbutton.set_tooltip_text(str(i)) toolbar.insert(toolbutton,i) box1.add(toolbar) self.add(box1) self.show_all()
def register_all_png_icons(imgdir, prefix=""): """ Register all svg icons in the Icons subdirectory as stock icons. The prefix is the prefix for the stock_id. """ logger.debug("Trying to register png icons from dir '%s'" % imgdir) import glob, os filelist = map(lambda fn: ("%s%s" % (prefix, fn.split(os.path.sep)[-1][:-4]), fn), \ glob.glob(os.path.join(imgdir,'*.png'))) iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() for stock_id, file in filelist: # only load image files when our stock_id is not present if stock_id not in stock_ids: logger.debug( "loading image '%s' as stock icon '%s'" % (file, stock_id) ) pixbuf = gtk.gdk.pixbuf_new_from_file(file) pixbuf = pixbuf.scale_simple(48,48,gtk.gdk.INTERP_BILINEAR) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def set_stock_icons(st_req, st_path): import pkg_resources as pr pidareq = pr.Requirement.parse(st_req) icon_names = pr.resource_listdir(pidareq, st_path) stock_ids = set(gtk.stock_list_ids()) iconfactory = gtk.IconFactory() theme = gtk.icon_theme_get_default() listed = theme.list_icons() for icon in icon_names: if icon.startswith('.'): continue iconname = icon.split('.', 1)[0] if iconname not in listed: iconres = '/'.join(['icons', icon]) iconpath = pr.resource_filename(pidareq, iconres) pixbuf = gtk.gdk.pixbuf_new_from_file(iconpath) iconset = gtk.IconSet(pixbuf) iconfactory.add(iconname, iconset) gtk.icon_theme_add_builtin_icon(iconname, 24, pixbuf) iconfactory.add_default() return theme, iconfactory
def __init__(self, icon_file=None): #icon_file = ('/home/ali/working/pida/pida/branches/' # 'pida-ali/pida/pidagtk/icons.dat') from pkg_resources import Requirement, resource_filename icon_file = resource_filename(Requirement.parse('pida'), 'images/icons.dat') #icon_file = "/usr/share/pida/icons.dat" self.d = shelve.open(icon_file, 'r') self.cs = gtk.gdk.COLORSPACE_RGB stock_ids = set(gtk.stock_list_ids()) iconfactory = gtk.IconFactory() self.__theme = gtk.icon_theme_get_default() for k in self.d: stockname = 'gtk-%s' % k if stockname not in stock_ids: d, a = self.d[k] pixbuf = gtk.gdk.pixbuf_new_from_data(d, self.cs, *a) iconset = gtk.IconSet(pixbuf) iconfactory.add(stockname, iconset) gtk.icon_theme_add_builtin_icon(stockname, 12, pixbuf) iconfactory.add_default() self.__iconfactory = iconfactory
def register_coot_icons(): import glob iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() pixbuf_dir = os.getenv('COOT_PIXMAPS_DIR') if (not pixbuf_dir): pixbuf_dir = get_pkgdatadir() patt = os.path.normpath(pixbuf_dir + '/*.svg') coot_icon_filename_ls = glob.glob(patt) icon_info_ls = [] for full_name in coot_icon_filename_ls: name = os.path.basename(full_name) icon_info_ls.append([name, full_name]) for stock_id, filename in icon_info_ls: # only load image files when our stock_id is not present if ((stock_id not in stock_ids) and not ('phenixed' in filename)): if os.path.isfile(filename): pixbuf = gtk.gdk.pixbuf_new_from_file(filename) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
def register_coot_icons(): import glob iconfactory = gtk.IconFactory() stock_ids = gtk.stock_list_ids() pixbuf_dir = os.getenv("COOT_PIXMAPS_DIR") if not pixbuf_dir: pixbuf_dir = os.path.join(get_pkgdatadir(), "pixmaps") patt = os.path.normpath(pixbuf_dir + "/*.svg") coot_icon_filename_ls = glob.glob(patt) icon_info_ls = [] for full_name in coot_icon_filename_ls: name = os.path.basename(full_name) icon_info_ls.append([name, full_name]) for stock_id, filename in icon_info_ls: # only load image files when our stock_id is not present if (stock_id not in stock_ids) and not ("phenixed" in filename): if os.path.isfile(filename): pixbuf = gtk.gdk.pixbuf_new_from_file(filename) iconset = gtk.IconSet(pixbuf) iconfactory.add(stock_id, iconset) iconfactory.add_default()
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 name(self): return '<b>%s</b>' % self._name icons = ObjectList([ Column(title='Stock Data', cells=[ Cell('stock_name', gtk.Pixmap, use_stock=True), Cell('stock_name', str), ], sorted=False), Column('name', str, 'Name', use_markup=True), ], sortable=True) for id in gtk.stock_list_ids(): lookup = gtk.stock_lookup(id) if lookup is None: continue stock_name, name = gtk.stock_lookup(id)[:2] name = name.replace('_', '') icons.append(IconInfo(stock_name, name)) scroll = gtk.ScrolledWindow() scroll.add(icons) win = gtk.Window() win.add(scroll) win.set_size_request(600, 400) win.show_all()
def _register_theme_icons(self): stock_ids = gtk.stock_list_ids() for name in gtk.icon_theme_get_default().list_icons(): if name not in stock_ids: self._stock_add(name) self._register_theme_icon(name)
if line is None: tab.gen_doc_struct() self.update_structbrowser(tab) else: tab.goto_index(line) return #------------------------------------------------------------------------------ if __name__ == '__main__': win = gtk.Window() win.connect('destroy', lambda w: gtk.main_quit()) # Example palette pal = palette.Palette() for id in gtk.stock_list_ids(): t = [id, id, win.render_icon(id, gtk.ICON_SIZE_MENU)] pal.add_tool(t) # Side panel sp = SidePanel() sp.add_expander('tree', "Project tree", gtk.Label("Hello !")) sp.add_expander('struct', "File structure", gtk.Label("Hello !")) sp.add_expander('operators', "Operators", pal) sp.add_expander('arrows', "Arrows", gtk.Label("Hello !")) sp.add_expander('greek', "Greek letters", gtk.Label("Hello !")) sp.add_expander('diacritics', "Diacritics", gtk.Label("Hello !")) win.add(sp) # Display win.show() gtk.main()
def __init__(self, stock=None): super(self.__class__, self).__init__(stock) if stock not in gtk.stock_list_ids(): self.set_icon_name(stock)
def lookupIcon(icon): stock_ids = gtk.stock_list_ids() for stock in stock_ids: if stock == icon: return stock
class Popup(gtk.Window): def __init__(self, stack, title, message, image, leftCb, middleCb, rightCb): gtk.Window.__init__(self, type=gtk.WINDOW_POPUP) self.leftclickCB = leftCb self.middleclickCB = middleCb self.rightclickCB = rightCb self.set_size_request(stack.size_x, stack.size_y) self.set_decorated(False) self.set_deletable(False) self.set_property("skip-pager-hint", True) self.set_property("skip-taskbar-hint", True) self.connect("enter-notify-event", self.on_hover, True) self.connect("leave-notify-event", self.on_hover, False) self.set_opacity(0.2) self.destroy_cb = stack.destroy_popup_cb if type(stack.fontdesc) == tuple or type(stack.fontdesc) == list: fontH, fontM, fontC = stack.fontdesc else: fontH = fontM = fontC = stack.fontdesc main_box = gtk.VBox() header_box = gtk.HBox() self.header = gtk.Label() self.header.set_markup("<b>%s</b>" % title) self.header.set_padding(3, 3) self.header.set_alignment(0, 0) try: self.header.modify_font(pango.FontDescription(fontH)) except Exception, e: print e header_box.pack_start(self.header, True, True, 5) if stack.close_but: close_button = gtk.Image() close_button.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) close_button.set_padding(3, 3) close_window = gtk.EventBox() close_window.set_visible_window(False) close_window.connect("button-press-event", self.hide_notification) close_window.add(close_button) header_box.pack_end(close_window, False, False) main_box.pack_start(header_box) body_box = gtk.HBox() if image is not None: self.image = gtk.Image() self.image.set_size_request(70, 70) self.image.set_alignment(0, 0) if image in gtk.stock_list_ids(): self.image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) elif type(image) == gtk.gdk.Pixbuf: self.image.set_from_pixbuf(image) else: self.image.set_from_file(image) body_box.pack_start(self.image, False, False, 5) self.message = gtk.Label() self.message.set_property("wrap", True) self.message.set_size_request(stack.size_x - 90, -1) self.message.set_alignment(0, 0) self.message.set_padding(5, 10) self.message.set_markup(message) try: self.message.modify_font(pango.FontDescription(fontM)) except Exception, e: print e
def create_toolbar(self): self.toolbar =gtk.Toolbar() list =gtk.stock_list_ids() self.check_button =gtk.CheckButton() self.string="test" #----open save clear bold italic spell------------- opentb =gtk.ToolButton(gtk.STOCK_OPEN) opentb.set_tooltip_text("Open(Ctrl-o)") opentb.connect("clicked",self.open_new_note,self.string) savetb =gtk.ToolButton(gtk.STOCK_SAVE) savetb.set_tooltip_text("Save(Ctrl-s)") savetb.connect("clicked",self.save_note) cleartb =gtk.ToolButton(gtk.STOCK_CLEAR) cleartb.set_tooltip_text("Clear") cleartb.connect("clicked",self.clear_text) boldtb =gtk.ToolButton(gtk.STOCK_BOLD) boldtb.set_tooltip_text("Bold") boldtb.connect("clicked",self.bold_clicked,self.string) italictb =gtk.ToolButton(gtk.STOCK_ITALIC) italictb.set_tooltip_text("Italic") italictb.connect("clicked",self.italic_clicked,self.string) spell_cheek =gtk.ToolButton(gtk.STOCK_SPELL_CHECK) spell_cheek.set_tooltip_text("Spell_check") spell_cheek.connect("clicked",self.spell_clicked) sep = gtk.SeparatorToolItem() #---------setting isOn importance quit--------------- settingtb =gtk.ToggleToolButton(list[31]) settingtb.set_tooltip_text("Setting") settingtb.connect("clicked",self.setting) self.isOn =gtk.ToggleToolButton(list[70]) self.isOn.set_tooltip_text("On/Off") self.isOn.connect("toggled",self.set_isOn,self.check_button) importance =gtk.ToggleToolButton(gtk.STOCK_SORT_ASCENDING) importance.set_tooltip_text("Importance") #importance.connect("toggled",self.set_inportance,self.string) quittb = gtk.ToolButton(gtk.STOCK_CLOSE) quittb.set_tooltip_text("Quit") #quittb.connect("clicked",self.on_button_clicked,self.string) self.toolbar.insert(opentb, 0) self.toolbar.insert(savetb, 1) self.toolbar.insert(cleartb,2) self.toolbar.insert(boldtb, 3) self.toolbar.insert(italictb, 4) self.toolbar.insert(spell_cheek, 5) self.toolbar.insert(sep, 6) self.toolbar.insert(settingtb,7) self.toolbar.insert(self.isOn,8) self.toolbar.insert(importance,9) self.toolbar.insert(quittb, 10)
def __init__(self, stack, title, message, image, leftCb, middleCb, rightCb): gtk.Window.__init__(self, type=gtk.WINDOW_POPUP) self.leftclickCB = leftCb self.middleclickCB = middleCb self.rightclickCB = rightCb self.set_size_request(stack.size_x, stack.size_y) self.set_decorated(False) self.set_deletable(False) self.set_property("skip-pager-hint", True) self.set_property("skip-taskbar-hint", True) self.connect("enter-notify-event", self.on_hover, True) self.connect("leave-notify-event", self.on_hover, False) self.set_opacity(0.2) self.destroy_cb = stack.destroy_popup_cb if type(stack.fontdesc) == tuple or type(stack.fontdesc) == list: fontH, fontM, fontC = stack.fontdesc else: fontH = fontM = fontC = stack.fontdesc main_box = gtk.VBox() header_box = gtk.HBox() self.header = gtk.Label() self.header.set_markup("<b>%s</b>" % title) self.header.set_padding(3, 3) self.header.set_alignment(0, 0) try: self.header.modify_font(pango.FontDescription(fontH)) except Exception as e: print(e) header_box.pack_start(self.header, True, True, 5) if stack.close_but: close_button = gtk.Image() close_button.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) close_button.set_padding(3, 3) close_window = gtk.EventBox() close_window.set_visible_window(False) close_window.connect("button-press-event", self.hide_notification) close_window.add(close_button) header_box.pack_end(close_window, False, False) main_box.pack_start(header_box) body_box = gtk.HBox() if image is not None: self.image = gtk.Image() self.image.set_size_request(70, 70) self.image.set_alignment(0, 0) if image in gtk.stock_list_ids(): self.image.set_from_stock(image, gtk.ICON_SIZE_DIALOG) elif type(image) == gtk.gdk.Pixbuf: self.image.set_from_pixbuf(image) else: self.image.set_from_file(image) body_box.pack_start(self.image, False, False, 5) self.message = gtk.Label() self.message.set_property("wrap", True) self.message.set_size_request(stack.size_x - 90, -1) self.message.set_alignment(0, 0) self.message.set_padding(5, 10) self.message.set_markup(message) try: self.message.modify_font(pango.FontDescription(fontM)) except Exception as e: print(e) self.counter = gtk.Label() self.counter.set_alignment(1, 1) self.counter.set_padding(3, 3) try: self.counter.modify_font(pango.FontDescription(fontC)) except Exception as e: print(e) self.timeout = stack.timeout body_box.pack_start(self.message, True, False, 5) body_box.pack_end(self.counter, False, False, 5) main_box.pack_start(body_box) eventbox = gtk.EventBox() eventbox.set_property('visible-window', False) eventbox.set_events(gtk.gdk.BUTTON_PRESS_MASK) eventbox.connect("button_press_event", self.onClick) eventbox.add(main_box) self.add(eventbox) if stack.bg_pixmap is not None: if not type(stack.bg_pixmap) == gtk.gdk.Pixmap: stack.bg_pixmap, stack.bg_mask = gtk.gdk.pixbuf_new_from_file(stack.bg_pixmap).render_pixmap_and_mask() self.set_app_paintable(True) self.connect_after("realize", self.callbackrealize, stack.bg_pixmap, stack.bg_mask) elif stack.bg_color is not None: self.modify_bg(gtk.STATE_NORMAL, stack.bg_color) if stack.fg_color is not None: self.message.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.header.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.counter.modify_fg(gtk.STATE_NORMAL, stack.fg_color) self.show_timeout = stack.show_timeout self.hover = False self.show_all() self.x, self.y = self.size_request() #Not displaying over windows bar if os.name == 'nt': if stack.corner[0] and taskbarSide == "left": stack.edge_offset_x += taskbarOffsetx elif not stack.corner[0] and taskbarSide == 'right': stack.edge_offset_x += taskbarOffsetx if stack.corner[1] and taskbarSide == "top": stack.edge_offset_x += taskbarOffsety elif not stack.corner[1] and taskbarSide == 'bottom': stack.edge_offset_x += taskbarOffsety if stack.corner[0]: posx = stack.edge_offset_x else: posx = gtk.gdk.screen_width() - self.x - stack.edge_offset_x sep_y = 0 if (stack._offset == 0): pass else: stack.sep_y self.y += sep_y if stack.corner[1]: posy = stack._offset + stack.edge_offset_y + sep_y else: posy = gtk.gdk.screen_height()- self.y - stack._offset - stack.edge_offset_y self.move(posx, posy) self.fade_in_timer = gobject.timeout_add(100, self.fade_in)