I have a simple page that I want to display a menu and toolbar.  I
have followed the tutorials and have made some customizations to the
basic code snippet found at

http://www.pygtk.org/pygtk2tutorial/examples/uimanager.py

However my customized code does not display the menu bar.  It displays
the toolbar though.  The terminal output is

--------------------------------------------------------------------------------
gui.py:79: GtkWarning: Quit: missing action
  menubar = uimanager.get_widget('/MenuBar')
--------------------------------------------------------------------------------

Line 79 is this

menubar = uimanager.get_widget('/MenuBar')

Thank you for any help in advanced.

Here is the code

--------------------------------------------------------------------------------

#!/usr/bin/env python
#
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import pygtk
pygtk.require('2.0')
import gtk

class d3_gui:
        ui = '''<ui>
                <menubar name="MenuBar">
                        <menu action="File">
                                <menuitem name="Quit"/>
                        </menu>
                </menubar>
                <toolbar name="ToolBar">
                        <toolitem action="Quit"/>
                </toolbar>
        </ui>'''

        def __init__(self):
                # Setup the window
                window = gtk.Window()

                # Kill the program if it's closed
                window.connect("destroy", lambda w: gtk.main_quit())

                # Set title and window size
                window.set_title("d3vscan")
                window.set_size_request(640, 480)

                # setup the widget container
                vbox = gtk.VBox()
                window.add(vbox)

                # Setup uimanager for menu and toolbar
                uimanager = gtk.UIManager()

                # Add accelerator group
                accelgroup = uimanager.get_accel_group()
                window.add_accel_group(accelgroup)

                # Create an ActionGroup
                actiongroup = gtk.ActionGroup('d3_gui')
                self.actiongroup = actiongroup

                # Create actions
                actiongroup.add_actions(
                        [
                                ('Quit', gtk.STOCK_QUIT, '_Quit me!', None,
                                'Quit the Program', self.quit_d3),
                                ('File', None, '_File')
                        ]
                )

                actiongroup.get_action('Quit').set_property('short-label',
'_Quit')

                # Attach the action group
                uimanager.insert_action_group(actiongroup, 0)

                # Add a UI description
                uimanager.add_ui_from_string(self.ui)

                # make menu
                menubar = uimanager.get_widget('/MenuBar')
                vbox.pack_start(menubar, False)

                # Create toolbar
                toolbar = uimanager.get_widget('/ToolBar')
                vbox.pack_start(toolbar, False)

                window.show_all()
                return

        def quit_d3(self, b):
                print 'Quitting program'
                gtk.main_quit()

def main():
        gtk.main()
        return 0

if __name__ == "__main__":
        d3 = d3_gui()
        gtk.main()

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to