On Thu, Nov 18, 2004 at 11:12:48AM -0500, Chris Lambacher wrote:
> I am attempting to use UIManager to generate a ToolBar and a MenuBar.
> I want to add icons that are not stock icons, but UIManger requires
> that you use stock icons. That means that an IconFactory needs to be
> created for the icons I wish to use. IconSets need to be added to the
> IconFactory for each icon and IconSources have to be added to the
> IconSets. I have my icons and I could just write a module to create
> the IconFactory (I want to share the icons between several related
> projects), but given that I can specify my menus and toolbars in XML I
> was wondering if there was a way to do the equivalent for IconFactory
> creation. Styles obviously do something similar to this. Can I
> create a partial style and just grab the IconFactory for that style
> and run the set_default method?
I do it the way you describe, and it's a very simple bit if code. Using XML
seems like it would actually be more work. (I'd probably use a dictionary,
now instead of a list of tuples.).
import gtk
'''Registers new icons with gtk. Tries to use already existing icons
if they are available, otherwise it loads them from files.'''
ICON_INFO = [
('gnome-stock-mic', 'gnome-stock-mic.png'),
('gnome-stock-midi', 'stock_midi.png'),
('gnome-stock-attach', 'stock_attach.png'),
('classicollect-composer', 'composer.png'),
('classicollect-work', 'work.png'),
('classicollect-role', 'role.png'),
('classicollect-artist', 'artist.png'),
('classicollect-performance', 'performance.png')
]
def register_iconsets(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()
register_iconsets(ICON_INFO)
Dave Cook
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/