aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/audioselector.py
blob: c4be4d3edef415a9175a114e530e0b3e53186508 (plain)
  1. import logging
  2. from gi.repository import Gst, Gdk, GLib
  3. from lib.config import Config
  4. import lib.connection as Connection
  5. class AudioSelectorController(object):
  6. """Displays a Level-Meter of another VideoDisplay into a GtkWidget"""
  7. def __init__(self, drawing_area, win, uibuilder):
  8. self.log = logging.getLogger('AudioSelectorController')
  9. self.drawing_area = drawing_area
  10. self.win = win
  11. combo = uibuilder.find_widget_recursive(win, 'combo_audio')
  12. combo.connect('changed', self.on_changed)
  13. # combo.set_sensitive(True)
  14. self.combo = combo
  15. eventbox = uibuilder.find_widget_recursive(win, 'combo_audio_events')
  16. eventbox.connect('button_press_event', self.on_button_press_event)
  17. eventbox.set_property('above_child', True)
  18. self.eventbox = eventbox
  19. combo.remove_all()
  20. for name in Config.getlist('mix', 'sources'):
  21. combo.append(name, name)
  22. # connect event-handler and request initial state
  23. Connection.on('audio_status', self.on_audio_status)
  24. Connection.send('get_audio')
  25. self.timer_iteration = 0
  26. def on_audio_status(self, source):
  27. self.log.info('on_audio_status callback w/ source: %s', source)
  28. self.combo.set_active_id(source)
  29. def on_button_press_event(self, combo, event):
  30. if event.type != Gdk.EventType.DOUBLE_BUTTON_PRESS:
  31. return
  32. self.log.debug('double-clicked, unlocking')
  33. self.set_enabled(True)
  34. GLib.timeout_add_seconds(5, self.on_disabled_timer,
  35. self.timer_iteration)
  36. def on_disabled_timer(self, timer_iteration):
  37. if timer_iteration != self.timer_iteration:
  38. self.log.debug('lock-timer fired late, ignoring')
  39. return
  40. self.log.debug('lock-timer fired, locking')
  41. self.set_enabled(False)
  42. return False
  43. def set_enabled(self, enable):
  44. self.combo.set_sensitive(enable)
  45. self.eventbox.set_property('above_child', not enable)
  46. def is_enabled(self):
  47. return self.combo.get_sensitive()
  48. def on_changed(self, combo):
  49. if not self.is_enabled():
  50. return
  51. self.timer_iteration += 1
  52. value = combo.get_active_text()
  53. self.log.info('changed to %s', value)
  54. self.set_enabled(False)
  55. Connection.send('set_audio', value)