[Sugar-devel] ASCII keypresses

James Cameron quozl at laptop.org
Mon Aug 15 18:44:35 EDT 2011


On Mon, Aug 15, 2011 at 06:23:07PM -0400, Art Hunkins wrote:
> In a new activity I'm working on, I'm catching (and passing on)
> ASCII keypresses with the following Python snippet:
> 
> def onKeyPress(self, widget, event):
>   if self.p:
>     self.w.set_channel("ascii", event.keyval)
> 
> def playcsd(self, widget):
>   if self.p == False:
>     self.p = True
>     self.w.play()
>     self.but.child.set_label("STOP !")
>     self.connect("key-press-event", self.onKeyPress)
> 
> 
> Basically the code works; I need, however, for the keypress to be
> passed on *for a single cycle only*, and for the routine also to
> accommodate repeat keypresses.

For a single cycle only, assuming by cycle you mean a key press cycle,
you might disconnect the signal that you connected in playcsd.  This
will prevent further key press events from being propagated to your
onKeyPress function.

But then you wouldn't catch repeat key press events.  So I'm just
utterly confused as to what you are looking for.

http://dev.laptop.org/git/projects/olpcquotes/commit/?id=4bd778fd9f5d05355de47331dff6d3a89b90bded
suggests you should return either True or False from the onKeyPress
function.  The default in PyGTK is False, which means the key press
event will be propagated further.  So the widget with focus will also
get the event.  This might not be what you want, but as I don't really
understand what you want I'm not sure if it matches your problem.

You might capture also key-release-event ... for interest.  ;-)

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list