aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/toolbar/streamblank.py
blob: ab71b17eb414fb86f989c2b8e79d30b082fae34b (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. self.current_status = None
  23. livebtn.connect('toggled', self.on_btn_toggled)
  24. livebtn.set_name('live')
  25. self.livebtn = livebtn
  26. self.blank_btns = {}
  27. for idx, name in enumerate(blank_sources):
  28. if idx == 0:
  29. new_btn = blankbtn
  30. else:
  31. new_icon = Gtk.Image.new_from_pixbuf(blankbtn.get_icon_widget().get_pixbuf())
  32. new_btn = Gtk.RadioToolButton(group=livebtn)
  33. new_btn.set_icon_widget(new_icon)
  34. drawing_area.insert(new_btn, blankbtn_pos+1)
  35. new_btn.set_label("Stream %s" % name)
  36. new_btn.connect('toggled', self.on_btn_toggled)
  37. new_btn.set_name(name)
  38. self.blank_btns[name] = new_btn
  39. # connect event-handler and request initial state
  40. Connection.on('stream_status', self.on_stream_status)
  41. Connection.send('get_stream_status')
  42. def on_btn_toggled(self, btn):
  43. if not btn.get_active():
  44. return
  45. btn_name = btn.get_name()
  46. if btn_name == 'live':
  47. self.warning_overlay.disable()
  48. else:
  49. self.warning_overlay.enable(btn_name)
  50. if self.current_status == btn_name:
  51. self.log.info('stream-status already activate: %s', btn_name)
  52. return
  53. self.log.info('stream-status activated: %s', btn_name)
  54. if btn_name == 'live':
  55. Connection.send('set_stream_live')
  56. else:
  57. Connection.send('set_stream_blank', btn_name)
  58. def on_stream_status(self, status, source = None):
  59. self.log.info('on_stream_status callback w/ status %s and source %s', status, source)
  60. self.current_status = source if source is not None else status
  61. if status == 'live':
  62. self.livebtn.set_active(True)
  63. else:
  64. self.blank_btns[source].set_active(True)