use subject class to notify of busmix update

update messageboxes
This commit is contained in:
onyx-and-iris 2023-06-26 13:57:08 +01:00
parent 0f734e87b7
commit 194b95d67b
2 changed files with 32 additions and 22 deletions

View File

@ -1,15 +1,19 @@
import logging
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from .data import _base_values, _configuration from .data import _base_values, _configuration
logger = logging.getLogger(__name__)
class Banner(ttk.Frame): class Banner(ttk.Frame):
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
self.parent = parent self.parent = parent
self.submix = tk.StringVar() self.parent.subject.add(self)
self.submix.set(self.target.bus[_configuration.submixes].label) self.logger = logger.getChild(self.__class__.__name__)
self.submix = tk.StringVar(value=self.target.bus[_configuration.submixes].label)
self.label = ttk.Label( self.label = ttk.Label(
self, self,
@ -17,19 +21,15 @@ class Banner(ttk.Frame):
) )
self.label.grid(column=0, row=0, sticky=(tk.N, tk.S, tk.W, tk.E)) self.label.grid(column=0, row=0, sticky=(tk.N, tk.S, tk.W, tk.E))
self.upd_submix()
@property @property
def target(self): def target(self):
"""returns the current interface""" """returns the current interface"""
return self.parent.target return self.parent.target
def upd_submix(self): def on_update(self, subject):
self.after(1, self.upd_submix_step) if subject == "submix":
if not _base_values.dragging:
def upd_submix_step(self): self.logger.debug("checking submix for banner")
if not _base_values.dragging: self.submix.set(self.target.bus[_configuration.submixes].label)
self.submix.set(self.target.bus[_configuration.submixes].label) self.label["text"] = f"SUBMIX: {self.submix.get().upper()}"
self.label["text"] = f"SUBMIX: {self.submix.get().upper()}"
self.after(100, self.upd_submix_step)

View File

@ -2,22 +2,23 @@ import logging
import tkinter as tk import tkinter as tk
import webbrowser import webbrowser
from functools import partial from functools import partial
from tkinter import messagebox, ttk from tkinter import messagebox
import sv_ttk import sv_ttk
import vban_cmd import vban_cmd
from vban_cmd.error import VBANCMDError from vban_cmd.error import VBANCMDConnectionError
from .data import _base_values, _configuration, get_configuration, kind_get from .data import _base_values, _configuration, get_configuration, kind_get
logger = logging.getLogger(__name__)
class Menus(tk.Menu): class Menus(tk.Menu):
logger = logging.getLogger("menu.menus")
def __init__(self, parent, vmr): def __init__(self, parent, vmr):
super().__init__() super().__init__()
self.parent = parent self.parent = parent
self.vmr = vmr self.vmr = vmr
self.logger = logger.getChild(self.__class__.__name__)
self.vban_config = get_configuration("vban") self.vban_config = get_configuration("vban")
self.app_config = get_configuration("app") self.app_config = get_configuration("app")
self._is_topmost = tk.BooleanVar() self._is_topmost = tk.BooleanVar()
@ -213,14 +214,19 @@ class Menus(tk.Menu):
setattr(self.target.command, cmd, val) setattr(self.target.command, cmd, val)
def load_profile(self, profile): def load_profile(self, profile):
self.logger.info(f"loading user profile {profile}")
self.target.apply_config(profile) self.target.apply_config(profile)
def load_defaults(self): def load_defaults(self):
resp = messagebox.askyesno( msg = (
message="Are you sure you want to Reset values to defaults?\nPhysical strips B1, Virtual strips A1\nMono, Solo, Mute, EQ all OFF" "Are you sure you want to Reset values to defaults?",
"Physical strips B1, Virtual strips A1",
"Mono, Solo, Mute, EQ all OFF",
"Gain sliders for Strip/Bus at 0.0",
) )
resp = messagebox.askyesno(message="\n".join(msg))
if resp: if resp:
self.target.apply_config("reset") self.load_profile("reset")
def always_on_top(self): def always_on_top(self):
self.parent.attributes("-topmost", self._is_topmost.get()) self.parent.attributes("-topmost", self._is_topmost.get())
@ -242,6 +248,7 @@ class Menus(tk.Menu):
self.parent.nav_frame.show_submix() self.parent.nav_frame.show_submix()
for j, var in enumerate(self._selected_bus): for j, var in enumerate(self._selected_bus):
var.set(i == j) var.set(i == j)
self.parent.subject.notify("submix")
def load_theme(self, theme): def load_theme(self, theme):
sv_ttk.set_theme(theme) sv_ttk.set_theme(theme)
@ -312,16 +319,19 @@ class Menus(tk.Menu):
try: try:
self.logger.info(f"Attempting vban connection to {opts.get('ip')}") self.logger.info(f"Attempting vban connection to {opts.get('ip')}")
self.vban.login() self.vban.login()
except VBANCMDError as e: except VBANCMDConnectionError as e:
self.vban.logout() self.vban.logout()
msg = (str(e), f"Please check your connection settings") msg = (
f"Timeout attempting to establish connection to {opts.get('ip')}",
f"Please check your connection settings",
)
messagebox.showerror("Connection Error", "\n".join(msg)) messagebox.showerror("Connection Error", "\n".join(msg))
msg = (str(e), f"resuming local connection") msg = (str(e), f"resuming local connection")
self.logger.error(", ".join(msg)) self.logger.error(", ".join(msg))
self.after(1, self.enable_vban_menus) self.after(1, self.enable_vban_menus)
return return
self.menu_teardown(i) self.menu_teardown(i)
self.vban.event.ldirty = True self.vban.event.add(["pdirty", "ldirty"])
# destroy the current App frames # destroy the current App frames
self.parent._destroy_top_level_frames() self.parent._destroy_top_level_frames()
_base_values.vban_connected = True _base_values.vban_connected = True