From 92a9dccc00566cd4b028bde052fe9b04c2041721 Mon Sep 17 00:00:00 2001 From: Mr Finchum Date: Sat, 1 Feb 2025 17:45:00 +0000 Subject: [PATCH] patch: update for ppu 0.5 --- CHANGELOG.md | 3 + pyproject.toml | 2 +- src/OptimaLab35/gui.py | 56 +++++++------- src/OptimaLab35/ui/updater_window.py | 83 ++++++++++----------- src/OptimaLab35/ui/updater_window.ui | 106 ++++++++++++--------------- 5 files changed, 118 insertions(+), 132 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6b9068..fdcff63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## 0.8.x +### 0.8.5: Patch for New PyPiUpdater Version +- **PyPiUpdater 0.5** introduced breaking changes; adjusted code to ensure compatibility with the new version. + ### 0.8.4: Minor Enhancements & Cleanup - Updated window titles. - Improved error handling for updater: now displays the specific error message instead of just **"error"** when an issue occurs during update checks. diff --git a/pyproject.toml b/pyproject.toml index a3f237f..b54eeb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ readme = "pip_README.md" requires-python = ">=3.8" dependencies = [ "optima35>=1.0.0, <2.0.0", - "PyPiUpdater>=0.4.0, <1.0.0", + "PyPiUpdater>=0.5.0, <1.0.0", "pyside6", "PyYAML", ] diff --git a/src/OptimaLab35/gui.py b/src/OptimaLab35/gui.py index 1f8e5ed..838222b 100644 --- a/src/OptimaLab35/gui.py +++ b/src/OptimaLab35/gui.py @@ -479,6 +479,7 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): super(UpdaterWindow, self).__init__() self.ui = Ui_Updater_Window() self.ui.setupUi(self) + self.dev_mode = True if optimalab35_localversion == "0.0.1" else False from PyPiUpdater import PyPiUpdater # Update log file location self.update_log_file = os.path.expanduser("~/.config/OptimaLab35/update_log.json") @@ -492,8 +493,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): self.ol35_last_state = self.ppu_ol35.get_last_state() self.o35_last_state = self.ppu_o35.get_last_state() - #self.last_update = self.ppu_o35.last_update_date_string() - # Track which packages need an update self.updates_available = {"OptimaLab35": False, "optima35": False} @@ -501,11 +500,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): def define_gui_interaction(self): """Setup UI interactions.""" - if self.optimalab35_localversion == "0.0.1": - self.dev_mode() - return - else: - self.ui.label_dev.setVisible(False) self.ui.label_optimalab35_localversion.setText(self.optimalab35_localversion) self.ui.label_optima35_localversion.setText(self.optima35_localversion) @@ -519,13 +513,18 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): # Connect buttons to functions self.ui.check_for_update_Button.clicked.connect(self.check_for_updates) self.ui.update_and_restart_Button.clicked.connect(self.update_and_restart) - self.ui.label_last_check_2.setText(str(self.ol35_last_state[0])) + self.ui.label_last_check_2.setText(self.time_to_string(self.ol35_last_state[0])) def dev_mode(self): self.ui.update_and_restart_Button.setEnabled(False) self.ui.check_for_update_Button.setEnabled(False) self.ui.label_dev.setStyleSheet("QLabel { background-color : red; color : black; }") + def time_to_string(self, time_time): + dt_obj = datetime.fromtimestamp(time_time) + date_string = dt_obj.strftime("%d %h %H:%M") + return date_string + def check_for_updates(self): """Check for updates and update the UI.""" self.ui.check_for_update_Button.setEnabled(False) @@ -533,29 +532,31 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): self.ui.label_optima35_latestversion.setText("Checking...") # Check OptimaLab35 update - is_newer_ol35, latest_version_ol35 = self.ppu_ol35.check_for_update(True) - if is_newer_ol35 is None: - self.ui.label_optimalab35_latestversion.setText(latest_version_ol35[0:13]) + ol35_pkg_info = self.ppu_ol35.check_for_update() + if ol35_pkg_info[0] is None: + self.ui.label_optimalab35_latestversion.setText(ol35_pkg_info[1][0:13]) else: - self.ui.label_optimalab35_latestversion.setText(latest_version_ol35) - self.updates_available["OptimaLab35"] = is_newer_ol35 + self.ui.label_optimalab35_latestversion.setText(ol35_pkg_info[1]) + self.updates_available["OptimaLab35"] = ol35_pkg_info[0] # Check optima35 update - is_newer_o35, latest_version_o35 = self.ppu_o35.check_for_update(True) - if is_newer_o35 is None: - self.ui.label_optima35_latestversion.setText(latest_version_o35[0:13]) + o35_pkg_info = self.ppu_o35.check_for_update() + if o35_pkg_info[0] is None: + self.ui.label_optima35_latestversion.setText(o35_pkg_info[1][0:13]) else: - self.ui.label_optima35_latestversion.setText(latest_version_o35) - self.updates_available["optima35"] = is_newer_o35 + self.ui.label_optima35_latestversion.setText(o35_pkg_info[1]) + self.updates_available["optima35"] = o35_pkg_info[0] # Enable update button if any update is available if any(self.updates_available.values()): - self.ui.update_and_restart_Button.setEnabled(True) + if self.dev_mode: + self.ui.update_and_restart_Button.setEnabled(False) + self.ui.update_and_restart_Button.setText("Update disabled") + else: + self.ui.update_and_restart_Button.setEnabled(True) - self.ppu_o35.record_update_check() - self.ppu_ol35.record_update_check() - last_date = self.ppu_ol35.get_last_state() - self.ui.label_last_check_2.setText(last_date[0]) + last_date = self.time_to_string(self.ppu_ol35.get_last_state()[0]) + self.ui.label_last_check_2.setText(last_date) self.ui.label_latest_version.setText("Online version") self.ui.check_for_update_Button.setEnabled(True) @@ -570,7 +571,7 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): # Confirm update msg = QMessageBox() msg.setWindowTitle("Update Available") - msg.setText(f"Updating: {', '.join(packages_to_update)}\nRestart after update?") + msg.setText(f"Updating: {', '.join(packages_to_update)}\nUpdate and restart app?") msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) result = msg.exec() @@ -579,11 +580,11 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): for package in packages_to_update: if package == "OptimaLab35": - success, message = self.ppu_ol35.update_package() + pkg_info = self.ppu_ol35.update_package() elif package == "optima35": - success, message = self.ppu_o35.update_package() + pkg_info = self.ppu_o35.update_package() - update_results.append(f"{package}: {'✔ Success' if success else '❌ Failed'}\n{message}") + update_results.append(f"{package}: {'Success' if pkg_info[0] else 'Failed'}\n{pkg_info[1]}") # Show summary of updates # Show update completion message @@ -600,7 +601,6 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window): def restart_program(self): """Restart the Python program after an update.""" print("Restarting the application...") - # Close all running Qt windows before restarting app = QApplication.instance() if app: diff --git a/src/OptimaLab35/ui/updater_window.py b/src/OptimaLab35/ui/updater_window.py index cd61ba0..ce1de3c 100644 --- a/src/OptimaLab35/ui/updater_window.py +++ b/src/OptimaLab35/ui/updater_window.py @@ -23,7 +23,7 @@ class Ui_Updater_Window(object): if not Updater_Window.objectName(): Updater_Window.setObjectName(u"Updater_Window") Updater_Window.setEnabled(True) - Updater_Window.resize(372, 251) + Updater_Window.resize(372, 196) self.centralwidget = QWidget(Updater_Window) self.centralwidget.setObjectName(u"centralwidget") self.gridLayout_2 = QGridLayout(self.centralwidget) @@ -43,6 +43,34 @@ class Ui_Updater_Window(object): self.widget_2.setObjectName(u"widget_2") self.gridLayout = QGridLayout(self.widget_2) self.gridLayout.setObjectName(u"gridLayout") + self.label = QLabel(self.widget_2) + self.label.setObjectName(u"label") + + self.gridLayout.addWidget(self.label, 1, 0, 1, 1) + + self.label_optima35_localversion = QLabel(self.widget_2) + self.label_optima35_localversion.setObjectName(u"label_optima35_localversion") + self.label_optima35_localversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) + + self.gridLayout.addWidget(self.label_optima35_localversion, 2, 1, 1, 1) + + self.label_9 = QLabel(self.widget_2) + self.label_9.setObjectName(u"label_9") + + self.gridLayout.addWidget(self.label_9, 0, 0, 1, 1) + + self.label_optima35_latestversion = QLabel(self.widget_2) + self.label_optima35_latestversion.setObjectName(u"label_optima35_latestversion") + self.label_optima35_latestversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) + + self.gridLayout.addWidget(self.label_optima35_latestversion, 2, 2, 1, 1) + + self.label_optimalab35_localversion = QLabel(self.widget_2) + self.label_optimalab35_localversion.setObjectName(u"label_optimalab35_localversion") + self.label_optimalab35_localversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) + + self.gridLayout.addWidget(self.label_optimalab35_localversion, 1, 1, 1, 1) + self.label_6 = QLabel(self.widget_2) self.label_6.setObjectName(u"label_6") self.label_6.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) @@ -55,50 +83,16 @@ class Ui_Updater_Window(object): self.gridLayout.addWidget(self.label_optimalab35_latestversion, 1, 2, 1, 1) - self.label_2 = QLabel(self.widget_2) - self.label_2.setObjectName(u"label_2") - - self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1) - - self.label_optima35_latestversion = QLabel(self.widget_2) - self.label_optima35_latestversion.setObjectName(u"label_optima35_latestversion") - self.label_optima35_latestversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - - self.gridLayout.addWidget(self.label_optima35_latestversion, 3, 2, 1, 1) - self.label_latest_version = QLabel(self.widget_2) self.label_latest_version.setObjectName(u"label_latest_version") self.label_latest_version.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) self.gridLayout.addWidget(self.label_latest_version, 0, 2, 1, 1) - self.label = QLabel(self.widget_2) - self.label.setObjectName(u"label") + self.label_2 = QLabel(self.widget_2) + self.label_2.setObjectName(u"label_2") - self.gridLayout.addWidget(self.label, 1, 0, 1, 1) - - self.label_9 = QLabel(self.widget_2) - self.label_9.setObjectName(u"label_9") - - self.gridLayout.addWidget(self.label_9, 0, 0, 1, 1) - - self.label_optimalab35_localversion = QLabel(self.widget_2) - self.label_optimalab35_localversion.setObjectName(u"label_optimalab35_localversion") - self.label_optimalab35_localversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - - self.gridLayout.addWidget(self.label_optimalab35_localversion, 1, 1, 1, 1) - - self.label_optima35_localversion = QLabel(self.widget_2) - self.label_optima35_localversion.setObjectName(u"label_optima35_localversion") - self.label_optima35_localversion.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter) - - self.gridLayout.addWidget(self.label_optima35_localversion, 3, 1, 1, 1) - - self.label_dev = QLabel(self.widget_2) - self.label_dev.setObjectName(u"label_dev") - self.label_dev.setAlignment(Qt.AlignCenter) - - self.gridLayout.addWidget(self.label_dev, 2, 0, 1, 3) + self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1) self.gridLayout_2.addWidget(self.widget_2, 1, 0, 1, 2) @@ -131,16 +125,15 @@ class Ui_Updater_Window(object): Updater_Window.setWindowTitle(QCoreApplication.translate("Updater_Window", u"Updater", None)) self.label_last_check.setText(QCoreApplication.translate("Updater_Window", u"Last update check:", None)) self.label_last_check_2.setText(QCoreApplication.translate("Updater_Window", u"TextLabel", None)) + self.label.setText(QCoreApplication.translate("Updater_Window", u"OptimaLab35", None)) + self.label_optima35_localversion.setText(QCoreApplication.translate("Updater_Window", u"0.0.0", None)) + self.label_9.setText(QCoreApplication.translate("Updater_Window", u"Package", None)) + self.label_optima35_latestversion.setText(QCoreApplication.translate("Updater_Window", u"unknown", None)) + self.label_optimalab35_localversion.setText(QCoreApplication.translate("Updater_Window", u"0.0.0", None)) self.label_6.setText(QCoreApplication.translate("Updater_Window", u"Local Version", None)) self.label_optimalab35_latestversion.setText(QCoreApplication.translate("Updater_Window", u"unknown", None)) - self.label_2.setText(QCoreApplication.translate("Updater_Window", u"optima35", None)) - self.label_optima35_latestversion.setText(QCoreApplication.translate("Updater_Window", u"unknown", None)) self.label_latest_version.setText(QCoreApplication.translate("Updater_Window", u"Latest version", None)) - self.label.setText(QCoreApplication.translate("Updater_Window", u"OptimaLab35", None)) - self.label_9.setText(QCoreApplication.translate("Updater_Window", u"Package", None)) - self.label_optimalab35_localversion.setText(QCoreApplication.translate("Updater_Window", u"0.0.0", None)) - self.label_optima35_localversion.setText(QCoreApplication.translate("Updater_Window", u"0.0.0", None)) - self.label_dev.setText(QCoreApplication.translate("Updater_Window", u"Detected dev env. updater disabled", None)) + self.label_2.setText(QCoreApplication.translate("Updater_Window", u"optima35", None)) self.check_for_update_Button.setText(QCoreApplication.translate("Updater_Window", u"Check for update", None)) self.update_and_restart_Button.setText(QCoreApplication.translate("Updater_Window", u"Update and restart", None)) # retranslateUi diff --git a/src/OptimaLab35/ui/updater_window.ui b/src/OptimaLab35/ui/updater_window.ui index b1fb75e..9a8d2de 100644 --- a/src/OptimaLab35/ui/updater_window.ui +++ b/src/OptimaLab35/ui/updater_window.ui @@ -10,7 +10,7 @@ 0 0 372 - 251 + 196 @@ -38,6 +38,50 @@ + + + + OptimaLab35 + + + + + + + 0.0.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Package + + + + + + + unknown + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0.0.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -58,23 +102,6 @@ - - - - optima35 - - - - - - - unknown - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -85,47 +112,10 @@ - - + + - OptimaLab35 - - - - - - - Package - - - - - - - 0.0.0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 0.0.0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Detected dev env. updater disabled - - - Qt::AlignCenter + optima35