hotkey support?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

hotkey support?

Tom Roche

Apologies if this is a FAQ, but I haven't seen anything in the FAQ,
wiki, or references (or even googling) regarding this: how to support
hotkeys (or registered global key bindings) with PyGTK? What I mean:

I'd like for data from a barcode scanner to go to a particular file or
process, not just to whatever is consuming stdin. (For more details
about the usecase, see the thread starting @

http://mail.python.org/pipermail/tutor/2010-March/075438.html

) One suggestion is to prefix an Alt-keychord, Ctrl-keychord, or
function key to the scanner output, and to register the prefixed key
as a hotkey. I know the particular barcode scanner I'm using claims to
support a wide variety of prefix keys (per the PDF

http://tinyurl.com/waspWLS9500manual

pages 147-148, 169-170, 174-175, 177-178), and google led me to

http://kaizer.se/wiki/python-keybinder
> a python module for gtk-based applications registering global key
> bindings. [...] This package has taken the python bindings for
> Tomboy's keybinder from the Deskbar Applet project, and broken it
> out to be a standalone module.

However I haven't seen anything explaining (preferably at a newbie
level) how to configure a PyGTK app to listen for and consume a
registered hotkey. I did find a recent post to this list

http://www.daa.com.au/pipermail/pygtk/2009-April/016972.html
> Is it possible to install a global keyboard shortcut, so if the user
> presses Ctrl-Alt-X anywhere, and my pygtk application is running, my
> application would get an event?

but no replies to it. Can anyone show/tell me how to handle hotkeys in
PyGTK?

TIA, Tom Roche <[hidden email]>
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: hotkey support?

Johannes Mockenhaupt
On 03/30/2010 03:36 AM, Tom Roche wrote:
[...]
 > http://www.daa.com.au/pipermail/pygtk/2009-April/016972.html
 >> Is it possible to install a global keyboard shortcut, so if the user
 >> presses Ctrl-Alt-X anywhere, and my pygtk application is running, my
 >> application would get an event?

Yes, that's exactly what python-keybinder does.

 > but no replies to it. Can anyone show/tell me how to handle hotkeys in
 > PyGTK?

import keybinder

def callback():
     pass  #TODO

keybinder.bind('<Alt>X', callback)


print keybinder.bind.__doc__
 >> bind (keystring, callback, user_data) -> bool
 >>
 >> Return True on success.
 >> Will raise KeyError if keystring is already bound.

Joe
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/