Reworked tk gui in preparation for migration to qt
This commit is contained in:
parent
e2655a483b
commit
4ce5df4103
1 changed files with 54 additions and 63 deletions
117
syng/gui.py
117
syng/gui.py
|
@ -5,7 +5,6 @@ from datetime import datetime, date, time
|
||||||
import os
|
import os
|
||||||
import builtins
|
import builtins
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from sys import argv, stderr
|
|
||||||
from typing import TYPE_CHECKING, Any, Optional
|
from typing import TYPE_CHECKING, Any, Optional
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
@ -296,6 +295,7 @@ class GeneralConfig(OptionFrame):
|
||||||
)
|
)
|
||||||
self.add_date_time_option("last_song", "Time of last song", config["last_song"])
|
self.add_date_time_option("last_song", "Time of last song", config["last_song"])
|
||||||
self.add_string_option("preview_duration", "Preview Duration", config["preview_duration"])
|
self.add_string_option("preview_duration", "Preview Duration", config["preview_duration"])
|
||||||
|
self.add_string_option("key", "Key for server", config["key"])
|
||||||
|
|
||||||
def get_config(self) -> dict[str, Any]:
|
def get_config(self) -> dict[str, Any]:
|
||||||
config = super().get_config()
|
config = super().get_config()
|
||||||
|
@ -320,6 +320,53 @@ class SyngGui(customtkinter.CTk): # type:ignore
|
||||||
self.withdraw()
|
self.withdraw()
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
|
def add_buttons(self) -> None:
|
||||||
|
button_line = customtkinter.CTkFrame(self)
|
||||||
|
button_line.pack(side="bottom", fill="x")
|
||||||
|
|
||||||
|
self.startsyng_serverbutton = customtkinter.CTkButton(
|
||||||
|
button_line, text="Start Local Server", command=self.start_syng_server
|
||||||
|
)
|
||||||
|
self.startsyng_serverbutton.pack(side="left", expand=True, anchor="w", padx=10, pady=5)
|
||||||
|
|
||||||
|
savebutton = customtkinter.CTkButton(button_line, text="Save", command=self.save_config)
|
||||||
|
savebutton.pack(side="left", padx=10, pady=5)
|
||||||
|
|
||||||
|
self.startbutton = customtkinter.CTkButton(
|
||||||
|
button_line, text="Save and Start", command=self.start_syng_client
|
||||||
|
)
|
||||||
|
self.startbutton.pack(side="left", padx=10, pady=10)
|
||||||
|
|
||||||
|
def init_frame(self):
|
||||||
|
self.frm = customtkinter.CTkFrame(self)
|
||||||
|
self.frm.pack(ipadx=10, padx=10, fill="both", expand=True)
|
||||||
|
|
||||||
|
def init_tabs(self):
|
||||||
|
self.tabview = customtkinter.CTkTabview(self.frm, width=600, height=500)
|
||||||
|
self.tabview.pack(side="right", padx=10, pady=10, fill="both", expand=True)
|
||||||
|
|
||||||
|
self.tabview.add("General")
|
||||||
|
for source in available_sources:
|
||||||
|
self.tabview.add(source)
|
||||||
|
self.tabview.set("General")
|
||||||
|
|
||||||
|
def add_qr(self) -> None:
|
||||||
|
self.qrlabel = customtkinter.CTkLabel(self.frm, text="")
|
||||||
|
self.qrlabel.pack(side="top", anchor="n", padx=10, pady=10)
|
||||||
|
self.linklabel = customtkinter.CTkLabel(self.frm, text="")
|
||||||
|
self.linklabel.bind("<Button-1>", lambda _: self.open_web())
|
||||||
|
self.linklabel.pack()
|
||||||
|
|
||||||
|
def add_general_config(self, config: dict[str, Any]) -> None:
|
||||||
|
self.general_config = GeneralConfig(self.tabview.tab("General"), config, self.update_qr)
|
||||||
|
self.general_config.pack(ipadx=10, fill="both", expand=True)
|
||||||
|
|
||||||
|
def add_source_config(self, source_name: str, source_config: dict[str, Any]) -> None:
|
||||||
|
self.tabs[source_name] = SourceTab(
|
||||||
|
self.tabview.tab(source_name), source_name, source_config
|
||||||
|
)
|
||||||
|
self.tabs[source_name].pack(ipadx=10, expand=True, fill="both")
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(className="Syng")
|
super().__init__(className="Syng")
|
||||||
self.protocol("WM_DELETE_WINDOW", self.on_close)
|
self.protocol("WM_DELETE_WINDOW", self.on_close)
|
||||||
|
@ -347,9 +394,6 @@ class SyngGui(customtkinter.CTk): # type:ignore
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
print("Could not load config")
|
print("Could not load config")
|
||||||
|
|
||||||
# if "config" in loaded_config:
|
|
||||||
# config["config"] |= loaded_config["config"]
|
|
||||||
|
|
||||||
if not config["config"]["secret"]:
|
if not config["config"]["secret"]:
|
||||||
config["config"]["secret"] = "".join(
|
config["config"]["secret"] = "".join(
|
||||||
secrets.choice(string.ascii_letters + string.digits) for _ in range(8)
|
secrets.choice(string.ascii_letters + string.digits) for _ in range(8)
|
||||||
|
@ -357,51 +401,11 @@ class SyngGui(customtkinter.CTk): # type:ignore
|
||||||
|
|
||||||
self.wm_title("Syng")
|
self.wm_title("Syng")
|
||||||
|
|
||||||
# Buttons
|
self.add_buttons()
|
||||||
button_line = customtkinter.CTkFrame(self)
|
self.init_frame()
|
||||||
button_line.pack(side="bottom", fill="x")
|
self.init_tabs()
|
||||||
|
self.add_qr()
|
||||||
self.startsyng_serverbutton = customtkinter.CTkButton(
|
self.add_general_config(config["config"])
|
||||||
button_line, text="Start Local Server", command=self.start_syng_server
|
|
||||||
)
|
|
||||||
self.startsyng_serverbutton.pack(side="left", expand=True, anchor="w", padx=10, pady=5)
|
|
||||||
|
|
||||||
savebutton = customtkinter.CTkButton(button_line, text="Save", command=self.save_config)
|
|
||||||
savebutton.pack(side="left", padx=10, pady=5)
|
|
||||||
|
|
||||||
# open_web_button = customtkinter.CTkButton(
|
|
||||||
# button_line, text="Open Web", command=self.open_web
|
|
||||||
# )
|
|
||||||
# open_web_button.pack(side="left", pady=5)
|
|
||||||
|
|
||||||
self.startbutton = customtkinter.CTkButton(
|
|
||||||
button_line, text="Save and Start", command=self.start_syng_client
|
|
||||||
)
|
|
||||||
self.startbutton.pack(side="left", padx=10, pady=10)
|
|
||||||
|
|
||||||
# Tabs and QR Code
|
|
||||||
frm = customtkinter.CTkFrame(self)
|
|
||||||
frm.pack(ipadx=10, padx=10, fill="both", expand=True)
|
|
||||||
|
|
||||||
tabview = customtkinter.CTkTabview(frm, width=600, height=500)
|
|
||||||
tabview.pack(side="right", padx=10, pady=10, fill="both", expand=True)
|
|
||||||
|
|
||||||
tabview.add("General")
|
|
||||||
for source in available_sources:
|
|
||||||
tabview.add(source)
|
|
||||||
tabview.set("General")
|
|
||||||
|
|
||||||
self.qrlabel = customtkinter.CTkLabel(frm, text="")
|
|
||||||
self.qrlabel.pack(side="top", anchor="n", padx=10, pady=10)
|
|
||||||
self.linklabel = customtkinter.CTkLabel(frm, text="")
|
|
||||||
self.linklabel.bind("<Button-1>", lambda _: self.open_web())
|
|
||||||
self.linklabel.pack()
|
|
||||||
|
|
||||||
self.general_config = GeneralConfig(
|
|
||||||
tabview.tab("General"), config["config"], self.update_qr
|
|
||||||
)
|
|
||||||
self.general_config.pack(ipadx=10, fill="both", expand=True)
|
|
||||||
|
|
||||||
self.tabs = {}
|
self.tabs = {}
|
||||||
|
|
||||||
for source_name in available_sources:
|
for source_name in available_sources:
|
||||||
|
@ -410,8 +414,7 @@ class SyngGui(customtkinter.CTk): # type:ignore
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
source_config = {}
|
source_config = {}
|
||||||
|
|
||||||
self.tabs[source_name] = SourceTab(tabview.tab(source_name), source_name, source_config)
|
self.add_source_config(source_name, source_config)
|
||||||
self.tabs[source_name].pack(ipadx=10, expand=True, fill="both")
|
|
||||||
|
|
||||||
self.update_qr()
|
self.update_qr()
|
||||||
|
|
||||||
|
@ -493,15 +496,3 @@ class SyngGui(customtkinter.CTk): # type:ignore
|
||||||
|
|
||||||
def run_gui() -> None:
|
def run_gui() -> None:
|
||||||
SyngGui().mainloop()
|
SyngGui().mainloop()
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
print(
|
|
||||||
f"Starting the gui with {argv[0]} is deprecated. Please use `syng gui` to start the gui",
|
|
||||||
file=stderr,
|
|
||||||
)
|
|
||||||
run_gui()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue