Beginner GTK question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dashawn888

    #1

    Beginner GTK question

    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



    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_w idget('/MenuBar')
    --------------------------------------------------------------------------------

    Line 79 is this

    menubar = uimanager.get_w idget('/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_titl e("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_a ccel_group()
    window.add_acce l_group(accelgr oup)

    # Create an ActionGroup
    actiongroup = gtk.ActionGroup ('d3_gui')
    self.actiongrou p = 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.inser t_action_group( actiongroup, 0)

    # Add a UI description
    uimanager.add_u i_from_string(s elf.ui)

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

    # Create toolbar
    toolbar = uimanager.get_w idget('/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()

  • Dave Cook

    #2
    Re: Beginner GTK question

    On 2007-03-25, dashawn888 <dashawn@gmail. comwrote:
    gui.py:79: GtkWarning: Quit: missing action
    menubar = uimanager.get_w idget('/MenuBar')
    <menuitem name="Quit"/>
    This should probably be action="Quit".

    Dave Cook

    Comment

    • dashawn888

      #3
      Re: Beginner GTK question

      On Mar 25, 5:00 pm, Dave Cook <davec...@nowhe re.netwrote:
      On 2007-03-25, dashawn888 <dash...@gmail. comwrote:
      >
      gui.py:79: GtkWarning: Quit: missing action
      menubar = uimanager.get_w idget('/MenuBar')
      <menuitem name="Quit"/>
      >
      This should probably be action="Quit".
      >
      Dave Cook

      Fixed it. :) Thanks

      Comment

      Working...