From 6af0617c2a303745e02347f899a1be82f49c98bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Fri, 2 Jul 2021 15:18:35 +0200 Subject: [PATCH] Upgrading client for MAC multi open compatibility --- client-py3/full/src/UDSClient.py | 26 ++-- client-py3/full/src/UDSClientLauncher.py | 47 ++++++++ client-py3/full/src/UDSLauncherMac.py | 78 ++++++++++++ client-py3/full/src/UDSLauncherMac.ui | 144 +++++++++++++++++++++++ client-py3/full/src/UDSResources_rc.py | 2 +- client-py3/full/src/UDSWindow.py | 5 +- 6 files changed, 286 insertions(+), 16 deletions(-) create mode 100644 client-py3/full/src/UDSClientLauncher.py create mode 100644 client-py3/full/src/UDSLauncherMac.py create mode 100644 client-py3/full/src/UDSLauncherMac.ui diff --git a/client-py3/full/src/UDSClient.py b/client-py3/full/src/UDSClient.py index 816a6f61..9a7f56d2 100755 --- a/client-py3/full/src/UDSClient.py +++ b/client-py3/full/src/UDSClient.py @@ -44,10 +44,10 @@ from PyQt5.QtCore import QSettings from uds.rest import RestApi, RetryException, InvalidVersion, UDSException # Just to ensure there are available on runtime -from uds.forward import forward # type: ignore -from uds.tunnel import forward as f2 # type: ignore +from uds.forward import forward as ssh_forward # type: ignore +from uds.tunnel import forward as tunnel_forwards # type: ignore -from uds.log import logger, DEBUG +from uds.log import logger from uds import tools from uds import VERSION @@ -176,8 +176,6 @@ class UDSClient(QtWidgets.QMainWindow): # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: - if DEBUG: - logger.exception('Got exception on getTransportData') self.showError(e) def start(self): @@ -316,12 +314,11 @@ def minimal(api: RestApi, ticket: str, scrambler: str): return 0 -if __name__ == "__main__": +def main(args: typing.List[str]): + app = QtWidgets.QApplication(sys.argv) logger.debug('Initializing connector for %s(%s)', sys.platform, platform.machine()) - # Initialize app - app = QtWidgets.QApplication(sys.argv) - + logger.debug('Arguments: %s', args) # Set several info for settings QtCore.QCoreApplication.setOrganizationName('Virtual Cable S.L.U.') QtCore.QCoreApplication.setApplicationName('UDS Connector') @@ -343,11 +340,11 @@ if __name__ == "__main__": # First parameter must be url useMinimal = False try: - uri = sys.argv[1] + uri = args[1] if uri == '--minimal': useMinimal = True - uri = sys.argv[2] # And get URI + uri = args[2] # And get URI if uri == '--test': sys.exit(0) @@ -362,8 +359,8 @@ if __name__ == "__main__": 'ssl:%s, host:%s, ticket:%s, scrambler:%s', ssl, host, - UDSClient.ticket, - UDSClient.scrambler, + ticket, + scrambler, ) except Exception: logger.debug('Detected execution without valid URI, exiting') @@ -404,3 +401,6 @@ if __name__ == "__main__": logger.debug('Exiting') sys.exit(exitVal) + +if __name__ == "__main__": + main(sys.argv) diff --git a/client-py3/full/src/UDSClientLauncher.py b/client-py3/full/src/UDSClientLauncher.py new file mode 100644 index 00000000..f2898d52 --- /dev/null +++ b/client-py3/full/src/UDSClientLauncher.py @@ -0,0 +1,47 @@ +import sys +import os.path +import subprocess +import typing + +from uds.log import logger +import UDSClient +from UDSLauncherMac import Ui_MacLauncher + +from PyQt5 import QtCore, QtWidgets, QtGui + +SCRIPT_NAME = 'UDSClientLauncher' + +class UdsApplication(QtWidgets.QApplication): + path: str + def __init__(self, argv: typing.List[str]) -> None: + super().__init__(argv) + self.path = os.path.join(os.path.dirname(sys.argv[0]).replace('Resources', 'MacOS'), SCRIPT_NAME) + + def event(self, evnt: QtCore.QEvent) -> bool: + logger.debug('Got event %s -> %s', evnt, evnt.type()) + + if evnt.type() == QtCore.QEvent.FileOpen: + fe = typing.cast(QtGui.QFileOpenEvent, evnt) + logger.debug('Got url: %s', fe.url().url()) + fe.accept() + logger.debug('Spawning %s', self.path) + subprocess.Popen([self.path, fe.url().url()]) + + return super().event(evnt) + + +def main(args: typing.List[str]): + if len(args) > 1: + UDSClient.main(args) + else: + app = UdsApplication(sys.argv) + window = QtWidgets.QMainWindow() + Ui_MacLauncher().setupUi(window) + + window.showMinimized() + + sys.exit(app.exec_()) + +if __name__ == "__main__": + main(args=sys.argv) + diff --git a/client-py3/full/src/UDSLauncherMac.py b/client-py3/full/src/UDSLauncherMac.py new file mode 100644 index 00000000..72719984 --- /dev/null +++ b/client-py3/full/src/UDSLauncherMac.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'UDSLauncherMac.ui' +# +# Created by: PyQt5 UI code generator 5.15.2 +# +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. + + +from PyQt5 import QtCore, QtGui, QtWidgets + + +class Ui_MacLauncher(object): + def setupUi(self, MacLauncher): + MacLauncher.setObjectName("MacLauncher") + MacLauncher.setWindowModality(QtCore.Qt.NonModal) + MacLauncher.resize(256, 150) + MacLauncher.setCursor(QtGui.QCursor(QtCore.Qt.BusyCursor)) + icon = QtGui.QIcon() + icon.addPixmap(QtGui.QPixmap(":/images/logo-uds-small"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + MacLauncher.setWindowIcon(icon) + MacLauncher.setWindowOpacity(1.0) + self.centralwidget = QtWidgets.QWidget(MacLauncher) + self.centralwidget.setAutoFillBackground(True) + self.centralwidget.setObjectName("centralwidget") + self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) + self.verticalLayout_2.setContentsMargins(4, 4, 4, 4) + self.verticalLayout_2.setSpacing(4) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.frame = QtWidgets.QFrame(self.centralwidget) + self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel) + self.frame.setFrameShadow(QtWidgets.QFrame.Raised) + self.frame.setObjectName("frame") + self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame) + self.verticalLayout_3.setContentsMargins(4, 4, 4, 4) + self.verticalLayout_3.setSpacing(4) + self.verticalLayout_3.setObjectName("verticalLayout_3") + self.verticalLayout = QtWidgets.QVBoxLayout() + self.verticalLayout.setObjectName("verticalLayout") + self.image = QtWidgets.QLabel(self.frame) + self.image.setMinimumSize(QtCore.QSize(0, 24)) + self.image.setAutoFillBackground(True) + self.image.setText("") + self.image.setPixmap(QtGui.QPixmap(":/images/logo-uds-small")) + self.image.setScaledContents(False) + self.image.setAlignment(QtCore.Qt.AlignCenter) + self.image.setObjectName("image") + self.verticalLayout.addWidget(self.image) + self.info = QtWidgets.QLabel(self.frame) + self.info.setMaximumSize(QtCore.QSize(16777215, 16)) + self.info.setAlignment(QtCore.Qt.AlignCenter) + self.info.setObjectName("info") + self.verticalLayout.addWidget(self.info) + spacerItem = QtWidgets.QSpacerItem(20, 30, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) + self.verticalLayout.addItem(spacerItem) + self.verticalLayout_3.addLayout(self.verticalLayout) + self.verticalLayout_2.addWidget(self.frame) + MacLauncher.setCentralWidget(self.centralwidget) + + self.retranslateUi(MacLauncher) + QtCore.QMetaObject.connectSlotsByName(MacLauncher) + + def retranslateUi(self, MacLauncher): + _translate = QtCore.QCoreApplication.translate + MacLauncher.setWindowTitle(_translate("MacLauncher", "UDS Launcher")) + self.info.setText(_translate("MacLauncher", "UDS Launcher")) +import UDSResources_rc + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + MacLauncher = QtWidgets.QMainWindow() + ui = Ui_MacLauncher() + ui.setupUi(MacLauncher) + MacLauncher.show() + sys.exit(app.exec_()) diff --git a/client-py3/full/src/UDSLauncherMac.ui b/client-py3/full/src/UDSLauncherMac.ui new file mode 100644 index 00000000..959dc16b --- /dev/null +++ b/client-py3/full/src/UDSLauncherMac.ui @@ -0,0 +1,144 @@ + + + MacLauncher + + + Qt::NonModal + + + + 0 + 0 + 256 + 150 + + + + BusyCursor + + + UDS Launcher + + + + :/images/logo-uds-small:/images/logo-uds-small + + + 1.000000000000000 + + + + true + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + + 0 + 24 + + + + true + + + + + + :/images/logo-uds-small + + + false + + + Qt::AlignCenter + + + + + + + + 16777215 + 16 + + + + UDS Launcher + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 30 + + + + + + + + + + + + + + + + + diff --git a/client-py3/full/src/UDSResources_rc.py b/client-py3/full/src/UDSResources_rc.py index ec4a412d..b8f61601 100644 --- a/client-py3/full/src/UDSResources_rc.py +++ b/client-py3/full/src/UDSResources_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created by: The Resource Compiler for PyQt5 (Qt v5.13.2) +# Created by: The Resource Compiler for PyQt5 (Qt v5.15.2) # # WARNING! All changes made in this file will be lost! diff --git a/client-py3/full/src/UDSWindow.py b/client-py3/full/src/UDSWindow.py index 44d46b1a..c6704072 100644 --- a/client-py3/full/src/UDSWindow.py +++ b/client-py3/full/src/UDSWindow.py @@ -2,9 +2,10 @@ # Form implementation generated from reading ui file 'UDSWindow.ui' # -# Created by: PyQt5 UI code generator 5.13.2 +# Created by: PyQt5 UI code generator 5.15.2 # -# WARNING! All changes made in this file will be lost! +# WARNING: Any manual changes made to this file will be lost when pyuic5 is +# run again. Do not edit this file unless you know what you are doing. from PyQt5 import QtCore, QtGui, QtWidgets