>>>>> "Steve" == Steve McClure <[EMAIL PROTECTED]> writes:
Steve> Why use the event box? You can add a key_press_event
Steve> handler on the button itself and that seems to work for me.
I tried that first, and when it failed, went to the FAQ and read about
event boxes. It seems to have something to do with the button living
in the toolbar. Below is a standalone script that shows the problem.
There are two things that I don't understand
1) The button in the toolbar doesn't catch key press events
2) That button in the main vbox catches key presses that happen
anywhere in the window, even over the toolbar buttons.
import sys, os
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
class NavBar(gtk.Toolbar):
def __init__(self):
gtk.Toolbar.__init__(self)
iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
self.set_border_width(5)
self.set_style(gtk.TOOLBAR_ICONS)
def panx(button, direction):
print 'pan', direction
iconw = gtk.Image()
iconw.set_from_stock(gtk.STOCK_GO_BACK, iconSize)
self.bLeft = self.append_item(
'Left',
'Move back in time',
'Private',
iconw,
panx,
0)
def key_press(widget, key):
print 'toolbar button works'
self.bLeft.add_events(gdk.KEY_PRESS_MASK)
self.bLeft.connect("scroll_event", panx)
self.bLeft.connect("key_press_event", key_press)
iconw = gtk.Image()
iconw.set_from_stock(gtk.STOCK_GO_FORWARD, iconSize)
self.bRight = self.append_item(
'Right',
'Move forward in time',
'Private',
iconw,
panx,
1)
self.bRight.connect("scroll_event", panx)
toolbar = NavBar()
toolbar.show()
button = gtk.Button('Click me')
button.show()
if 1: # if 0: no key presses are captured
button.add_events(gdk.KEY_PRESS_MASK)
def key_press2(widget, event):
print 'button works'
button.connect("key_press_event", key_press2)
win = gtk.Window()
vbox = gtk.VBox()
vbox.show()
win.add(vbox)
vbox.pack_start(button, gtk.FALSE, gtk.FALSE)
vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE)
win.show()
gtk.mainloop()
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/