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