Compare commits
2 commits
266d98f12e
...
193e3770ff
Author | SHA1 | Date | |
---|---|---|---|
193e3770ff | |||
fe6539de35 |
3 changed files with 46 additions and 7 deletions
|
@ -152,6 +152,7 @@ class State:
|
||||||
waiting_room: list[Entry] = field(default_factory=list)
|
waiting_room: list[Entry] = field(default_factory=list)
|
||||||
recent: list[Entry] = field(default_factory=list)
|
recent: list[Entry] = field(default_factory=list)
|
||||||
config: dict[str, Any] = field(default_factory=default_config)
|
config: dict[str, Any] = field(default_factory=default_config)
|
||||||
|
old_config: dict[str, Any] = field(default_factory=default_config)
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
@ -257,6 +258,23 @@ class Client:
|
||||||
"""
|
"""
|
||||||
self.state.config = default_config() | data
|
self.state.config = default_config() | data
|
||||||
|
|
||||||
|
async def send_update_config(self) -> None:
|
||||||
|
"""
|
||||||
|
Send the current configuration to the server.
|
||||||
|
|
||||||
|
This is used to update the server with the current configuration of the
|
||||||
|
client. This is done by sending a "update_config" message to the server.
|
||||||
|
|
||||||
|
:rtype: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
changes = dict()
|
||||||
|
for key, value in self.state.config.items():
|
||||||
|
if key in default_config() and default_config()[key] != value:
|
||||||
|
changes[key] = value
|
||||||
|
|
||||||
|
await self.sio.emit("update_config", self.state.config)
|
||||||
|
|
||||||
async def handle_skip_current(self, data: dict[str, Any]) -> None:
|
async def handle_skip_current(self, data: dict[str, Any]) -> None:
|
||||||
"""
|
"""
|
||||||
Handle the "skip-current" message.
|
Handle the "skip-current" message.
|
||||||
|
@ -337,6 +355,10 @@ class Client:
|
||||||
|
|
||||||
:rtype: None
|
:rtype: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# stop running mpv instances
|
||||||
|
await self.kill_mpv()
|
||||||
|
|
||||||
logger.info("Connected to server")
|
logger.info("Connected to server")
|
||||||
data = {
|
data = {
|
||||||
"queue": self.state.queue,
|
"queue": self.state.queue,
|
||||||
|
@ -583,7 +605,7 @@ class Client:
|
||||||
|
|
||||||
async def kill_mpv(self) -> None:
|
async def kill_mpv(self) -> None:
|
||||||
"""
|
"""
|
||||||
Kill the mpv process. Needs to be called in a thread, because of mpv...
|
Kill the mpv process. Needs to be called in a seperate thread, because of mpv...
|
||||||
See https://github.com/jaseg/python-mpv/issues/114#issuecomment-1214305952
|
See https://github.com/jaseg/python-mpv/issues/114#issuecomment-1214305952
|
||||||
|
|
||||||
:rtype: None
|
:rtype: None
|
||||||
|
|
27
syng/gui.py
27
syng/gui.py
|
@ -504,7 +504,6 @@ class GeneralConfig(OptionFrame):
|
||||||
["debug", "info", "warning", "error", "critical"],
|
["debug", "info", "warning", "error", "critical"],
|
||||||
config["log_level"],
|
config["log_level"],
|
||||||
)
|
)
|
||||||
# self.add_bool_option("show_advanced", "Show Advanced Options", config["show_advanced"])
|
|
||||||
|
|
||||||
self.simple_options = ["server", "room", "secret"]
|
self.simple_options = ["server", "room", "secret"]
|
||||||
|
|
||||||
|
@ -568,6 +567,10 @@ class SyngGui(QMainWindow):
|
||||||
self.print_queue_button.clicked.connect(self.debug_print_queue)
|
self.print_queue_button.clicked.connect(self.debug_print_queue)
|
||||||
self.buttons_layout.addWidget(self.print_queue_button)
|
self.buttons_layout.addWidget(self.print_queue_button)
|
||||||
|
|
||||||
|
self.update_config_button = QPushButton("Update Config")
|
||||||
|
self.update_config_button.clicked.connect(self.update_config)
|
||||||
|
self.update_config_button.setVisible(False)
|
||||||
|
self.buttons_layout.addWidget(self.update_config_button)
|
||||||
self.startbutton = QPushButton("Connect")
|
self.startbutton = QPushButton("Connect")
|
||||||
|
|
||||||
self.startbutton.clicked.connect(self.start_syng_client)
|
self.startbutton.clicked.connect(self.start_syng_client)
|
||||||
|
@ -768,7 +771,7 @@ class SyngGui(QMainWindow):
|
||||||
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||||
)
|
)
|
||||||
if answer == QMessageBox.StandardButton.Yes:
|
if answer == QMessageBox.StandardButton.Yes:
|
||||||
self.update_config(self.complete_config({"config": {}, "sources": {}}))
|
self.set_config(self.complete_config({"config": {}, "sources": {}}))
|
||||||
|
|
||||||
def load_config(self, filename: str) -> dict[str, Any]:
|
def load_config(self, filename: str) -> dict[str, Any]:
|
||||||
try:
|
try:
|
||||||
|
@ -780,7 +783,14 @@ class SyngGui(QMainWindow):
|
||||||
|
|
||||||
return self.complete_config(loaded_config)
|
return self.complete_config(loaded_config)
|
||||||
|
|
||||||
def update_config(self, config: dict[str, Any]) -> None:
|
def update_config(self) -> None:
|
||||||
|
if self.client is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
new_config = self.gather_config()
|
||||||
|
old_config = self.client.config
|
||||||
|
|
||||||
|
def set_config(self, config: dict[str, Any]) -> None:
|
||||||
self.general_config.load_config(config["config"])
|
self.general_config.load_config(config["config"])
|
||||||
for source_name, source_config in config["sources"].items():
|
for source_name, source_config in config["sources"].items():
|
||||||
self.tabs[source_name].load_config(source_config)
|
self.tabs[source_name].load_config(source_config)
|
||||||
|
@ -809,7 +819,7 @@ class SyngGui(QMainWindow):
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
config = self.load_config(filename)
|
config = self.load_config(filename)
|
||||||
self.update_config(config)
|
self.set_config(config)
|
||||||
|
|
||||||
def export_config(self) -> None:
|
def export_config(self) -> None:
|
||||||
filename = QFileDialog.getSaveFileName(self, "Save File", "", "YAML Files (*.yaml)")[0]
|
filename = QFileDialog.getSaveFileName(self, "Save File", "", "YAML Files (*.yaml)")[0]
|
||||||
|
@ -831,9 +841,16 @@ class SyngGui(QMainWindow):
|
||||||
self.set_client_button_stop()
|
self.set_client_button_stop()
|
||||||
|
|
||||||
def set_client_button_stop(self) -> None:
|
def set_client_button_stop(self) -> None:
|
||||||
|
self.update_config_button.setVisible(True)
|
||||||
|
self.general_config.string_options["server"].setEnabled(False)
|
||||||
|
self.general_config.string_options["room"].setEnabled(False)
|
||||||
|
|
||||||
self.startbutton.setText("Disconnect")
|
self.startbutton.setText("Disconnect")
|
||||||
|
|
||||||
def set_client_button_start(self) -> None:
|
def set_client_button_start(self) -> None:
|
||||||
|
self.general_config.string_options["server"].setEnabled(True)
|
||||||
|
self.general_config.string_options["room"].setEnabled(True)
|
||||||
|
self.update_config_button.setVisible(False)
|
||||||
self.startbutton.setText("Connect")
|
self.startbutton.setText("Connect")
|
||||||
|
|
||||||
def start_syng_client(self) -> None:
|
def start_syng_client(self) -> None:
|
||||||
|
@ -924,7 +941,7 @@ def run_gui() -> None:
|
||||||
app.setWindowIcon(QIcon(os.path.join(base_dir, "syng.ico")))
|
app.setWindowIcon(QIcon(os.path.join(base_dir, "syng.ico")))
|
||||||
else:
|
else:
|
||||||
app.setWindowIcon(QIcon(":/icons/syng.ico"))
|
app.setWindowIcon(QIcon(":/icons/syng.ico"))
|
||||||
app.setApplicationName("Syng")
|
app.setApplicationName("Syng.Rocks!")
|
||||||
app.setDesktopFileName("rocks.syng.Syng")
|
app.setDesktopFileName("rocks.syng.Syng")
|
||||||
window = SyngGui()
|
window = SyngGui()
|
||||||
window.show()
|
window.show()
|
||||||
|
|
|
@ -108,7 +108,7 @@ class Queue:
|
||||||
|
|
||||||
def find_by_name(self, name: str) -> Optional[Entry]:
|
def find_by_name(self, name: str) -> Optional[Entry]:
|
||||||
"""
|
"""
|
||||||
Find an entry by its performer and return it.
|
Find the first entry by its performer and return it.
|
||||||
|
|
||||||
:param name: The name of the performer to search for.
|
:param name: The name of the performer to search for.
|
||||||
:type name: str
|
:type name: str
|
||||||
|
|
Loading…
Add table
Reference in a new issue