Skip to content

Commit

Permalink
Fix nasa#72 - Upgrade PyQt4 to PyQt5
Browse files Browse the repository at this point in the history
Includes code cleanup/refactoring. Also fixes nasa#71
  • Loading branch information
lbleier-GSFC committed May 11, 2020
1 parent 8cd7b0e commit 9555ec8
Show file tree
Hide file tree
Showing 30 changed files with 11,542 additions and 13,602 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.pyc
cmdUtil
.DS_Store
.DS_Store
Subsystems/cmdGui/CHeaderParser.py
Subsystems/cmdGui/CHeaderParser.py
77 changes: 43 additions & 34 deletions GroundSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,89 @@
#
#cFS Ground System Version 2.0.0
#
#!/usr/bin/env python
#!/usr/bin/env python3
#
import shlex
import subprocess
import sys
import os
import socket
import zmq
from pathlib import Path

from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox

from PyQt4 import QtGui, QtNetwork, QtCore
from MainWindow import Ui_MainWindow
from RoutingService import RoutingService

ROOTDIR = Path(sys.argv[0]).resolve().parent


#
# CFS Ground System: Setup and manage the main window
#
class GroundSystem(QtGui.QMainWindow):
class GroundSystem(QMainWindow, Ui_MainWindow):

#
# Init the class
#
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self)
def __init__(self):
super().__init__()
self.setupUi((self))

self.RoutingService = None
self.alert = QMessageBox()

self.pushButtonStartTlm.clicked.connect(self.startTlmSystem)
self.pushButtonStartCmd.clicked.connect(self.startCmdSystem)
# Init lists
self.ipAddressesList = ['All']
self.spacecraftNames = ['All']

# Init GUI and set callback methods for buttons
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButtonStartTlm.clicked.connect(self.startTlmSystem)
self.ui.pushButtonStartCmd.clicked.connect(self.startCmdSystem)

def closeEvent(self, evnt):
if self.RoutingService:
self.RoutingService.stop()
print ("Stopped routing service")
print("Stopped routing service")

super(GroundSystem, self).closeEvent(evnt)
super().closeEvent(evnt)

# Read the selected spacecraft from combo box on GUI
def getSelectedSpacecraftAddress(self):
return str(self.ui.comboBoxIpAddresses.currentText())
return self.comboBoxIpAddresses.currentText().strip()

# Returns the name of the selected spacecraft
def getSelectedSpacecraftName(self):
return self.spacecraftNames[self.ipAddressesList.index(self.getSelectedSpacecraftAddress())]
return self.spacecraftNames[self.ipAddressesList.index(
self.getSelectedSpacecraftAddress())].strip()

#
# Display popup with error
#
def DisplayErrorMessage(self, message):
print (message)
alert = QtGui.QMessageBox()
alert.setText(message)
alert.setIcon(QtGui.QMessageBox.Warning)
alert.exec_()
print(message)
# alert = QMessageBox()
self.alert.setText(message)
self.alert.setIcon(QMessageBox.Warning)
self.alert.exec_()

# Start the telemetry system for the selected spacecraft
def startTlmSystem(self):
selectedSpacecraft = self.getSelectedSpacecraftName()

# Setup the subscription (to let know the telemetry system the messages it will be receiving)
# Setup the subscription (to let know the
# telemetry system the messages it will be receiving)
if selectedSpacecraft == 'All':
subscription = '--sub=GroundSystem'
else:
subscription = '--sub=GroundSystem.' + selectedSpacecraft + '.TelemetryPackets'
subscription = f'--sub=GroundSystem.{selectedSpacecraft}.TelemetryPackets'

# Open Telemetry System
system_call = '( cd Subsystems/tlmGUI/ && python3 TelemetrySystem.py ' + subscription + ' ) & '
os.system(system_call)
system_call = f'python3 {ROOTDIR}/Subsystems/tlmGUI/TelemetrySystem.py {subscription}'
args = shlex.split(system_call)
subprocess.Popen(args)

