aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/toolbar/composition.py
blob: a2b1f29cd1215b3e7250e172169e0626678f4c9f (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. self.current_composition = None
  18. for idx, name in enumerate(composites):
  19. key, mod = Gtk.accelerator_parse('F%u' % (idx+1))
  20. btn = uibuilder.find_widget_recursive(drawing_area, 'composite-'+name.replace('_', '-'))
  21. btn.set_name(name)
  22. # Thanks to http://stackoverflow.com/a/19739855/1659732
  23. btn.get_child().add_accelerator('clicked', accelerators, key, mod, Gtk.AccelFlags.VISIBLE)
  24. btn.connect('toggled', self.on_btn_toggled)
  25. self.composite_btns[name] = btn
  26. # connect event-handler and request initial state
  27. Connection.on('composite_mode', self.on_composite_mode)
  28. Connection.send('get_composite_mode')
  29. def on_btn_toggled(self, btn):
  30. if not btn.get_active():
  31. return
  32. btn_name = btn.get_name()
  33. if self.current_composition == btn_name:
  34. self.log.info('composition-mode already active: %s', btn_name)
  35. return
  36. self.log.info('composition-mode activated: %s', btn_name)
  37. Connection.send('set_composite_mode', btn_name)
  38. def on_composite_mode(self, mode):
  39. self.log.info('on_composite_mode callback w/ mode %s', mode)
  40. self.current_composition = mode
  41. self.composite_btns[mode].set_active(True)