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

Daniel Narvaez dwnarvaez at gmail.com
Thu Feb 28 11:06:07 EST 2013


Two things you could try:

- set_visible_window(True) the event box and also set_can_focus

- Remove the box and set_can_focus the image.

On Thursday, 28 February 2013, James Simmons wrote:

> Gonzalo,
>
> The problem with that it I want the arrow keys to page through the images
> only when the image has the focus.  There are other places in the Activity
> where I don't want to interfere with the arrow keys.  For instance, you can
> make annotations for a specific image.
>
> I notice that GtkImage is a subclass of GtkWidget, so maybe that means
> that I don't need the event box anymore.  Maybe the image itself can accept
> the focus and receive the events.  The problem I have with that is that the
> old GTK made Image extend Widget also, and as I remember it you couldn't
> get events from an Image.  It was years ago.  Maybe I've been doing it
> wrong the whole time.
>
> James Simmons
>
>
> On Wed, Feb 27, 2013 at 6:24 PM, Gonzalo Odiard <gonzalo at laptop.org<javascript:_e({}, 'cvml', 'gonzalo at laptop.org');>
> > wrote:
>
>> Can you catch the key-press-event in the activity class?
>> I think other activities like Read or Terminal do this.
>>
>> Gonzalo
>>
>> On Wed, Feb 27, 2013 at 1:53 PM, James Simmons <nicestep at gmail.com<javascript:_e({}, 'cvml', 'nicestep at gmail.com');>
>> > wrote:
>>
>>> Aneesh,
>>>
>>> I'm trying to incorporate your GTK3 update to View Slides and release
>>> the result on ASLO.  The problem I'm still having is that I cannot page
>>> through the images using the keyboard as I used to.  What I did in the past
>>> was to nest the image control in an event box and make the event box able
>>> to accept the focus.  Then the user clicks on the image with the mouse to
>>> set the focus and at that point the event box receives key press events.
>>>
>>> When you upgraded View Slides to use GTK3 you removed the code to make
>>> the event box focusable.  I have tried to replace the missing line of code
>>> with what seems to be the GTK3 equivalent but it isn't working.  I've done
>>> a lot of google searches trying to figure out the problem and I'm not
>>> getting anywhere.  I cannot release View Slides as it is.  It really needs
>>> to be able to navigate through the images with the keyboard to be usable.
>>>
>>> I'm hoping you might have some thoughts or maybe an idea of how to do
>>> the keyboard paging a different way.
>>>
>>> James Simmons
>>>
>>>
>>> On Mon, Feb 25, 2013 at 6:20 AM, Manuel Quiñones <manuq at laptop.org<javascript:_e({}, 'cvml', 'manuq at laptop.org');>
>>> > wrote:
>>>
>>>> Hi James,
>>>>
>>>> 2013/2/24 James Simmons <nicestep at gmail.com <javascript:_e({}, 'cvml',
>>>> 'nicestep at gmail.com');>>:
>>>> > 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.
>>>>
>>>> Have you tried self.eventbox.grab_focus() ?
>>>>
>>>>
>>>> http://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-grab-focus
>>>>
>>>> --
>>>> .. manuq ..
>>>>
>>>
>>>
>>> _______________________________________________
>>> Sugar-devel mailing list
>>> Sugar-devel at lists.sugarlabs.org <javascript:_e({}, 'cvml',
>>> 'Sugar-devel at lists.sugarlabs.org');>
>>> http://lists.sugarlabs.org/listinfo/sugar-devel
>>>
>>>
>>
>

-- 
Daniel Narvaez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20130228/b5e1e037/attachment-0001.html>


More information about the Sugar-devel mailing list