Hi all,

I am currently learning Python and PyGTK by programming a simple
application and noticed a strange behaviour of accelerators in
connection with UIManager:

In my program, I use UIManager to create a toolbar, but I don't use a
menu. Everything seems to work fine except for the accelerators.
A reduced version of my code is attached.

Here are some observations I made (on Debian Lenny, PyGTK 2.12):

 * In the attached program, the accelerators <Control>a and <Control>r
   do not work.

 * When commenting out the size request in line9, <Control>a works but
   <Control>r still doesn't initially. However, after clicking on the
   arrow to expand the toolbar, <Control>r works as well.

 * Similarly in the example program from
       http://www.pygtk.org/pygtk2tutorial/examples/uimanager.py
   All accelerators work fine, but if the menu is not created (comment
   out lines 82 and 83), they don't work at all.

What is the reason for this strange behaviour? Is there a way to use
accelerators when creating only a toolbar but not a menu?

Thanks a lot for your help and your great work on PyGTK,

Eike
#! /usr/bin/env python
# -*- coding: UTF-8 -*-

import gtk

class MainWindow:
    def __init__(self):
        window = gtk.Window()
        window.set_size_request(100, 100)

        vbox = gtk.VBox()
        window.add(vbox)

        uimanager = gtk.UIManager()
        accelgroup = uimanager.get_accel_group()
        window.add_accel_group(accelgroup)
        action_group = gtk.ActionGroup('my_actions')
        action_group.add_actions([
            ('add', gtk.STOCK_ADD, None, '<Control>a', 'Add action',
                self.add),
            ('remove', gtk.STOCK_REMOVE, None, '<Control>r',
                'Remove action', self.remove)])
        uimanager.insert_action_group(action_group, 0)
        ui = """<ui>
        <toolbar name="Toolbar">
            <toolitem action="add"/>
            <toolitem action="remove"/>
        </toolbar>
        </ui>"""
        uimanager.add_ui_from_string(ui)

        toolbar = uimanager.get_widget('/Toolbar')
        vbox.pack_start(toolbar, False)

        window.connect('destroy', self.destroy)
        window.show_all()


    def destroy(self, widget, data = None):
        gtk.main_quit()

    def add(self, widget):
        print 'add action'

    def remove(self, widget):
        print 'remove action'


if __name__ == '__main__':
    my_app = MainWindow()
    gtk.main()

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to