On Sun, 2003-12-14 at 18:46, John Hunter wrote:
> I want the behavior of a button to be different depending on whether a
> modifier key is pressed when that button is pressed.  I haven't
> succeeded yet in capturing the keys pressed.  The bottom lives in a
> gtk.Toolbar.
> 
> I have tried various incantations suggested by the FAQ, eg, using an
> event box, to no avail
> 
>         iconw = gtk.Image()
>         iconw.set_from_stock(gtk.STOCK_GO_BACK, iconSize)
>         self.bLeft = self.append_item(
>             'Left',
>             'Move back in time',
>             'Private',
>             iconw,
>             self.panx,
>             0)
> 
>         def key_press(widget, key):
>             print 'press', key
> 
>         def key_release(widget, key):
>             print 'release', key
> 
>         ebox = gtk.EventBox()            
>         ebox.add(self.bLeft)
>         ebox.add_events(gdk.KEY_PRESS_MASK|gdk.KEY_RELEASE_MASK)
>         self.bLeft.add_events(gdk.KEY_PRESS_MASK|gdk.KEY_RELEASE_MASK)
>         self.bLeft.connect("scroll_event", self.panx)
>         ebox.connect("key_press_event", key_press)
>         ebox.connect("key_release_event", key_release)
> 
> The 'scroll_event' works with no extra schenanigans, but I am not
> getting any key_press or key_release events.
> 
> Any ideas?

Why use the event box?  You can add a key_press_event handler on the
button itself and that seems to work for me.

I don't know what all the values mean but I do note that in my
button_press handlers, the state attribute of the event does change when
modifier keys are pressed.  e.g. just a right mouse click and I see a
value of 16, shift right click is 17, ...

> 
> Thanks, John Hunter
> _______________________________________________
> pygtk mailing list   [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
-- 
Steve McClure <[EMAIL PROTECTED]>
Racemi, Inc.

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
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