aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/audioselector.py
blob: 4f8f9ecccaeca8fb37fb00e99754223b5ec0c414 (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, self.timer_iteration)
  35. def on_disabled_timer(self, timer_iteration):
  36. if timer_iteration != self.timer_iteration:
  37. self.log.debug('lock-timer fired late, ignoring')
  38. return
  39. self.log.debug('lock-timer fired, locking')
  40. self.set_enabled(False)
  41. return False
  42. def set_enabled(self, enable):
  43. self.combo.set_sensitive(enable)
  44. self.eventbox.set_property('above_child', not enable)
  45. def is_enabled(self):
  46. return self.combo.get_sensitive()
  47. def on_changed(self, combo):
  48. if not self.is_enabled():
  49. return
  50. self.timer_iteration += 1
  51. value = combo.get_active_text()
  52. self.log.info('changed to %s', value)
  53. self.set_enabled(False)
  54. Connection.send('set_audio', value)