[Sugar-devel] How to make a GTK3 EventBox accept the focus?

James Simmons nicestep at gmail.com
Sun Feb 24 20:18:14 EST 2013


I was looking at the upgrade to GTK3 done for View Slides and it seems that
it no longer responds to the keyboard.  What I had done previously to get
it to do that was to put the image I was displaying in an event box.  I
then made the event box accept the focus like this:

self.eventbox.set_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.BUTTON_PRESS_MASK)
self.eventbox.set_flags(gtk.CAN_FOCUS)

The Gtk3 port changed the code to this:

self.eventbox.set_events(Gdk.EventMask.KEY_PRESS_MASK |
Gdk.EventMask.BUTTON_PRESS_MASK)

There was no code to make it accept the focus.  I tried adding this:

self.eventbox.set_can_focus(True)

This does not prevent the Activity from running, but it doesn't make the
Event Box focusable either.

The idea of making the event box focusable is that the user can page
through a bunch of images using the keyboard arrow keys, which is much more
convenient than clicking buttons with the mouse.

The code for the application is here:

https://git.sugarlabs.org/viewslides

The relevant file is this:

https://git.sugarlabs.org/viewslides/mainline/blobs/master/viewslides.py

I did look through what PyGtk docs I could find and there doesn't seem to
be anything for version 3.

If anyone can point me in the right direction I'd be greatly obliged.

James Simmons
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20130224/56331faf/attachment.html>


More information about the Sugar-devel mailing list