[pygtk] emulate Live Bookmarks buttons?
Karl Ostmo
kostmo at gmail.com
Sat Sep 6 16:50:25 WST 2008
Hello,
I am trying to create a button the behaves and looks like the "Live
Bookmark" or "Smart Bookmarks" buttons in the Bookmarks Toolbar in Firefox
3. E.g. - I would like it to have an icon, text, and a downward-pointing
gtk.Arrow on the right side, and the button should stay depressed while the
popup menu is open.
I would actually prefer for this button to be part of a gtk.Toolbar, such as
a gtk.ToolButton. However, gtk.MenuToolButton does not do what I want; that
widget has the menu part split into a separate button, as in the "Recent
pages" next to the Forward and Back buttons in Firefox 3 (Linux version).
Trying to pack a gtk.Arrow into a gtk.Button gives unexpected results; the
arrow always ends up between the label and the icon, even after applying
"reorder_child(...)". I am also not sure how to attach the menu to a button
such that the button stays depressed while the menu is up. My code for the
unsuccessful attempts is below. Suggestions would be much appreciated!
Karl
#!/usr/bin/python
from pygtk import require
require('2.0')
import gtk
class Playground(gtk.Window):
def __init__(self):
gtk.Window.__init__( self, gtk.WINDOW_TOPLEVEL )
vbox = gtk.VBox(False)
self.add(vbox)
vbox.set_size_request(200, -1)
toolbar = gtk.Toolbar()
toolbutton = gtk.ToolButton()
toolbutton.set_label("Add")
# ATTEMPT NUMBER ONE
toolbutton_icon_widget = gtk.HBox()
img = gtk.Image()
img.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_SMALL_TOOLBAR)
toolbutton_icon_widget.pack_start(img, False, False)
arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
toolbutton_icon_widget.pack_start(arrow, False, False)
menu = gtk.Menu()
[menu.append(gtk.MenuItem(video_source)) for video_source in
["Milk", "Cookies"]]
menu.show_all()
menu.attach_to_widget( toolbutton, None ) # This doesn't work :(
toolbutton.set_icon_widget(toolbutton_icon_widget)
toolbar.insert(toolbutton, -1)
# ATTEMPT NUMBER TWO
menu_button = gtk.MenuToolButton( gtk.STOCK_ADD )
menu = gtk.Menu()
[menu.append(gtk.MenuItem(video_source)) for video_source in
["Peas", "Carrots"]]
menu.show_all()
menu_button.set_menu(menu)
toolbar.insert(menu_button, -1)
vbox.pack_start(toolbar, False, False)
# ATTEMPT NUMBER THREE
add_button = gtk.Button( "Add pipeline", gtk.STOCK_ADD )
add_button.set_relief( gtk.RELIEF_NONE )
container = add_button.get_children()[0].get_children()[0]
arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
container.reorder_child(arrow, -1) # doesn't put the arrow at the
end :(
container.pack_start( arrow, False, False )
vbox.pack_start(add_button, False, False)
self.show_all()
if __name__ == "__main__":
application = Playground()
gtk.main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20080906/4e25be3a/attachment.htm
More information about the pygtk
mailing list