Skip to content

Commit 807f2d7

Browse files
mcagriaksoymcagriaksoy
authored andcommitted
More UI changes in case of seperated actions
1 parent fe557a3 commit 807f2d7

File tree

6 files changed

+691
-61
lines changed

6 files changed

+691
-61
lines changed

src/action_ui.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@file action_ui.py
4+
@brief Action UI for the application.
5+
@details This module provides the Action UI for the application, allowing users to interact with the system.
6+
"""
7+
try:
8+
from PySide6.QtUiTools import QUiLoader
9+
from PySide6.QtWidgets import QDialog, QFileDialog, QMessageBox
10+
from PySide6.QtCore import QFile
11+
except ImportError:
12+
print("PySide6 is not installed. Please install it to use this module.")
13+
14+
15+
def action_save_as(ui):
16+
"""
17+
Save the current state of the application as a new file.
18+
"""
19+
# Open the file dialog to select the save location and file name
20+
file_name, _ = QFileDialog.getSaveFileName(
21+
None, 'Save File', '', 'Text Files (*.txt)')
22+
if file_name:
23+
with open(file_name, 'w') as file:
24+
text = ui.data_textEdit.toPlainText() # Access the textEdit element
25+
file.write(text)
26+
27+
def action_save(ui):
28+
"""
29+
Save the current state of the application to the existing file.
30+
"""
31+
# Check if a file is already open
32+
if hasattr(ui, 'current_file'):
33+
# Save the current state to the existing file
34+
with open(ui.current_file, 'w') as file:
35+
file.write(ui.data_textEdit.toPlainText())
36+
else:
37+
# If no file is open, call action_save_as to prompt for a file name
38+
action_save_as(ui)
39+
40+
def basic_view_enabled(ui):
41+
""" Hide specific layouts in the UI for basic view """
42+
# Hide all widgets in the verticalLayout_config
43+
for i in range(ui.verticalLayout_config.count()):
44+
widget = ui.verticalLayout_config.itemAt(i).widget()
45+
if widget:
46+
widget.setVisible(False)
47+
48+
# Optionally, hide all widgets in the formLayout_config
49+
for i in range(ui.formLayout_config.count()):
50+
widget = ui.formLayout_config.itemAt(i).widget()
51+
if widget:
52+
widget.setVisible(False)
53+
54+
def advanced_view_enabled(ui):
55+
""" Show specific layouts in the UI for advanced view """
56+
# Show all widgets in the verticalLayout_config
57+
for i in range(ui.verticalLayout_config.count()):
58+
widget = ui.verticalLayout_config.itemAt(i).widget()
59+
if widget:
60+
widget.setVisible(True)
61+
62+
# Optionally, show all widgets in the formLayout_config
63+
for i in range(ui.formLayout_config.count()):
64+
widget = ui.formLayout_config.itemAt(i).widget()
65+
if widget:
66+
widget.setVisible(True)
67+
68+
def clear_buffer(ui):
69+
""" Clear the buffer """
70+
ui.data_textEdit.clear()
71+
ui.send_data_text.clear()
72+
73+
def show_about_dialog(ui):
74+
""" Show the about dialog """
75+
# Crete a message box to display the about information
76+
msg_box = QMessageBox()
77+
msg_box.setWindowTitle("About")
78+
msg_box.setText("AFCOM Client v1.4.0.0 (C) 2020 - 2025 \r\n\r\nAuthor: Mehmet Cagri Aksoy \r\ngithub.com/mcagriaksoy")
79+
msg_box.setIcon(QMessageBox.Information)
80+
msg_box.setStandardButtons(QMessageBox.Ok)
81+
msg_box.setDefaultButton(QMessageBox.Ok)
82+
msg_box.setModal(True)
83+
msg_box.exec() # Show the message box modally
84+
85+
86+
def show_help_dialog(ui):
87+
""" Show the help dialog """
88+
# Load the help.ui file
89+
file_path = "ui/help.ui" # Adjust the path if necessary
90+
ui_file = QFile(file_path)
91+
if not ui_file.exists():
92+
QMessageBox.critical(None, "Error", f"Help UI file not found: {file_path}")
93+
return
94+
95+
ui_file.open(QFile.ReadOnly)
96+
loader = QUiLoader()
97+
help_dialog = loader.load(ui_file)
98+
ui_file.close()
99+
100+
if help_dialog:
101+
# Show the help dialog as a modal dialog
102+
help_dialog.setWindowTitle("Help")
103+
help_dialog.setModal(True)
104+
help_dialog.exec()
105+
else:
106+
QMessageBox.critical(None, "Error", "Failed to load the help UI.")
107+
108+
def show_settings_dialog(ui):
109+
""" Show the settings dialog """
110+
# Load the settings.ui file
111+
file_path = "ui/settings.ui" # Adjust the path if necessary
112+
ui_file = QFile(file_path)
113+
if not ui_file.exists():
114+
QMessageBox.critical(None, "Error", f"Settings UI file not found: {file_path}")
115+
return
116+
117+
ui_file.open(QFile.ReadOnly)
118+
loader = QUiLoader()
119+
settings_dialog = loader.load(ui_file)
120+
ui_file.close()
121+
122+
if settings_dialog:
123+
# Show the settings dialog as a modal dialog
124+
settings_dialog.setWindowTitle("Settings")
125+
settings_dialog.setModal(True)
126+
settings_dialog.exec()
127+
else:
128+
QMessageBox.critical(None, "Error", "Failed to load the settings UI.")
129+
130+
def check_for_updates(ui):
131+
""" Check for updates """
132+
# Placeholder function for checking updates
133+
# You can implement the actual update check logic here
134+
QMessageBox.information(ui, "Check for Updates", "No updates available at this time.")
135+
136+
137+

src/help.py

Whitespace-only changes.

src/ui_main.py

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from sys import platform, exit, argv
1616
from glob import glob
1717

18+
from src import action_ui
1819
# Runtime Type Checking
1920
PROGRAM_TYPE_DEBUG = True
2021
PROGRAM_TYPE_RELEASE = False
@@ -27,8 +28,8 @@
2728
#system("python -m pip install pyserial")
2829

2930
try:
30-
from PySide6.QtCore import QObject, QThread, Signal, QFile
31-
from PySide6.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog, QFileDialog
31+
from PySide6.QtCore import QObject, QThread, Signal, QFile, Qt
32+
from PySide6.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog
3233

3334
if (PROGRAM_TYPE_DEBUG):
3435
from PySide6.QtUiTools import QUiLoader
@@ -154,47 +155,23 @@ def __init__(self):
154155
self.ui.saved_command_4.clicked.connect(self.move_command4_to_text)
155156
'''
156157

157-
# When actionClear_Cache is triggered, clear the buffer
158-
self.ui.actionClear_Cache.triggered.connect(self.clear_buffer)
158+
self.ui.actionClear_Cache.triggered.connect(action_ui.clear_buffer)
159159

160-
self.ui.actionBasic_View.triggered.connect(self.basic_view_enabled)
161-
self.ui.actionAdvanced_View.triggered.connect(self.advanced_view_enabled)
162-
#self.ui.clear_buffer_button.clicked.connect(self.clear_buffer)
160+
self.ui.actionBasic_View.triggered.connect(lambda: action_ui.basic_view_enabled(self.ui))
161+
self.ui.actionAdvanced_View.triggered.connect(lambda: action_ui.advanced_view_enabled(self.ui))
163162

164-
# self.ui.view_change.clicked.connect(self.view_changes)
163+
self.ui.actionSave.triggered.connect(action_ui.action_save)
164+
self.ui.actionSave_As.triggered.connect(action_ui.action_save_as)
165165

166166
self.ui.port_comboBox.addItems(PORTS)
167167
self.ui.send_button.clicked.connect(self.on_send_data_button_clicked)
168168

169-
def basic_view_enabled(self):
170-
""" Hide specific layouts in the UI for basic view """
171-
# Hide all widgets in the verticalLayout_config
172-
for i in range(self.ui.verticalLayout_config.count()):
173-
widget = self.ui.verticalLayout_config.itemAt(i).widget()
174-
if widget:
175-
widget.setVisible(False)
176-
177-
# Optionally, hide all widgets in the formLayout_config
178-
for i in range(self.ui.formLayout_config.count()):
179-
widget = self.ui.formLayout_config.itemAt(i).widget()
180-
if widget:
181-
widget.setVisible(False)
182-
183-
def advanced_view_enabled(self):
184-
""" Show specific layouts in the UI for advanced view """
185-
# Show all widgets in the verticalLayout_config
186-
for i in range(self.ui.verticalLayout_config.count()):
187-
widget = self.ui.verticalLayout_config.itemAt(i).widget()
188-
if widget:
189-
widget.setVisible(True)
190-
191-
# Optionally, show all widgets in the formLayout_config
192-
for i in range(self.ui.formLayout_config.count()):
193-
widget = self.ui.formLayout_config.itemAt(i).widget()
194-
if widget:
195-
widget.setVisible(True)
169+
self.ui.actionExit.triggered.connect(lambda: exit(0))
170+
self.ui.actionAbout.triggered.connect(action_ui.show_about_dialog)
171+
self.ui.actionCheck_for_updates.triggered.connect(action_ui.check_for_updates)
172+
self.ui.actionHelp_2.triggered.connect(action_ui.show_help_dialog)
173+
self.ui.actionPreferences.triggered.connect(action_ui.show_settings_dialog)
196174

197-
198175
'''
199176
def command1(self):
200177
""" Open the text input popup to save command for button 1 """
@@ -377,12 +354,6 @@ def stop_loop(self):
377354
# Disconnect the serial port and close it
378355
SERIAL_DEVICE.close()
379356

380-
def clear_buffer(self):
381-
""" Clear the buffer """
382-
self.ui.data_textEdit.clear()
383-
self.ui.send_data_text.clear()
384-
385-
386357
def read_data_from_thread(self, serial_data):
387358
""" Write the result to the text edit box"""
388359
# self.ui.data_textEdit.append("{}".format(i))
@@ -410,17 +381,6 @@ def read_data_from_thread(self, serial_data):
410381
self.ui.data_textEdit.verticalScrollBar().setValue(
411382
self.ui.data_textEdit.verticalScrollBar().maximum())
412383

413-
def on_save_txt_button_clicked(self):
414-
""" Save the values to the TXT file"""
415-
# Open file dialog to create new .txt file
416-
file_name, _ = QFileDialog.getSaveFileName(
417-
self, 'Save File', '', 'Text Files (*.txt)')
418-
if file_name:
419-
with open(file_name, 'w') as file:
420-
text = self.ui.data_textEdit.toPlainText()
421-
file.write(text)
422-
file.close()
423-
424384
def on_end_button_clicked(self):
425385
""" Stop the process """
426386
global is_serial_port_established

ui/main_window.ui

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<string>AFCOM Client (A free COM port data transfer client)</string>
3636
</property>
3737
<property name="windowIcon">
38-
<iconset>
39-
<normaloff>icon.ico</normaloff>icon.ico</iconset>
38+
<iconset resource="resources.qrc">
39+
<normaloff>:/res/icon.ico</normaloff>:/res/icon.ico</iconset>
4040
</property>
4141
<property name="windowOpacity">
4242
<double>1.000000000000000</double>
@@ -127,7 +127,7 @@
127127
<item row="0" column="0">
128128
<widget class="QLabel" name="label_46">
129129
<property name="text">
130-
<string> Refresh Port(s):</string>
130+
<string>Refresh Port(s):</string>
131131
</property>
132132
</widget>
133133
</item>
@@ -565,6 +565,8 @@
565565
</property>
566566
<addaction name="separator"/>
567567
<addaction name="actionNew"/>
568+
<addaction name="actionSave"/>
569+
<addaction name="actionSave_As"/>
568570
<addaction name="separator"/>
569571
<addaction name="actionExit"/>
570572
</widget>
@@ -575,8 +577,9 @@
575577
</widget>
576578
<widget class="QMenu" name="menuSetup">
577579
<property name="title">
578-
<string>Setup</string>
580+
<string>Settings</string>
579581
</property>
582+
<addaction name="actionPreferences"/>
580583
</widget>
581584
<widget class="QMenu" name="menuControl">
582585
<property name="title">
@@ -589,6 +592,7 @@
589592
<property name="title">
590593
<string>Help</string>
591594
</property>
595+
<addaction name="actionHelp_2"/>
592596
<addaction name="separator"/>
593597
<addaction name="actionAbout"/>
594598
<addaction name="actionCheck_for_updates"/>
@@ -599,6 +603,7 @@
599603
</property>
600604
<addaction name="actionBasic_View"/>
601605
<addaction name="actionAdvanced_View"/>
606+
<addaction name="separator"/>
602607
</widget>
603608
<addaction name="menuFile"/>
604609
<addaction name="menuEdit"/>
@@ -657,7 +662,39 @@
657662
<string>Advanced View</string>
658663
</property>
659664
</action>
665+
<action name="actionPreferences">
666+
<property name="text">
667+
<string>Preferences..</string>
668+
</property>
669+
</action>
670+
<action name="actionMinimize">
671+
<property name="text">
672+
<string>Minimize</string>
673+
</property>
674+
</action>
675+
<action name="actionFull_Screen">
676+
<property name="text">
677+
<string>Full Screen</string>
678+
</property>
679+
</action>
680+
<action name="actionHelp_2">
681+
<property name="text">
682+
<string>Help</string>
683+
</property>
684+
</action>
685+
<action name="actionSave_As">
686+
<property name="text">
687+
<string>Save As..</string>
688+
</property>
689+
</action>
690+
<action name="actionSave">
691+
<property name="text">
692+
<string>Save</string>
693+
</property>
694+
</action>
660695
</widget>
661-
<resources/>
696+
<resources>
697+
<include location="resources.qrc"/>
698+
</resources>
662699
<connections/>
663700
</ui>

ui/resources.qrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/">
3-
<file>resource/play.svg</file>
4-
</qresource>
2+
<qresource prefix="res">
3+
<file>icon.ico</file>
4+
</qresource>
55
</RCC>

0 commit comments

Comments
 (0)