patch: Minor improvement for updater
This commit is contained in:
parent
630985d70c
commit
89c40a8ca1
4 changed files with 107 additions and 43 deletions
|
@ -12,7 +12,7 @@ from OptimaLab35.ui.exif_handler_window import ExifEditor
|
|||
from OptimaLab35.ui.simple_dialog import SimpleDialog # Import the SimpleDialog class
|
||||
from OptimaLab35 import __version__
|
||||
|
||||
from PySide6.QtCore import QRunnable, QThreadPool, Signal, QObject, QRegularExpression, Qt
|
||||
from PySide6.QtCore import QRunnable, QThreadPool, Signal, QObject, QRegularExpression, Qt, QTimer
|
||||
|
||||
from PySide6 import QtWidgets
|
||||
from PySide6.QtWidgets import (
|
||||
|
@ -479,8 +479,8 @@ 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
|
||||
self.set_dev_ui()
|
||||
self.dev_mode = True #True if optimalab35_localversion == "0.0.1" else False
|
||||
#self.set_dev_ui()
|
||||
from PyPiUpdater import PyPiUpdater
|
||||
# Update log file location
|
||||
self.update_log_file = os.path.expanduser("~/.config/OptimaLab35/update_log.json")
|
||||
|
@ -499,9 +499,23 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
|
||||
self.define_gui_interaction()
|
||||
|
||||
def start_long_press(self):
|
||||
"""Start the timer when button is pressed."""
|
||||
self.timer.start(1000) # 1-second long press
|
||||
|
||||
def cancel_long_press(self):
|
||||
"""Cancel long press if released early."""
|
||||
self.timer.stop()
|
||||
|
||||
def toggle_dev_ui(self):
|
||||
"""Show or hide the hidden UI when long press is detected."""
|
||||
self.ui.dev_widget.setVisible(True)
|
||||
|
||||
self.ui.check_local_Button.clicked.connect(self.local_check_for_updates)
|
||||
self.ui.update_local_Button.clicked.connect(self.local_update)
|
||||
|
||||
def define_gui_interaction(self):
|
||||
"""Setup UI interactions."""
|
||||
|
||||
self.ui.label_optimalab35_localversion.setText(self.optimalab35_localversion)
|
||||
self.ui.label_optima35_localversion.setText(self.optima35_localversion)
|
||||
|
||||
|
@ -515,16 +529,16 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
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(self.time_to_string(self.ol35_last_state[0]))
|
||||
self.ui.dev_widget.setVisible(False)
|
||||
|
||||
def set_dev_ui(self):
|
||||
self.ui.check_local_Button.setVisible(self.dev_mode)
|
||||
self.ui.update_local_Button.setVisible(self.dev_mode)
|
||||
self.ui.check_for_update_Button.setVisible(not self.dev_mode)
|
||||
self.ui.update_and_restart_Button.setVisible(not self.dev_mode)
|
||||
# Timer for long press detection
|
||||
self.timer = QTimer()
|
||||
self.timer.setSingleShot(True)
|
||||
self.timer.timeout.connect(self.toggle_dev_ui)
|
||||
|
||||
if self.dev_mode:
|
||||
self.ui.check_local_Button.clicked.connect(self.local_check_for_updates)
|
||||
self.ui.update_local_Button.clicked.connect(self.local_update)
|
||||
# Connect button press/release
|
||||
self.ui.check_for_update_Button.pressed.connect(self.start_long_press)
|
||||
self.ui.check_for_update_Button.released.connect(self.cancel_long_press)
|
||||
|
||||
def local_check_for_updates(self):
|
||||
dist_folder = os.path.expanduser("~/git/gitlab_public/OptimaLab35/dist/")
|
||||
|
@ -560,7 +574,14 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
# Confirm update
|
||||
msg = QMessageBox()
|
||||
msg.setWindowTitle("Update Available")
|
||||
msg.setText(f"Updating: {', '.join(packages_to_update)}\nUpdate and restart app?")
|
||||
message = f"Updating: {', '.join(packages_to_update)}\nUpdate "
|
||||
|
||||
if self.ui.restart_checkBox.isChecked():
|
||||
message = message + "and restart app?"
|
||||
else:
|
||||
message = message + "app?"
|
||||
|
||||
msg.setText(message)
|
||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||
result = msg.exec()
|
||||
|
||||
|
@ -584,8 +605,8 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
msg.exec()
|
||||
|
||||
# Restart the application after user clicks "OK"
|
||||
#self.ppu_ol35.restart_program()
|
||||
self.restart_program()
|
||||
if self.ui.restart_checkBox.isChecked():
|
||||
self.restart_program()
|
||||
|
||||
def time_to_string(self, time_time):
|
||||
dt_obj = datetime.fromtimestamp(time_time)
|
||||
|
@ -638,7 +659,14 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
# Confirm update
|
||||
msg = QMessageBox()
|
||||
msg.setWindowTitle("Update Available")
|
||||
msg.setText(f"Updating: {', '.join(packages_to_update)}\nUpdate and restart app?")
|
||||
message = f"Updating: {', '.join(packages_to_update)}\nUpdate "
|
||||
|
||||
if self.ui.restart_checkBox.isChecked():
|
||||
message = message + "and restart app?"
|
||||
else:
|
||||
message = message + "app?"
|
||||
|
||||
msg.setText(message)
|
||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
||||
result = msg.exec()
|
||||
|
||||
|
@ -662,8 +690,8 @@ class UpdaterWindow(QMainWindow, Ui_Updater_Window):
|
|||
msg.exec()
|
||||
|
||||
# Restart the application after user clicks "OK"
|
||||
#self.ppu_ol35.restart_program()
|
||||
self.restart_program()
|
||||
if self.ui.restart_checkBox.isChecked():
|
||||
self.restart_program()
|
||||
|
||||
def restart_program(self):
|
||||
"""Restart the Python program after an update."""
|
||||
|
|
|
@ -15,15 +15,16 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
|||
QFont, QFontDatabase, QGradient, QIcon,
|
||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||
from PySide6.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel,
|
||||
QMainWindow, QPushButton, QSizePolicy, QWidget)
|
||||
from PySide6.QtWidgets import (QApplication, QCheckBox, QGridLayout, QHBoxLayout,
|
||||
QLabel, QMainWindow, QPushButton, QSizePolicy,
|
||||
QWidget)
|
||||
|
||||
class Ui_Updater_Window(object):
|
||||
def setupUi(self, Updater_Window):
|
||||
if not Updater_Window.objectName():
|
||||
Updater_Window.setObjectName(u"Updater_Window")
|
||||
Updater_Window.setEnabled(True)
|
||||
Updater_Window.resize(336, 200)
|
||||
Updater_Window.resize(340, 200)
|
||||
Updater_Window.setMinimumSize(QSize(336, 200))
|
||||
Updater_Window.setMaximumSize(QSize(340, 300))
|
||||
self.centralwidget = QWidget(Updater_Window)
|
||||
|
@ -102,15 +103,11 @@ class Ui_Updater_Window(object):
|
|||
|
||||
self.horizontalLayout.addWidget(self.update_and_restart_Button)
|
||||
|
||||
self.check_local_Button = QPushButton(self.widget)
|
||||
self.check_local_Button.setObjectName(u"check_local_Button")
|
||||
self.restart_checkBox = QCheckBox(self.widget)
|
||||
self.restart_checkBox.setObjectName(u"restart_checkBox")
|
||||
self.restart_checkBox.setChecked(True)
|
||||
|
||||
self.horizontalLayout.addWidget(self.check_local_Button)
|
||||
|
||||
self.update_local_Button = QPushButton(self.widget)
|
||||
self.update_local_Button.setObjectName(u"update_local_Button")
|
||||
|
||||
self.horizontalLayout.addWidget(self.update_local_Button)
|
||||
self.horizontalLayout.addWidget(self.restart_checkBox)
|
||||
|
||||
|
||||
self.gridLayout_2.addWidget(self.widget, 2, 0, 1, 2)
|
||||
|
@ -127,6 +124,23 @@ class Ui_Updater_Window(object):
|
|||
|
||||
self.gridLayout_2.addWidget(self.label_last_check_2, 0, 1, 1, 1)
|
||||
|
||||
self.dev_widget = QWidget(self.centralwidget)
|
||||
self.dev_widget.setObjectName(u"dev_widget")
|
||||
self.horizontalLayout_2 = QHBoxLayout(self.dev_widget)
|
||||
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||
self.check_local_Button = QPushButton(self.dev_widget)
|
||||
self.check_local_Button.setObjectName(u"check_local_Button")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.check_local_Button)
|
||||
|
||||
self.update_local_Button = QPushButton(self.dev_widget)
|
||||
self.update_local_Button.setObjectName(u"update_local_Button")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.update_local_Button)
|
||||
|
||||
|
||||
self.gridLayout_2.addWidget(self.dev_widget, 3, 0, 1, 2)
|
||||
|
||||
Updater_Window.setCentralWidget(self.centralwidget)
|
||||
|
||||
self.retranslateUi(Updater_Window)
|
||||
|
@ -146,10 +160,14 @@ class Ui_Updater_Window(object):
|
|||
self.label_latest_version.setText(QCoreApplication.translate("Updater_Window", u"Latest version", 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))
|
||||
self.check_local_Button.setText(QCoreApplication.translate("Updater_Window", u"Check local", None))
|
||||
self.update_local_Button.setText(QCoreApplication.translate("Updater_Window", u"Update local", None))
|
||||
self.update_and_restart_Button.setText(QCoreApplication.translate("Updater_Window", u"Update", None))
|
||||
#if QT_CONFIG(tooltip)
|
||||
self.restart_checkBox.setToolTip(QCoreApplication.translate("Updater_Window", u"Restarts the app after update.", None))
|
||||
#endif // QT_CONFIG(tooltip)
|
||||
self.restart_checkBox.setText(QCoreApplication.translate("Updater_Window", u"Restart", 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.check_local_Button.setText(QCoreApplication.translate("Updater_Window", u"Check local", None))
|
||||
self.update_local_Button.setText(QCoreApplication.translate("Updater_Window", u"Update local", None))
|
||||
# retranslateUi
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>336</width>
|
||||
<width>340</width>
|
||||
<height>200</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -130,21 +130,20 @@
|
|||
<item>
|
||||
<widget class="QPushButton" name="update_and_restart_Button">
|
||||
<property name="text">
|
||||
<string>Update and restart</string>
|
||||
<string>Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="check_local_Button">
|
||||
<property name="text">
|
||||
<string>Check local</string>
|
||||
<widget class="QCheckBox" name="restart_checkBox">
|
||||
<property name="toolTip">
|
||||
<string>Restarts the app after update.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="update_local_Button">
|
||||
<property name="text">
|
||||
<string>Update local</string>
|
||||
<string>Restart</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -171,6 +170,26 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QWidget" name="dev_widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="check_local_Button">
|
||||
<property name="text">
|
||||
<string>Check local</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="update_local_Button">
|
||||
<property name="text">
|
||||
<string>Update local</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
|
@ -29,7 +29,6 @@ class Utilities:
|
|||
|
||||
def _ensure_program_folder_exists(self):
|
||||
program_folder = os.path.expanduser("~/.config/OptimaLab35")
|
||||
print(program_folder)
|
||||
if not os.path.exists(program_folder):
|
||||
print("in not, make folder")
|
||||
os.makedirs(program_folder)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue