diff options
-rw-r--r-- | voctogui/lib/audioselector.py | 6 | ||||
-rw-r--r-- | voctogui/lib/connection.py | 34 |
2 files changed, 32 insertions, 8 deletions
diff --git a/voctogui/lib/audioselector.py b/voctogui/lib/audioselector.py index ab8f31e..4f8f9ec 100644 --- a/voctogui/lib/audioselector.py +++ b/voctogui/lib/audioselector.py @@ -34,7 +34,8 @@ class AudioSelectorController(object): self.timer_iteration = 0 def on_audio_status(self, source): - self.combo.set_active_id(name) + self.log.info('on_audio_status callback w/ source: %s', source) + self.combo.set_active_id(source) def on_button_press_event(self, combo, event): if event.type != Gdk.EventType.DOUBLE_BUTTON_PRESS: @@ -67,5 +68,6 @@ class AudioSelectorController(object): self.timer_iteration += 1 value = combo.get_active_text() - self.log.debug('changed to %s', value) + self.log.info('changed to %s', value) self.set_enabled(False) + Connection.send('set_audio', value) diff --git a/voctogui/lib/connection.py b/voctogui/lib/connection.py index b56a490..42a403e 100644 --- a/voctogui/lib/connection.py +++ b/voctogui/lib/connection.py @@ -10,6 +10,7 @@ log = logging.getLogger('Connection') conn = None port = 9999 command_queue = Queue() +signal_handlers = {} def establish(host): global conn, port, log @@ -101,15 +102,36 @@ def on_loop(): args = words[1:] log.info('received signal %s, dispatching', signal) + if signal not in signal_handlers: + return True + + for handler in signal_handlers[signal]: + cb = handler['cb'] + if 'one' in handler and handler['one']: + log.debug('removing one-time handler') + del signal_handlers[signal] + + cb(*args) + + return True -def send(command): +def send(command, *args): global conn, log - if isinstance(command, str): - command = command.encode('ascii') - conn.send(command) + if len(args) > 0: + command += ' '+(' '.join(args)) + + command += '\n' + + conn.send(command.encode('ascii')) def on(signal, cb): - pass + if signal not in signal_handlers: + signal_handlers[signal] = [] + + signal_handlers[signal].append({'cb': cb}) def one(signal, cb): - pass + if signal not in signal_handlers: + signal_handlers[signal] = [] + + signal_handlers[signal].append({'cb': cb, 'one': True}) |