summaryrefslogtreecommitdiff
path: root/voctogui/lib/toolbar/streamblank.py
blob: e1963c2657c940b5f77560bd035df17c5c26cf7e (plain)
  1. import logging
  2. from gi.repository import Gtk
  3. import lib.connection as Connection
  4. class StreamblankToolbarController(object):
  5. """ Manages Accelerators and Clicks on the Composition Toolbar-Buttons """
  6. def __init__(self, drawing_area, win, uibuilder, warning_overlay):
  7. self.log = logging.getLogger('StreamblankToolbarController')
  8. self.warning_overlay = warning_overlay
  9. blank_sources = ['pause', 'nostream']
  10. self.status_btns = {}
  11. livebtn = uibuilder.find_widget_recursive(drawing_area, 'stream_live')
  12. blankbtn = uibuilder.find_widget_recursive(drawing_area, 'stream_blank')
  13. blankbtn_pos = drawing_area.get_item_index(blankbtn)
  14. livebtn.connect('toggled', self.on_btn_toggled)
  15. livebtn.set_name('live')
  16. self.livebtn = livebtn
  17. self.blank_btns = {}
  18. for idx, name in enumerate(blank_sources):
  19. if idx == 0:
  20. new_btn = blankbtn
  21. else:
  22. new_icon = Gtk.Image.new_from_pixbuf(blankbtn.get_icon_widget().get_pixbuf())
  23. new_btn = Gtk.RadioToolButton(group=livebtn)
  24. new_btn.set_icon_widget(new_icon)
  25. drawing_area.insert(new_btn, blankbtn_pos+1)
  26. new_btn.set_label("Stream %s" % name)
  27. new_btn.connect('toggled', self.on_btn_toggled)
  28. new_btn.set_name(name)
  29. self.blank_btns[name] = new_btn
  30. # connect event-handler and request initial state
  31. Connection.on('stream_status', self.on_stream_status)
  32. Connection.send('get_stream_status')
  33. def on_btn_toggled(self, btn):
  34. if not btn.get_active():
  35. return
  36. btn_name = btn.get_name()
  37. self.log.info('stream-status activated: %s', btn_name)
  38. if btn_name == 'live':
  39. self.warning_overlay.disable()
  40. else:
  41. self.warning_overlay.enable(btn_name)
  42. if btn_name == 'live':
  43. Connection.send('set_stream_live')
  44. else:
  45. Connection.send('set_stream_blank', btn_name)
  46. def on_stream_status(self, status, source = None):
  47. self.log.info('on_stream_status callback w/ status %s and source %s', status, source)
  48. if status == 'live':
  49. self.livebtn.set_active(True)
  50. else:
  51. self.blank_btns[source].set_active(True)