# Start command system
def startCmdSystem(self):
os.system('( cd Subsystems/cmdGui/ && python3 CommandSystem.py ) & ')
@staticmethod
def startCmdSystem():
subprocess.Popen(
['python3', f'{ROOTDIR}/Subsystems/cmdGui/CommandSystem.py'])

# Start FDL-FUL gui system
#def startFDLSystem(self):
Expand All @@ -108,21 +117,22 @@ def startCmdSystem(self):
def updateIpList(self, ip, name):
self.ipAddressesList.append(ip)
self.spacecraftNames.append(name)
self.ui.comboBoxIpAddresses.addItem(ip)
self.comboBoxIpAddresses.addItem(ip)

# Start the routing service (see RoutingService.py)
def initRoutingService(self):
self.RoutingService = RoutingService(self)
self.connect(self.RoutingService, self.RoutingService.signalUpdateIpList, self.updateIpList)
self.RoutingService = RoutingService()
self.RoutingService.signalUpdateIpList.connect(self.updateIpList)
self.RoutingService.start()


#
# Main
#
if __name__ == "__main__":

# Init app
app = QtGui.QApplication(sys.argv)
app = QApplication(sys.argv)

# Init main window
MainWindow = GroundSystem()
Expand All @@ -136,4 +146,3 @@ def initRoutingService(self):

# Execute the app
sys.exit(app.exec_())

10 changes: 5 additions & 5 deletions Guide-GroundSystem.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ Future enhancements:


Before launching the Ground System make sure that:
-> PyQt4 is installed.
-> PyQt5 is installed.
-> PyZMQ is installed.
-> cmdUtil is compiled.


Installing and running cFS Ground System on Ubuntu:
$ sudo apt-get install python3-pyqt4
$ sudo apt-get install python3-pyqt5
$ sudo apt-get install python3-zmq
$ sudo apt-get install libcanberra-gtk-module
$ ( cd Subsystems/cmdUtil/ && make )
$ python3 GroundSystem.py


The historically included instructions for running on Mac or CentOS are inluded at the bottom of this document for referance.
The historically included instructions for running on Mac or CentOS are inluded at the bottom of this document for reference.
Please note that instructions have not been maintained.
Welcoming instruction contributions if any of these are your platform of choice.

Expand Down Expand Up @@ -160,8 +160,8 @@ Installing and running cFS Ground System on CentOS 6:
$ ldconfig
$ pip install pyzmq

#### Install pyQT4 ####
$ yum install -y PyQt4
#### Install pyQT5 ####
$ yum install -y PyQt5
$ yum install -y qt qt-demos qt-designer qt4 qt4-designer


