Created
August 28, 2010 21:30
-
-
Save seanh/555602 to your computer and use it in GitHub Desktop.
Keyboard shortcuts in PyGTK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self._window.connect("key-press-event",self._key_press_event) | |
def _key_press_event(self,widget,event): | |
keyval = event.keyval | |
keyval_name = gtk.gdk.keyval_name(keyval) | |
state = event.state | |
ctrl = (state & gtk.gdk.CONTROL_MASK) | |
if ctrl and keyval_name == 's': | |
self._notewindow.save() | |
elif ctrl and keyval_name == 'l': | |
self._searchwidget.grab_focus() | |
elif ctrl and keyval_name == 'j': | |
self._notestorewindow.next() | |
elif ctrl and keyval_name == 'k': | |
self._notestorewindow.prev() | |
elif keyval_name == "Escape": | |
self._searchwidget.clear() | |
else: | |
return False | |
return True |
ctrl = (state & gtk.gdk.CONTROL_MASK)
This seems to check if ctrl is included in the modifier keys pressed but it doesn't check if other modifiers were also pressed.
I.e. If Ctrl + Alt were pressed, along with s, the save window would also appear.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx