[pygtk] UIManager problems

mycophyta at gmx.net mycophyta at gmx.net
Sun May 16 19:44:11 WST 2010


Hi there, i have problems setting up a propper Menubar with the gtk.UIManager. 2 Years ago i made a GUI with the UIManager but i deleted it and forgot how to do it. I have read through the pygtk-tutorial and followed the example programm to do it but the Menubar wont show. I have some more questions and wrote them into the comments of the code. Maybe someone can tell we where i am wrong.

#_*_coding: utf-8_*_
import gtk
import pygtk

class MainWin:
	
	ui = '''<ui>
    		    <menubar name="MenuBar">
        		<menu action="Datei">
	    		    <menuitem action="Beenden"/>
			</menu>
			<menu action="Hilfe">
	    		    <menuitem action="Uber"/>
			</menu>
    		    </menubar>
		</ui>'''

	def quit_app(self):
		gtk.main_quit()

	def __init__(self):
		
		mainwin = gtk.Window(gtk.WINDOW_TOPLEVEL)
		mainwin.set_title("Test App")
		mainwin.set_default_size(300, 200)
		mainwin.set_border_width(10)
		mainwin.connect("destroy", lambda quit: gtk.main_quit())
		vbox = gtk.VBox()
		
		uimanager = gtk.UIManager()
#What is an accelgroup? What accelerates it? I'm just following the Tut.
#Didnt understand the Tut in its decription.
                accelgroup = uimanager.get_accel_group()
		mainwin.add_accel_group(accelgroup)
		actiongroup = gtk.ActionGroup('MainWin')
		self.actiongroup = actiongroup
#Where is the descriptoin of add_actions funktion to be found?
#I think its add_actions([(xml defined pos, img i.e. Stock, label, dont 
#know, tooltip, funktion to be executed)])

                actiongroup.add_actions([('Beenden', gtk.STOCK_QUIT, '_Beenden',
					   None, 'Beendet das Programm', self.quit_app),
					   ('Datei', None, '_Datei'),
					   ('Hilfe', None, '_Hilfe'),
					   ('Uber', None, '_Uber')])
		#
                uimanager.insert_action_group(actiongroup, 0)
		uimanager.add_ui_from_string(self.ui)
		menubar = uimanager.get_widget('/MenuBar')
		vbox.pack_start(menubar, False)

		vbox.show()
		mainwin.show_all()
		


	def main(self):
		gtk.main()

if __name__ == "__main__":
	MainWin().main()

Thanks in advance
bye
-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01


More information about the pygtk mailing list