John Hunter <[EMAIL PROTECTED]> writes:

> While I know it is generally frowned up on to use stock buttons for
> purposes other than their original intentions to preserve consistent
> look and feel across applications, I often find myself wanting to use
> a different label with a stock icon.
> 
> I suspect this isn't possible from my reading of the docs, but I
> thought I'd ask.  I'd like to be able to do something like

People have suggested some ways to do this that work, but I find them
a bit hackish.  It's a few more lines of code, but I think it's better
to register your own stock icons that reuse images from existing stock
items.  This also gives you accelerators and themability.


def register_stock_icons():
    items = [('pg-create', '_Create', 0, 0, None),
             ('pg-alter', '_Alter', 0, 0, None),
             ('pg-drop', '_Drop', 0, 0, None),
             ]

    # We're too lazy to make our own icons, so we use regular stock icons.
    aliases = [('pg-create', gtk.STOCK_NEW),
               ('pg-alter', gtk.STOCK_PROPERTIES),
               ('pg-drop', gtk.STOCK_DELETE),
               ]

    gtk.stock_add(items)

    factory = gtk.IconFactory()
    factory.add_default()

    for new_stock, alias in aliases:
        icon_set = gtk.icon_factory_lookup_default(alias)
        factory.add(new_stock, icon_set)


if __name__ == '__main__':

    win = gtk.Window()
    win.connect('delete-event', gtk.mainquit)

    register_stock_icons()

    bb = gtk.HButtonBox()
    win.add(bb)

    # Show our relabeled icons.
    b_create = gtk.Button(stock='pg-create')
    b_alter = gtk.Button(stock='pg-alter')
    b_drop = gtk.Button(stock='pg-drop')
    bb.add(b_create)
    bb.add(b_alter)
    bb.add(b_drop)

    # The stock items we copied are still available unchanged.
    bb.add(gtk.Button(stock=gtk.STOCK_NEW))
    bb.add(gtk.Button(stock=gtk.STOCK_PROPERTIES))
    bb.add(gtk.Button(stock=gtk.STOCK_DELETE))

    win.show_all()
    gtk.main()

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to