Last active
December 18, 2018 01:47
-
-
Save thorsummoner/230bed5bbd3380bd5949 to your computer and use it in GitHub Desktop.
PyGTK3 Accelerator Demo
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
#!/usr/bin/env python2 | |
import signal | |
from gi.repository import Gtk | |
def bind_accelerator(accelerators, widget, accelerator, signal='clicked'): | |
key, mod = Gtk.accelerator_parse(accelerator) | |
widget.add_accelerator(signal, accelerators, key, mod, Gtk.AccelFlags.VISIBLE) | |
def on_recompute_base_encryption_key_hash(widget): | |
print 'Thinking... (This could take forever)' | |
def main(): | |
if 'gtk': | |
window = Gtk.Window() | |
window.connect("delete-event", Gtk.main_quit) | |
if 'accelerator-demo': | |
# Accelerators | |
accelerators = Gtk.AccelGroup() | |
window.add_accel_group(accelerators) | |
# Widget | |
target_widget = Gtk.Button('Recompute Base Encryption Key Hash') | |
target_widget.connect('clicked', on_recompute_base_encryption_key_hash) | |
window.add(target_widget) | |
# Bind | |
bind_accelerator(accelerators, target_widget, '<Control>b') | |
window.show_all() | |
signal.signal(signal.SIGINT, signal.SIG_DFL) | |
Gtk.main() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment