From cee18857433a3d5cc1d5b57a97872bbd7b6cf021 Mon Sep 17 00:00:00 2001 From: sbahling Date: Mon, 22 Oct 2018 18:49:07 +0200 Subject: Access console button state from another button Create lookup table of console buttons by button name, --- buttons.py | 8 ++++++-- console.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/buttons.py b/buttons.py index f80afc1..b654b38 100644 --- a/buttons.py +++ b/buttons.py @@ -96,8 +96,9 @@ class StripSelButton(Button): strip = self.strip print('handle_strip_sel', strip) - if self.get('REC ENABLE', 0): - if strip.recenable: + recenable = self.console.buttons.get('REC ENABLE', None) + if recenable.pressed: + if strip.rec: osc.client.send_message('/strip/recenable', (strip.num, 0)) else: osc.client.send_message('/strip/recenable', (strip.num, 1)) @@ -246,3 +247,6 @@ class NudgeButton(Button): osc.client.send_message('/access_action', 'Common/nudge-next-backward') super().press() + + +NULLBUTTON = Button(None, None) diff --git a/console.py b/console.py index 7662e2f..6ad67a8 100644 --- a/console.py +++ b/console.py @@ -99,12 +99,21 @@ class Console(): self.more_banks_up = False self.more_banks_down = False self.strips = strips.init_strips(self) - self.buttons = fw_1884_buttons.init_buttons(self) + self.buttons = {} + self.init_buttons() self.unit.connect('control', self.handle_control) self.status_thread = RunningStatusThread(self) # noqa F841 + def init_buttons(self): + self.button_map = fw_1884_buttons.init_buttons(self) + for index, items in self.button_map.items(): + for item in items: + if item is None: + continue + self.buttons[item.name] = item + @property def status(self): try: @@ -119,7 +128,7 @@ class Console(): bits = reversed(bits32(changed)) for bit in [i for i, b in enumerate(bits) if int(b)]: high = bool(after & (0b1 << bit)) - button = self.buttons[index][int(bit)] + button = self.button_map[index][int(bit)] if button is None: print('unhandled control bit {}:{}'.format(index, bit)) continue -- cgit v1.2.3