[Sugar-devel] ASCII keypresses
Art Hunkins
abhunkin at uncg.edu
Mon Aug 15 21:54:36 EDT 2011
To clarify:
an "a" keypress needs to be sent for a single cycle, then nothing further
until another key - or another "a" - is pressed.
It's not clear to me that the second "a" would be sent, without somehow
checking that the first one had been released.
And then, of course, a different key could be pressed before the first one
was released. This could require the status of a good number of keys (all of
them?) to be stored and tested.
Ugh.
Art Hunkins
----- Original Message -----
From: "James Cameron" <quozl at laptop.org>
To: "Art Hunkins" <abhunkin at uncg.edu>
Cc: <sugar-devel at lists.sugarlabs.org>
Sent: Monday, August 15, 2011 6:44 PM
Subject: Re: [Sugar-devel] ASCII keypresses
> 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