From 26d25359fdb29f3338c6f83b8ce3498d85812fa6 Mon Sep 17 00:00:00 2001 From: bbtufty Date: Sun, 27 Oct 2024 09:52:11 +0000 Subject: [PATCH] Fix directory changes in dev tools Fix directory changes in dev tools --- CHANGES.rst | 1 + nxbrew_dl/gui/gui_nxbrew_dl.py | 76 +++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c1f060a..9a7dc5b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,7 @@ 0.4 (Unreleased) ================ +- Keep games list searchable even when downloads are running [#18] - If error occurs, don't crash GUI [#17] - Exclude log folder so pip builds successfully [#16] - Further fixes for link shortening [#15] diff --git a/nxbrew_dl/gui/gui_nxbrew_dl.py b/nxbrew_dl/gui/gui_nxbrew_dl.py index 9748d55..d38cd3f 100644 --- a/nxbrew_dl/gui/gui_nxbrew_dl.py +++ b/nxbrew_dl/gui/gui_nxbrew_dl.py @@ -78,7 +78,7 @@ def __init__(self): # Check for version updates self.logger.info("Checking for new versions online") - github_version, github_url = check_github_version() + github_version, github_url = check_github_version() local_version = nxbrew_dl.__version__ new_version_available = False @@ -88,9 +88,10 @@ def __init__(self): else: self.logger.info("You have the latest version of NXBrew-dl") - self.update_notification = self.setup_update_notification(new_version_available, - url=github_url, - ) + self.update_notification = self.setup_update_notification( + new_version_available, + url=github_url, + ) # Load in various config files self.mod_dir = os.path.dirname(nxbrew_dl.__file__) @@ -172,10 +173,11 @@ def __init__(self): self.load_table() - def setup_update_notification(self, - new_version_available, - url, - ): + def setup_update_notification( + self, + new_version_available, + url, + ): """Create a message box to open up to the latest GitHub release""" if not new_version_available: @@ -183,10 +185,12 @@ def setup_update_notification(self, # Open up a dialogue box to go to the webpage update_box = QMessageBox() - reply = update_box.question(self, - "Version update!", - "Open latest GitHub release?", - QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + reply = update_box.question( + self, + "Version update!", + "Open latest GitHub release?", + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, + ) if reply == QMessageBox.StandardButton.Yes: self.logger.info("Opening GitHub, and closing down") @@ -254,7 +258,6 @@ def load_table(self): found_cache_item = False for r in range(self.game_table.rowCount()): if self.game_table.item(r, 0).toolTip() == cache_item: - self.game_table.item(r, 1).setCheckState(Qt.CheckState.Checked) found_cache_item = True break @@ -405,7 +408,6 @@ def run_nxbrew_dl(self): for g in self.game_dict: if self.game_dict[g]["url"] == url: - n = self.game_dict[g]["short_name"] to_download.update({n: url}) @@ -428,13 +430,14 @@ def run_nxbrew_dl(self): # When finished, re-enable the UI self.nxbrew_thread.finished.connect( - lambda: self.ui.centralwidget.setEnabled(True) + lambda: self.enable_disable_ui(mode="enable") ) + # Start the thread self.nxbrew_thread.start() # Disable the UI - self.ui.centralwidget.setEnabled(False) + self.enable_disable_ui(mode="disable") return True @@ -450,6 +453,47 @@ def closeEvent(self, event): event.accept() + def enable_disable_ui(self, mode="disable"): + """Selective enable/disable parts of the UI + + Args: + mode: Whether to 'enable' or 'disable'. Defaults + to disable + """ + + # Disable the various UI elements + ui_elements = [ + self.ui.lineEditNXBrewURL, + self.ui.lineEditDownloadDir, + self.ui.pushButtonDownloadDir, + self.ui.lineEditJDownloaderDevice, + self.ui.lineEditJDownloaderUser, + self.ui.lineEditJDownloaderPass, + self.ui.radioButtonPreferNSP, + self.ui.radioButtonPreferXCI, + self.ui.checkBoxDownloadUpdates, + self.ui.checkBoxDownloadDLC, + self.ui.pushButtonRegionLanguage, + self.ui.checkBoxDryRun, + self.ui.lineEditDiscordURL, + self.ui.tableGames, + self.ui.pushButtonRefresh, + self.ui.pushButtonRun, + self.ui.pushButtonExit, + ] + + for e in ui_elements: + if mode == "disable": + e.setEnabled(False) + elif mode == "enable": + e.setEnabled(True) + else: + raise ValueError( + f"Button {mode} should be one of 'disable' or 'enable'" + ) + + return True + class NXBrewWorker(QObject): """Handles running NXBrew so GUI doesn't hang"""