summaryrefslogtreecommitdiff
path: root/voctogui/lib/toolbar/composition.py
blob: 0185b7dd6aba8128f79f0ff20a3dc6730a10312e (plain)
  1. import logging
  2. from gi.repository import Gtk
  3. class CompositionToolbarController(object):
  4. """ Manages Accelerators and Clicks on the Composition Toolbar-Buttons """
  5. def __init__(self, drawing_area, win, uibuilder):
  6. self.log = logging.getLogger('CompositionToolbarController')
  7. accelerators = Gtk.AccelGroup()
  8. win.add_accel_group(accelerators)
  9. composites = [
  10. 'composite-fullscreen',
  11. 'composite-picture-in-picture',
  12. 'composite-side-by-side-equal',
  13. 'composite-side-by-side-preview'
  14. ]
  15. for idx, name in enumerate(composites):
  16. key, mod = Gtk.accelerator_parse('F%u' % (idx+1))
  17. btn = uibuilder.find_widget_recursive(drawing_area, name)
  18. btn.set_name(name)
  19. # Thanks to http://stackoverflow.com/a/19739855/1659732
  20. btn.get_child().add_accelerator('clicked', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  21. btn.connect('toggled', self.on_btn_toggled)
  22. def on_btn_toggled(self, btn):
  23. if not btn.get_active():
  24. return
  25. self.log.info("on_btn_toggled: %s", btn.get_name())