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