summaryrefslogtreecommitdiff
path: root/voctogui/lib/audioselector.py
blob: 141ecc4ff8ae8aafee03fed30a2595c81a82c800 (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. #combo.set_active_id(name)
  22. self.timer_iteration = 0
  23. def on_button_press_event(self, combo, event):
  24. if event.type != Gdk.EventType.DOUBLE_BUTTON_PRESS:
  25. return
  26. self.log.debug('double-clicked, unlocking')
  27. self.set_enabled(True)
  28. GLib.timeout_add_seconds(5, self.on_disabled_timer, self.timer_iteration)
  29. def on_disabled_timer(self, timer_iteration):
  30. if timer_iteration != self.timer_iteration:
  31. self.log.debug('lock-timer fired late, ignoring')
  32. return
  33. self.log.debug('lock-timer fired, locking')
  34. self.set_enabled(False)
  35. return False
  36. def set_enabled(self, enable):
  37. self.combo.set_sensitive(enable)
  38. self.eventbox.set_property('above_child', not enable)
  39. def is_enabled(self):
  40. return self.combo.get_sensitive()
  41. def on_changed(self, combo):
  42. if not self.is_enabled():
  43. return
  44. self.timer_iteration += 1
  45. value = combo.get_active_text()
  46. self.log.debug('changed to %s', value)
  47. self.set_enabled(False)