Skip to content

Commit fe71b33

Browse files
author
Mehmet Cagri Aksoy
committed
Performance improvements -> unused import removed
1 parent 1876e23 commit fe71b33

File tree

5 files changed

+25
-32
lines changed

5 files changed

+25
-32
lines changed

CITATION.cff

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ authors:
55
given-names: "Mehmet Çağrı"
66
orcid: " https://orcid.org/0000-0002-7886-7945 "
77
title: "Serial-Communication-GUI-Program"
8-
version: 1.0.0
9-
doi: 10.5281/zenodo.1234
8+
version: 2024.04
109
date-released: 2018
1110
url: "https://github.com/mcagriaksoy/Serial-Communication-GUI-Program"
-21 Bytes
Binary file not shown.

src/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
__copyright__ = "Copyright 2023, The AFCOM Project"
88
__credits__ = ["Mehmet Cagri Aksoy"]
99
__license__ = "MIT"
10-
__version__ = "1.0.1"
10+
__version__ = "2024.04"
1111
__maintainer__ = "Mehmet Cagri Aksoy"
1212
__status__ = "Production"
1313

src/ui_config.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
66
# run again. Do not edit this file unless you know what you are doing.
77

8-
98
from PyQt6 import QtCore, QtGui, QtWidgets
109

11-
1210
class Ui_main_window(object):
1311
def setupUi(self, main_window):
1412
main_window.setObjectName("main_window")

src/ui_main.py

+23-27
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@
66

77
__author__ = 'Mehmet Cagri Aksoy - github.com/mcagriaksoy'
88
__annotations__ = 'AFCOM - Serial Communication GUI Program'
9+
__version__ = '2024.04'
10+
__license__ = 'MIT'
11+
__status__ = 'Research'
912

1013
# IMPORTS
11-
import sys
12-
import glob
13-
import os
14+
from os import path, system
15+
from sys import platform, exit, argv
16+
from glob import glob
1417

1518
# Runtime Type Checking
1619
PROGRAM_TYPE_DEBUG = 1
1720
PROGRAM_TYPE_RELEASE = 0
21+
1822
try:
19-
import serial
2023
import serial.tools.list_ports
21-
from serial import SerialException
24+
from serial import SerialException, Serial
2225
except ImportError as e:
2326
print("Import Error! I am installing the PySerial library.")
24-
os.system("python -m pip install pyserial")
27+
system("python -m pip install pyserial")
2528

2629
try:
27-
from PyQt6.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
30+
from PyQt6.QtCore import QObject, QThread, pyqtSignal
2831
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog
2932

3033
if (PROGRAM_TYPE_DEBUG):
@@ -33,15 +36,13 @@
3336
from ui_config import Ui_main_window
3437
except ImportError as e:
3538
print("Import Error! I am installing the required libraries: " + str(e))
36-
os.system("pip install {0}".format(str(e).split(" ")[-1]))
39+
system("pip install {0}".format(str(e).split(" ")[-1]))
3740

3841
# GLOBAL VARIABLES
39-
SERIAL_INFO = serial.Serial()
42+
SERIAL_INFO = Serial()
4043
PORTS = []
41-
4244
is_serial_port_established = False
4345

44-
4546
def get_serial_port():
4647
""" Lists serial port names
4748
@@ -50,35 +51,32 @@ def get_serial_port():
5051
:returns:
5152
A list of the serial ports available on the system
5253
"""
53-
if sys.platform.startswith('win'):
54+
if platform.startswith('win'):
5455
ports = ['COM%s' % (i + 1) for i in range(256)]
55-
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
56+
elif platform.startswith('linux') or platform.startswith('cygwin'):
5657
# this excludes your current terminal "/dev/tty"
57-
ports = glob.glob('/dev/tty[A-Za-z]*')
58-
elif sys.platform.startswith('darwin'):
59-
ports = glob.glob('/dev/tty.*')
58+
ports = glob('/dev/tty[A-Za-z]*')
59+
elif platform.startswith('darwin'):
60+
ports = glob('/dev/tty.*')
6061
else:
6162
raise EnvironmentError('Unsupported platform')
6263

6364
result = []
6465
for port in ports:
6566
try:
66-
s = serial.Serial(port)
67+
s = Serial(port)
6768
s.close()
6869
result.append(port)
69-
except (OSError, serial.SerialException):
70+
except SerialException:
7071
pass
7172
return result
7273

7374
# MULTI-THREADING
74-
75-
7675
class Worker(QObject):
7776
""" Worker Thread """
7877
finished = pyqtSignal()
7978
serial_data = pyqtSignal(str)
8079

81-
@pyqtSlot()
8280
def __init__(self):
8381
super(Worker, self).__init__()
8482
self.working = True
@@ -96,18 +94,17 @@ def work(self):
9694
self.working = False
9795
self.finished.emit()
9896

99-
10097
class MainWindow(QMainWindow):
10198
""" Main Window """
10299

103100
def __init__(self):
104101
""" Initialize Main Window """
105102
super(MainWindow, self).__init__()
106103
if PROGRAM_TYPE_DEBUG:
107-
file_path = os.path.join("../ui/main_window.ui")
108-
if not os.path.exists(file_path):
104+
file_path = path.join("../ui/main_window.ui")
105+
if not path.exists(file_path):
109106
print("UI File Not Found!")
110-
sys.exit(1)
107+
exit(1)
111108
loadUi(file_path, self) # Load the .ui file
112109
self.show() # Show the GUI
113110

@@ -314,10 +311,9 @@ def on_send_data_button_clicked(self):
314311
self.print_message_on_screen(
315312
"Serial Port is not established yet! Please establish the serial port first!")
316313

317-
318314
def start_ui_design():
319315
""" Start the UI Design """
320-
app = QApplication(sys.argv) # Create an instance
316+
app = QApplication(argv) # Create an instance
321317
window_object = MainWindow() # Create an instance of our class
322318

323319
if PROGRAM_TYPE_RELEASE:

0 commit comments

Comments
 (0)