[pygtk] Display tooltips in status bar
Chris Lambacher
chris at kateandchris.net
Sun May 14 00:38:40 WST 2006
On Sat, May 13, 2006 at 12:23:19PM +0200, Jarek Zgoda wrote:
> It requires using uimanager, which is complicated for me. ;)
uimanager is not hard. It just takes a bit of time to get the pieces you need
sorted out. Once you have that, it is the easiest thing going for menus and
toolbars.
>
> Any possibility for glade-based ui?
I mix glade and uimanager quite easily. I use glade to generate subsections
of my ui and join them together with a little code. I always found the glade
method of doing Toolbars and Menus to be kind of annoying anyways. With UI
Manager you can have a toolbar, a top menu and a context menu that all operate
against one action just by adding a little xml.
When you are starting out, just ignore merge ids and removing ui descriptions.
When you get to adding action groups and actions that gtk.ActionGroup has the
functions add_actions, add_toggle_actions and add_radio_actions which means
you can do something like this:
import pygtk
import gtk
def do_file_quit(*args): gtk.main_quit()
def do_file_open(*args): print 'Open'
def do_file_close(*args): print 'Close'
uistr = '''
<ui>
<menubar name="MenuBar">
<menu action="File">
<menuitem action="FileOpen"/>
<menuitem action="FileClose"/>
<separator/>
<menuitem action="FileQuit"/>
</menu>
</menubar>
<toolbar name="Toolbar">
<toolitem action="FileOpen"/>
<toolitem action="FileClose"/>
<separator/>
<toolitem action="FileQuit"/>
</toolbar>
</ui>'''
ui = gtk.UIManager()
ui.add_ui_from_string(uistr)
al=[('File', None, 'File'),
('FileOpen', gtk.STOCK_OPEN, 'Open', None, 'Open a file', do_file_open),
('FileClose', gtk.STOCK_CLOSE, 'Close', None, 'Close file',
do_file_close),
('FileQuit', gtk.STOCK_QUIT, 'Quit', None, 'Exit application',
do_file_quit)]
ag = gtk.ActionGroup('myactions')
ag.add_actions(al)
ui.insert_action_group(ag, -1)
mb = ui.get_widget('/MenuBar')
tb = ui.get_widget('/Toolbar')
wndmain = gtk.Window()
vbox = gtk.VBox()
vbox.pack_start(mb, False)
vbox.pack_start(tb, False)
# XXX load some ui elements from glade and add them to the vbox
wndmain.add(vbox)
wndmain.set_default_size(200,75)
wndmain.show_all()
gtk.main()
More information about the pygtk
mailing list