Skip to content

Instantly share code, notes, and snippets.

@thorsummoner
Last active December 18, 2018 01:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thorsummoner/230bed5bbd3380bd5949 to your computer and use it in GitHub Desktop.
Save thorsummoner/230bed5bbd3380bd5949 to your computer and use it in GitHub Desktop.
PyGTK3 Accelerator Demo
#!/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