diff --git a/src/ui/settings_window.py b/src/ui/settings_window.py index ed4102e..68fa9b3 100644 --- a/src/ui/settings_window.py +++ b/src/ui/settings_window.py @@ -6,7 +6,7 @@ import socket from datetime import datetime from PyQt6 import QtCore -from PyQt6.QtCore import Qt, QSettings, pyqtSignal as Signal +from PyQt6.QtCore import Qt, QSettings, pyqtSignal as Signal, QThread, pyqtSignal from PyQt6.QtGui import QIcon from PyQt6.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QStackedWidget, QVBoxLayout, \ QWidget, QLabel, QCheckBox, QLineEdit, \ @@ -21,6 +21,16 @@ from src.version import APP_AUTHOR, APP_NAME settings = QSettings(APP_AUTHOR, APP_NAME) +class GetEngineInfoWorker(QThread): + done = pyqtSignal(object) # emits the result when finished + + def __init__(self, parent=None): + super().__init__(parent) + self.parent = parent + + def run(self): + data = RenderServerProxy(socket.gethostname()).get_engine_info() + self.done.emit(data) class SettingsWindow(QMainWindow): def __init__(self): @@ -110,7 +120,7 @@ class SettingsWindow(QMainWindow): startup_layout = QVBoxLayout() # startup_layout.addWidget(QCheckBox("Start application on system startup")) check_for_updates_checkbox = QCheckBox("Check for updates automatically") - check_for_updates_checkbox.setChecked(settings.value("auto_check_for_updates", True)) + check_for_updates_checkbox.setChecked(settings.value("auto_check_for_updates", True, type=bool)) check_for_updates_checkbox.stateChanged.connect(lambda state: settings.setValue("auto_check_for_updates", bool(state))) startup_layout.addWidget(check_for_updates_checkbox) startup_group.setLayout(startup_layout) @@ -169,19 +179,23 @@ class SettingsWindow(QMainWindow): enable_sharing_checkbox.stateChanged.connect(self.toggle_render_sharing) sharing_layout.addWidget(enable_sharing_checkbox) + password_enabled = (settings.value("enable_network_sharing", False, type=bool) and + settings.value("enable_network_password", False, type=bool)) + password_layout = QHBoxLayout() password_layout.setContentsMargins(0, 0, 0, 0) self.enable_network_password_checkbox = QCheckBox("Enable network password:") self.enable_network_password_checkbox.setChecked(settings.value("enable_network_password", False, type=bool)) self.enable_network_password_checkbox.stateChanged.connect(self.enable_network_password_changed) + self.enable_network_password_checkbox.setEnabled(settings.value("enable_network_sharing", False, type=bool)) sharing_layout.addWidget(self.enable_network_password_checkbox) self.network_password_line = QLineEdit() self.network_password_line.setPlaceholderText("Enter a password") self.network_password_line.setEchoMode(QLineEdit.EchoMode.Password) - self.network_password_line.setEnabled(settings.value("enable_network_password", False, type=bool)) + self.network_password_line.setEnabled(password_enabled) password_layout.addWidget(self.network_password_line) self.show_password_button = QPushButton("Show") - self.show_password_button.setEnabled(settings.value("enable_network_password", False, type=bool)) + self.show_password_button.setEnabled(password_enabled) self.show_password_button.clicked.connect(self.show_password_button_pressed) password_layout.addWidget(self.show_password_button) sharing_layout.addLayout(password_layout) @@ -210,7 +224,7 @@ class SettingsWindow(QMainWindow): # toggle showing / hiding the password show_pass = self.show_password_button.text() == "Show" self.show_password_button.setText("Hide" if show_pass else "Show") - self.network_password_line.setEchoMode(QLineEdit.EchoMode.Normal if show_pass else QLineEdit.EchoMode.Normal) + self.network_password_line.setEchoMode(QLineEdit.EchoMode.Normal if show_pass else QLineEdit.EchoMode.Password) def create_engines_page(self): """Create the Engines settings page.""" @@ -267,12 +281,12 @@ class SettingsWindow(QMainWindow): engine_updates_layout.addLayout(engine_download_layout) - check_for_engine_updates_checkbox = QCheckBox("Check for new versions on launch") - check_for_engine_updates_checkbox.setChecked(settings.value('check_for_engine_updates_on_launch', True, type=bool)) - check_for_engine_updates_checkbox.setEnabled(at_least_one_downloadable) - check_for_engine_updates_checkbox.stateChanged.connect( + self.check_for_engine_updates_checkbox = QCheckBox("Check for new versions on launch") + self.check_for_engine_updates_checkbox.setChecked(settings.value('check_for_engine_updates_on_launch', True, type=bool)) + self.check_for_engine_updates_checkbox.setEnabled(at_least_one_downloadable) + self.check_for_engine_updates_checkbox.stateChanged.connect( lambda state: settings.setValue("check_for_engine_updates_on_launch", bool(state))) - engine_updates_layout.addWidget(check_for_engine_updates_checkbox) + engine_updates_layout.addWidget(self.check_for_engine_updates_checkbox) self.engines_last_update_label = QLabel() self.update_last_checked_label() self.engines_last_update_label.setEnabled(at_least_one_downloadable) @@ -292,7 +306,7 @@ class SettingsWindow(QMainWindow): def change_ignore_system_installs(self, value): settings.setValue("engines_ignore_system_installs", bool(value)) - self.installed_engines_table.update_table() + self.installed_engines_table.update_engines_table() def update_last_checked_label(self): """Retrieve the last check timestamp and return a human-friendly string.""" @@ -338,7 +352,7 @@ class SettingsWindow(QMainWindow): f"Unknown error while deleting {engine_info['engine']} {engine_info['version']}.", QMessageBox.StandardButton.Ok) - self.installed_engines_table.update_table(use_cached=False) + self.installed_engines_table.update_engines_table(use_cached=False) def launch_selected_engine(self): engine_info = self.installed_engines_table.selected_engine_data() @@ -419,12 +433,19 @@ class EngineTableWidget(QWidget): def showEvent(self, event): """Runs when the widget is about to be shown.""" - self.update_table() + self.update_engines_table() super().showEvent(event) # Ensure normal event processing - def update_table(self, use_cached=True): + def engine_data_ready(self, raw_server_data): + self.raw_server_data = raw_server_data + self.update_engines_table() + + def update_engines_table(self, use_cached=True): if not self.raw_server_data or not use_cached: - self.raw_server_data = RenderServerProxy(socket.gethostname()).get_engine_info() + self.worker = GetEngineInfoWorker(self) + self.worker.done.connect(self.engine_data_ready) + self.worker.start() + return if not self.raw_server_data: return