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