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