Skip to content

Commit

Permalink
Performance improvements -> unused import removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Cagri Aksoy committed Mar 17, 2024
1 parent 1876e23 commit fe71b33
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
3 changes: 1 addition & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors:
given-names: "Mehmet Çağrı"
orcid: " https://orcid.org/0000-0002-7886-7945 "
title: "Serial-Communication-GUI-Program"
version: 1.0.0
doi: 10.5281/zenodo.1234
version: 2024.04
date-released: 2018
url: "https://github.com/mcagriaksoy/Serial-Communication-GUI-Program"
Binary file modified src/__pycache__/ui_main.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__copyright__ = "Copyright 2023, The AFCOM Project"
__credits__ = ["Mehmet Cagri Aksoy"]
__license__ = "MIT"
__version__ = "1.0.1"
__version__ = "2024.04"
__maintainer__ = "Mehmet Cagri Aksoy"
__status__ = "Production"

Expand Down
2 changes: 0 additions & 2 deletions src/ui_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_main_window(object):
def setupUi(self, main_window):
main_window.setObjectName("main_window")
Expand Down
50 changes: 23 additions & 27 deletions src/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@

__author__ = 'Mehmet Cagri Aksoy - github.com/mcagriaksoy'
__annotations__ = 'AFCOM - Serial Communication GUI Program'
__version__ = '2024.04'
__license__ = 'MIT'
__status__ = 'Research'

# IMPORTS
import sys
import glob
import os
from os import path, system
from sys import platform, exit, argv
from glob import glob

# Runtime Type Checking
PROGRAM_TYPE_DEBUG = 1
PROGRAM_TYPE_RELEASE = 0

try:
import serial
import serial.tools.list_ports
from serial import SerialException
from serial import SerialException, Serial
except ImportError as e:
print("Import Error! I am installing the PySerial library.")
os.system("python -m pip install pyserial")
system("python -m pip install pyserial")

try:
from PyQt6.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from PyQt6.QtCore import QObject, QThread, pyqtSignal
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog

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

# GLOBAL VARIABLES
SERIAL_INFO = serial.Serial()
SERIAL_INFO = Serial()
PORTS = []

is_serial_port_established = False


def get_serial_port():
""" Lists serial port names
Expand All @@ -50,35 +51,32 @@ def get_serial_port():
:returns:
A list of the serial ports available on the system
"""
if sys.platform.startswith('win'):
if platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
elif platform.startswith('linux') or platform.startswith('cygwin'):
# this excludes your current terminal "/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
ports = glob('/dev/tty[A-Za-z]*')
elif platform.startswith('darwin'):
ports = glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')

result = []
for port in ports:
try:
s = serial.Serial(port)
s = Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
except SerialException:
pass
return result

# MULTI-THREADING


class Worker(QObject):
""" Worker Thread """
finished = pyqtSignal()
serial_data = pyqtSignal(str)

@pyqtSlot()
def __init__(self):
super(Worker, self).__init__()
self.working = True
Expand All @@ -96,18 +94,17 @@ def work(self):
self.working = False
self.finished.emit()


class MainWindow(QMainWindow):
""" Main Window """

def __init__(self):
""" Initialize Main Window """
super(MainWindow, self).__init__()
if PROGRAM_TYPE_DEBUG:
file_path = os.path.join("../ui/main_window.ui")
if not os.path.exists(file_path):
file_path = path.join("../ui/main_window.ui")
if not path.exists(file_path):
print("UI File Not Found!")
sys.exit(1)
exit(1)
loadUi(file_path, self) # Load the .ui file
self.show() # Show the GUI

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


def start_ui_design():
""" Start the UI Design """
app = QApplication(sys.argv) # Create an instance
app = QApplication(argv) # Create an instance
window_object = MainWindow() # Create an instance of our class

if PROGRAM_TYPE_RELEASE:
Expand Down

0 comments on commit fe71b33

Please sign in to comment.