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