aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/toolbar/composition.py
blob: f473ccf54b134863ca7699417ba2ad6aad2fd815 (plain)
  1. import logging
  2. from gi.repository import Gtk
  3. import lib.connection as Connection
  4. class CompositionToolbarController(object):
  5. """ Manages Accelerators and Clicks on the Composition Toolbar-Buttons """
  6. def __init__(self, drawing_area, win, uibuilder):
  7. self.log = logging.getLogger('CompositionToolbarController')
  8. accelerators = Gtk.AccelGroup()
  9. win.add_accel_group(accelerators)
  10. composites = [
  11. 'fullscreen',
  12. 'picture_in_picture',
  13. 'side_by_side_equal',
  14. 'side_by_side_preview'
  15. ]
  16. self.composite_btns = {}
  17. for idx, name in enumerate(composites):
  18. key, mod = Gtk.accelerator_parse('F%u' % (idx+1))
  19. btn = uibuilder.find_widget_recursive(drawing_area, 'composite-'+name.replace('_', '-'))
  20. btn.set_name(name)
  21. # Thanks to http://stackoverflow.com/a/19739855/1659732
  22. btn.get_child().add_accelerator('clicked', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  23. btn.connect('toggled', self.on_btn_toggled)
  24. self.composite_btns[name] = btn
  25. # connect event-handler and request initial state
  26. Connection.on('composite_mode', self.on_composite_mode)
  27. Connection.send('get_composite_mode')
  28. def on_btn_toggled(self, btn):
  29. if not btn.get_active():
  30. return
  31. btn_name = btn.get_name()
  32. self.log.info('composition-mode activated: %s', btn_name)
  33. Connection.send('set_composite_mode', btn_name)
  34. def on_composite_mode(self, mode):
  35. self.log.info('on_composite_mode callback w/ mode %s', mode)
  36. self.composite_btns[mode].set_active(True)