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