From 80340ac2193bcc28d34bcf8a784db13887f83da7 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 26 Apr 2022 20:59:00 +0100 Subject: [PATCH] updates to bus mode cache add a separate bus mode cache for each interface. add property objects to config frame for setting/getting from bus mode cache. update function update_bus_modes to fit changes to bus mode cache --- vmcompact/app.py | 5 ++++- vmcompact/channels.py | 6 +++--- vmcompact/config.py | 39 ++++++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/vmcompact/app.py b/vmcompact/app.py index 1795155..de6b937 100644 --- a/vmcompact/app.py +++ b/vmcompact/app.py @@ -64,7 +64,10 @@ class App(tk.Tk): ] _base_vals.submixes = self.configuration["submixes"]["default"] _base_vals.mwscroll_step = self.configuration["mwscroll_step"]["size"] - self.bus_modes = [tk.StringVar(value="normal") for _ in range(12)] + self.bus_modes_cache = { + "vmr": list(tk.StringVar(value="normal") for _ in range(12)), + "vban": list(tk.StringVar(value="normal") for _ in range(12)), + } # create menus self.menus = Menus(self, vmr) diff --git a/vmcompact/channels.py b/vmcompact/channels.py index b47c263..6dfd14d 100644 --- a/vmcompact/channels.py +++ b/vmcompact/channels.py @@ -394,9 +394,9 @@ class ChannelFrame(ttk.Frame): def update_bus_modes(self): [ - self._parent.bus_modes[i].set( - labelframe.config_frame.bus_mode_current.get() - ) + self._parent.bus_modes_cache[ + "vban" if _base_vals.vban_connected else "vmr" + ][i].set(labelframe.config_frame.bus_mode) for i, labelframe in enumerate(self.labelframes) if labelframe is not None and labelframe.config_frame ] diff --git a/vmcompact/config.py b/vmcompact/config.py index 0dc3be5..bab010a 100644 --- a/vmcompact/config.py +++ b/vmcompact/config.py @@ -378,35 +378,44 @@ class BusConfig(Config): _target = super(BusConfig, self).target return getattr(_target, self.identifier)[self.index] + @property + def bus_mode(self): + return self._parent.bus_modes_cache[ + "vban" if _base_vals.vban_connected else "vmr" + ][self.index].get() + + @bus_mode.setter + def bus_mode(self, val): + self._parent.bus_modes_cache["vban" if _base_vals.vban_connected else "vmr"][ + self.index + ].set(val) + def make_row0(self): self.bus_mode_label_text = tk.StringVar() - self.bus_mode_current = tk.StringVar( - value=self._parent.bus_modes[self.index].get() - ) - self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode_current.get()}") - setattr(self.target.mode, self.bus_mode_current.get(), True) + self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode}") + setattr(self.target.mode, self.bus_mode.lower(), True) self.busmode_button = ttk.Button(self, textvariable=self.bus_mode_label_text) self.busmode_button.grid(column=0, row=0, columnspan=2, sticky=(tk.W)) self.busmode_button.bind("", self.rotate_bus_modes_right) self.busmode_button.bind("", self.rotate_bus_modes_left) def rotate_bus_modes_right(self, *args): - current_index = self.bus_modes.index(self.bus_mode_current.get()) + current_index = self.bus_modes.index(self.bus_mode) if current_index + 1 < len(self.bus_modes): - self.bus_mode_current.set(self.bus_modes[current_index + 1]) + self.bus_mode = self.bus_modes[current_index + 1] else: - self.bus_mode_current.set(self.bus_modes[0]) - setattr(self.target.mode, self.bus_mode_current.get().lower(), True) - self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode_current.get()}") + self.bus_mode = self.bus_modes[0] + setattr(self.target.mode, self.bus_mode.lower(), True) + self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode}") def rotate_bus_modes_left(self, *args): - current_index = self.bus_modes.index(self.bus_mode_current.get()) + current_index = self.bus_modes.index(self.bus_mode) if current_index == 0: - self.bus_mode_current.set(self.bus_modes[-1]) + self.bus_mode = self.bus_modes[-1] else: - self.bus_mode_current.set(self.bus_modes[current_index - 1]) - setattr(self.target.mode, self.bus_mode_current.get().lower(), True) - self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode_current.get()}") + self.bus_mode = self.bus_modes[current_index - 1] + setattr(self.target.mode, self.bus_mode.lower(), True) + self.bus_mode_label_text.set(f"Bus Mode: {self.bus_mode}") def make_row1(self): param_buttons = [