[pygtk] Simple question on reusing stock item
Alessandro Dentella
sandro at e-den.it
Tue Feb 10 16:45:59 WST 2009
On Mon, Feb 09, 2009 at 02:24:35PM +0000, Amondo Roquentin wrote:
> John Finlay wrote:
>
> > A MenuItem is a Container so you can add anything to it. In your case
> > create an empty MenuItem and add an HBox containing an Image and a Label.
>
> Is there a policy on the spacing to apply to HBoxes in this
> circumstance? For example, should the spacing be zero or a fixed number?
I don't have the answer, but I can point out 2 things that I wrote yesterday
erroneusly to John instead of the list (see other mail on Repy-To).
1. the code I attach to this message adds the icon but the alignment is
wrong as can be seen in this image ex.:
http://www.e-den.it/misc/menu.png
2. in pygtk FAQ tere are 2 aswers. (It's a pity on Sunday the pygtk FAQ was
unreachable) and the hint there shows that you can write:
item = gtk.ImageMenuItem('Foo')
even thought official docs say:
gtk.ImageMenuItem(stock_id=None, accel_group=None)
This works correctly
sandro
*:-)
--
Sandro Dentella *:-)
http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy
####################### bad ####################################
code that leads to uncorrect alignment:
class StockMenuItem(gtk.MenuItem):
def __init__(self, label, stock, size=gtk.ICON_SIZE_MENU):
gtk.MenuItem.__init__(self)
label = gtk.AccelLabel(label)
hbox = gtk.HBox(spacing=5)
image = gtk.Image()
image.set_from_stock(stock, size)
hbox.add(image)
hbox.add(label)
self.add(hbox)
self.show_all()
More information about the pygtk
mailing list