Expand Down
131 changes: 54 additions & 77 deletions MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,144 +1,121 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'MainWindow.ui'
# Form implementation generated from reading ui file '/home/lbleier/cFS/tools/cFS-GroundSystem/MainWindow.ui'
#
# Created: Wed Jun 24 09:56:47 2015
# by: PyQt4 UI code generator 4.11.3
# Created by: PyQt5 UI code generator 5.12.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
from PyQt5 import QtCore, QtGui, QtWidgets

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(420, 217)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(24)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.labelHomeTittle = QtGui.QLabel(self.centralwidget)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.labelHomeTittle = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(22)
font.setBold(False)
font.setWeight(50)
self.labelHomeTittle.setFont(font)
self.labelHomeTittle.setAlignment(QtCore.Qt.AlignCenter)
self.labelHomeTittle.setObjectName(_fromUtf8("labelHomeTittle"))
self.labelHomeTittle.setObjectName("labelHomeTittle")
self.verticalLayout.addWidget(self.labelHomeTittle)
self.line_2 = QtGui.QFrame(self.centralwidget)
self.line_2.setFrameShape(QtGui.QFrame.HLine)
self.line_2.setFrameShadow(QtGui.QFrame.Sunken)
self.line_2.setObjectName(_fromUtf8("line_2"))
self.line_2 = QtWidgets.QFrame(self.centralwidget)
self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.verticalLayout.addWidget(self.line_2)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.label_3 = QtGui.QLabel(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
self.label_3 = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth())
self.label_3.setSizePolicy(sizePolicy)
self.label_3.setMinimumSize(QtCore.QSize(141, 0))
self.label_3.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_3.setObjectName("label_3")
self.horizontalLayout.addWidget(self.label_3)
self.comboBoxIpAddresses = QtGui.QComboBox(self.centralwidget)
self.comboBoxIpAddresses = QtWidgets.QComboBox(self.centralwidget)
self.comboBoxIpAddresses.setMinimumSize(QtCore.QSize(132, 0))
self.comboBoxIpAddresses.setMaximumSize(QtCore.QSize(132, 16777215))
self.comboBoxIpAddresses.setObjectName(_fromUtf8("comboBoxIpAddresses"))
self.comboBoxIpAddresses.addItem(_fromUtf8(""))
self.comboBoxIpAddresses.setObjectName("comboBoxIpAddresses")
self.comboBoxIpAddresses.addItem("")
self.horizontalLayout.addWidget(self.comboBoxIpAddresses)
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setSpacing(32)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.pushButtonStartTlm = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.pushButtonStartTlm = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButtonStartTlm.sizePolicy().hasHeightForWidth())
self.pushButtonStartTlm.setSizePolicy(sizePolicy)
self.pushButtonStartTlm.setObjectName(_fromUtf8("pushButtonStartTlm"))
self.pushButtonStartTlm.setObjectName("pushButtonStartTlm")
self.horizontalLayout_2.addWidget(self.pushButtonStartTlm)
self.pushButtonStartCmd = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.pushButtonStartCmd = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButtonStartCmd.sizePolicy().hasHeightForWidth())
self.pushButtonStartCmd.setSizePolicy(sizePolicy)
self.pushButtonStartCmd.setObjectName(_fromUtf8("pushButtonStartCmd"))
self.pushButtonStartCmd.setObjectName("pushButtonStartCmd")
self.horizontalLayout_2.addWidget(self.pushButtonStartCmd)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.line = QtGui.QFrame(self.centralwidget)
self.line.setFrameShape(QtGui.QFrame.HLine)
self.line.setFrameShadow(QtGui.QFrame.Sunken)
self.line.setObjectName(_fromUtf8("line"))
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.verticalLayout.addWidget(self.line)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.label_5 = QtGui.QLabel(self.centralwidget)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(11)
self.label_5.setFont(font)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.label_5.setObjectName("label_5")
self.horizontalLayout_4.addWidget(self.label_5)
self.pushButton = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton.setObjectName("pushButton")
self.horizontalLayout_4.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout_4)
MainWindow.setCentralWidget(self.centralwidget)

self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.close)
self.pushButton.clicked.connect(MainWindow.close)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "Main Window", None))
self.labelHomeTittle.setText(_translate("MainWindow", "cFS Ground System", None))
self.label_3.setText(_translate("MainWindow", "Selected IP Address: ", None))
self.comboBoxIpAddresses.setItemText(0, _translate("MainWindow", "All", None))
self.pushButtonStartTlm.setText(_translate("MainWindow", "Start Telemetry System", None))
self.pushButtonStartCmd.setText(_translate("MainWindow", "Start Command System", None))
self.label_5.setText(_translate("MainWindow", "*Read Guide-GroundSystem.txt for help", None))
self.pushButton.setText(_translate("MainWindow", "Close", None))


if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
self.labelHomeTittle.setText(_translate("MainWindow", "CFS Ground System"))
self.label_3.setText(_translate("MainWindow", "Selected IP Address: "))
self.comboBoxIpAddresses.setItemText(0, _translate("MainWindow", "All"))
self.pushButtonStartTlm.setText(_translate("MainWindow", "Start Telemetry System"))
self.pushButtonStartCmd.setText(_translate("MainWindow", "Start Command System"))
self.label_5.setText(_translate("MainWindow", "*Read Guide-GroundSystem.txt for help"))
self.pushButton.setText(_translate("MainWindow", "Close"))
Loading

0 comments on commit 9555ec8

Please sign in to comment.