Skip to content

Commit 1107948

Browse files
author
Mehmet Aksoy
committed
Adds update check and edit menu actions
Implements functionality to check for updates against GitHub releases. It displays a prompt to download the latest version if a newer one is available. If the 'requests' library is missing, it informs the user to install it. Adds copy, select all and clear screen actions to the edit menu for improved text editing within the application.
1 parent 5f6da2c commit 1107948

File tree

3 files changed

+86
-7
lines changed

3 files changed

+86
-7
lines changed

src/action_ui.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
from PySide6.QtUiTools import QUiLoader
1212
from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox
1313
from PySide6.QtCore import QFile
14+
from PySide6.QtGui import QDesktopServices
15+
from PySide6.QtCore import QUrl
1416
from ui.settings import Ui_Dialog
1517
from ui.help import Ui_HelpDialog
1618
except ImportError:
1719
print("PySide6 is not installed. Please install it to use this module.")
1820

21+
import json
22+
try:
23+
import requests
24+
except ImportError:
25+
requests = None
26+
27+
CURRENT_VERSION = "v1.5.1"
28+
1929
def action_save_as(ui):
2030
"""
2131
Save the current state of the application as a new file.
@@ -76,17 +86,17 @@ def clear_buffer(ui):
7686

7787
def show_about_dialog(ui):
7888
""" Show the about dialog """
79-
# Crete a message box to display the about information
89+
# Create a message box to display the about information
8090
msg_box = QMessageBox()
8191
msg_box.setWindowTitle("About")
82-
msg_box.setText("AFCOM Client v1.4.0.0 (C) 2020 - 2025 \r\n\r\nAuthor: Mehmet Cagri Aksoy \r\ngithub.com/mcagriaksoy")
92+
# Use CURRENT_VERSION for the version number
93+
msg_box.setText(f"AFCOM Client {CURRENT_VERSION} (C) 2020 - 2025 \r\n\r\nAuthor: Mehmet Cagri Aksoy \r\ngithub.com/mcagriaksoy")
8394
msg_box.setIcon(QMessageBox.Information)
8495
msg_box.setStandardButtons(QMessageBox.Ok)
8596
msg_box.setDefaultButton(QMessageBox.Ok)
8697
msg_box.setModal(True)
8798
msg_box.exec() # Show the message box modally
8899

89-
90100
def show_help_dialog(ui):
91101
""" Show the help dialog """
92102
if PROGRAM_TYPE_DEBUG:
@@ -146,10 +156,36 @@ def show_settings_dialog(ui):
146156
print(f"Error in show_settings_dialog: {e}")
147157

148158
def check_for_updates(ui):
149-
""" Check for updates """
150-
# Placeholder function for checking updates
151-
# You can implement the actual update check logic here
152-
QMessageBox.information(ui, "Check for Updates", "No updates available at this time.")
159+
"""Check for updates by comparing the latest GitHub tag with the current version."""
160+
if requests is None:
161+
QMessageBox.warning(None, "Check for Updates", "The 'requests' library is not installed. Please install it to check for updates.")
162+
return
163+
try:
164+
url = "https://api.github.com/repos/mcagriaksoy/Serial-Communication-GUI-Program/tags"
165+
response = requests.get(url, timeout=5)
166+
if response.status_code == 200:
167+
tags = response.json()
168+
if tags:
169+
latest_tag = tags[0]["name"]
170+
if latest_tag != CURRENT_VERSION:
171+
msg_box = QMessageBox()
172+
msg_box.setWindowTitle("Update Available")
173+
msg_box.setText(f"A new version is available: {latest_tag}\nYou are using: {CURRENT_VERSION}\nWould you like to download the latest version?")
174+
download_button = msg_box.addButton("Download", QMessageBox.AcceptRole)
175+
msg_box.addButton(QMessageBox.Ok)
176+
msg_box.setIcon(QMessageBox.Information)
177+
msg_box.setModal(True)
178+
msg_box.exec()
179+
if msg_box.clickedButton() == download_button:
180+
QDesktopServices.openUrl(QUrl(f"https://github.com/mcagriaksoy/Serial-Communication-GUI-Program/releases/tag/{latest_tag}"))
181+
else:
182+
QMessageBox.information(None, "Check for Updates", "You are using the latest version.")
183+
else:
184+
QMessageBox.information(None, "Check for Updates", "No version tags found on GitHub.")
185+
else:
186+
QMessageBox.warning(None, "Check for Updates", f"Failed to fetch updates. Status code: {response.status_code}")
187+
except Exception as e:
188+
QMessageBox.critical(None, "Check for Updates", f"Error checking for updates: {e}")
153189

154190

155191

src/ui_main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def __init__(self):
189189
self.ui.saved_command_4.clicked.connect(self.move_command4_to_text)
190190
'''
191191

192+
self.ui.actionCopy.triggered.connect(lambda: self.ui.data_textEdit.copy())
193+
self.ui.actionSelect_All.triggered.connect(lambda: self.ui.data_textEdit.selectAll())
194+
self.ui.actionClear_Screen.triggered.connect(lambda: self.ui.data_textEdit.clear())
195+
192196
self.ui.actionClear_Cache.triggered.connect(action_ui.clear_buffer)
193197

194198
self.ui.actionBasic_View.triggered.connect(lambda: action_ui.basic_view_enabled(self.ui))

ui/main_window.ui

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@
642642
<property name="title">
643643
<string>Edit</string>
644644
</property>
645+
<addaction name="actionCopy"/>
646+
<addaction name="actionClear_Screen"/>
647+
<addaction name="separator"/>
648+
<addaction name="actionSelect_All"/>
645649
</widget>
646650
<widget class="QMenu" name="menuSetup">
647651
<property name="title">
@@ -760,6 +764,41 @@
760764
<string>Save</string>
761765
</property>
762766
</action>
767+
<action name="actionCopy">
768+
<property name="text">
769+
<string>Copy</string>
770+
</property>
771+
</action>
772+
<action name="actionClear_Screen">
773+
<property name="text">
774+
<string>Clear Screen</string>
775+
</property>
776+
</action>
777+
<action name="actionClear_Buffer">
778+
<property name="text">
779+
<string>Clear Buffer</string>
780+
</property>
781+
</action>
782+
<action name="actionSelect_All">
783+
<property name="text">
784+
<string>Select All</string>
785+
</property>
786+
</action>
787+
<action name="actionMinimize_All">
788+
<property name="text">
789+
<string>Minimize All</string>
790+
</property>
791+
</action>
792+
<action name="actionCascade">
793+
<property name="text">
794+
<string>Cascade</string>
795+
</property>
796+
</action>
797+
<action name="actionSide_by_Side">
798+
<property name="text">
799+
<string>Side by Side</string>
800+
</property>
801+
</action>
763802
</widget>
764803
<resources>
765804
<include location="resources.qrc"/>

0 commit comments

Comments
 (0)