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