Update menu.py

check for vban config, if none disable menu
This commit is contained in:
onyx-and-iris 2022-04-12 01:25:46 +01:00
parent 25d7ac1832
commit 335bb2b1db

View File

@ -15,7 +15,8 @@ class Menus(tk.Menu):
super().__init__() super().__init__()
self._parent = parent self._parent = parent
self._vmr = vmr self._vmr = vmr
self.vban_conns = [None for i, _ in enumerate(self.configuration_vban)] if self.configuration_vban is not None:
self.vban_conns = [None for i, _ in enumerate(self.configuration_vban)]
self.menubar = tk.Menu(self, tearoff=0) self.menubar = tk.Menu(self, tearoff=0)
parent["menu"] = self.menubar parent["menu"] = self.menubar
self._is_topmost = tk.BooleanVar() self._is_topmost = tk.BooleanVar()
@ -88,19 +89,22 @@ class Menus(tk.Menu):
# vban connect menu # vban connect menu
self.menu_vban = tk.Menu(self.menubar, tearoff=0) self.menu_vban = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(menu=self.menu_vban, label="VBAN Connect") self.menubar.add_cascade(menu=self.menu_vban, label="VBAN Connect")
for i, _ in enumerate(self.configuration_vban): if self.configuration_vban is not None:
setattr(self, f"menu_vban_{i+1}", tk.Menu(self.menu_vban, tearoff=0)) for i, _ in enumerate(self.configuration_vban):
target_menu = getattr(self, f"menu_vban_{i+1}") setattr(self, f"menu_vban_{i+1}", tk.Menu(self.menu_vban, tearoff=0))
self.menu_vban.add_cascade( target_menu = getattr(self, f"menu_vban_{i+1}")
menu=target_menu, label=f"VBAN Connect #{i+1}", underline=0 self.menu_vban.add_cascade(
) menu=target_menu, label=f"VBAN Connect #{i+1}", underline=0
target_menu.add_command( )
label="Connect", command=partial(self.vban_connect, i) target_menu.add_command(
) label="Connect", command=partial(self.vban_connect, i)
target_menu.add_command( )
label="Disconnect", command=partial(self.vban_disconnect, i) target_menu.add_command(
) label="Disconnect", command=partial(self.vban_disconnect, i)
target_menu.entryconfig(1, state="disabled") )
target_menu.entryconfig(1, state="disabled")
else:
self.menubar.entryconfig(2, state="disabled")
# extends menu # extends menu
self.menu_extends = tk.Menu(self.menubar, tearoff=0) self.menu_extends = tk.Menu(self.menubar, tearoff=0)
@ -191,7 +195,8 @@ class Menus(tk.Menu):
@property @property
def configuration_vban(self): def configuration_vban(self):
return configuration["vban"] if "vban" in configuration:
return configuration["vban"]
def action_invoke_voicemeeter(self, cmd): def action_invoke_voicemeeter(self, cmd):
getattr(self.target.command, cmd)() getattr(self.target.command, cmd)()