Skip to content

Commit

Permalink
Fix directory changes in dev tools
Browse files Browse the repository at this point in the history
Fix directory changes in dev tools
  • Loading branch information
bbtufty committed Oct 27, 2024
1 parent 218d6fc commit 26d2535
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
76 changes: 60 additions & 16 deletions nxbrew_dl/gui/gui_nxbrew_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)
Expand Down Expand Up @@ -172,21 +173,24 @@ 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:
return None

# 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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})

Expand All @@ -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

Expand All @@ -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"""
Expand Down

0 comments on commit 26d2535

Please sign in to comment.