[pygtk] Evaluation key combinations
Lang Hurst
lang at tharin.com
Wed Jun 20 17:38:09 WST 2012
On 06/19/2012 10:03 AM, Lang Hurst wrote:
> I wrote a little app awhile ago which used a bunch of hotkeys
> (shortcuts, whatever they are called) like CTRL-G, ALT-N, etc. I used
> something very similar to this code:
>
> if event.state & gtk.gdk.CONTROL_MASK | gtk.gdk.MOD2_MASK:
>
> and so on. I'm trying to re-write my old application using pyGObject
> and am getting errors referencing no gdk module. Is there a quick way
> of just doing:
>
> if CTRL-B is pressed:
> do_something()
>
> Thanks.
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
>
OK, figured it out. Added this to the top of my script:
from gi.repository import Gtk, Gdk
Have this in my class init:
self.window.connect("key_press_event", self.combo_catcher)
And then have my code set up like this:
def combo_catcher(self, widget, event):
keyname = Gdk.keyval_name(event.keyval)
ctrl = event.state & Gdk.ModifierType.CONTROL_MASK
if ctrl:
print 'Control was pushed with ', keyname
got most of that from a stackoverflow post here:
http://stackoverflow.com/questions/10978447/python-gtk3-evince-viewer-how-to-reload-document
I can get to sleep now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20120620/6fbb74f2/attachment.html>
More information about the pygtk
mailing list