tpds-application 2.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tpds/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
@@ -0,0 +1,102 @@
1
+ import os
2
+ import sys
3
+ import subprocess
4
+
5
+ from PySide2.QtCore import QDir, QLockFile
6
+ from PySide2.QtWidgets import QApplication
7
+ from PySide2.QtWidgets import QMessageBox
8
+ from PySide2.QtGui import QIcon
9
+
10
+ from tpds.settings import TrustPlatformSettings
11
+ from .pyside_check import pyside2_check
12
+ from .app import TPDSApplication
13
+ from .control import shutdown
14
+
15
+ def handle_env_check():
16
+ if sys.platform == 'darwin':
17
+ apple_script = """display dialog "Environmental variables are not set correctly or updated. \nTry reinstalling the application" with title "Environment Checks" with icon caution buttons {"OK"}"""
18
+ subprocess.call(['osascript', '-e', apple_script])
19
+ sys.exit()
20
+ else:
21
+ print((
22
+ 'Environmental variables are not set correctly or updated.'
23
+ '\nTry reinstalling the application'))
24
+ sys.exit()
25
+
26
+
27
+ """
28
+ # Get requirements file path
29
+ if os.getenv('CONDA_PREFIX') not in os.path.abspath(__file__):
30
+ handle_env_check()
31
+ """
32
+
33
+
34
+ def run_app():
35
+ print("This prompt runs Trust Platform GUI, Do NOT close this window.")
36
+
37
+ # Configuration system
38
+ # A default configuraiton is built here.
39
+ # Upon start, the user is prompted with a Settings window to override
40
+ # and complete the data set.
41
+ # it is then saved into $HOME/.trustplatform/TPDS_config.json
42
+ config = TrustPlatformSettings()
43
+
44
+ if os.getenv('CONDA_PREFIX') is not None:
45
+ # Find and add conda path
46
+ config.settings.conda_path = os.getenv('CONDA_PREFIX')
47
+ # Find and add tpds_core path
48
+ # config.settings.local_path = os.path.join(os.getenv(
49
+ # 'CONDA_PREFIX'), 'tpds_core')
50
+ # Define a default log file if there is none
51
+ config.settings.log_file = os.path.join(
52
+ QDir.homePath(),
53
+ '.trustplatform',
54
+ 'trustplatform.log')
55
+ # Write the above default configuration locally
56
+ config.save()
57
+
58
+ # Mainl
59
+ if os.environ.get('XDG_SESSION_TYPE') == 'wayland':
60
+ # This silences the warning locally in ubuntu and seems to resolve some issues
61
+ os.environ['XDG_SESSION_TYPE'] = 'xcb'
62
+ # This uses the qtwayland5 wayland extension which improve performance in wayland based
63
+ # environments - it still throws the warning however
64
+ # os.environ['QT_QPA_PLATFORM'] = 'wayland'
65
+
66
+ if sys.platform == 'darwin':
67
+ os.environ['QT_MAC_WANTS_LAYER'] = '1'
68
+
69
+ # Clean up old instances if they exist
70
+ if QApplication.instance():
71
+ shutdown()
72
+
73
+ # Start the Qt application
74
+ _app = TPDSApplication()
75
+ sys.exit(_app.exec_())
76
+
77
+ def tpds_app_launch():
78
+ try:
79
+ lock_file = QLockFile(QDir.tempPath() + '/tpds.lock')
80
+ if lock_file.tryLock():
81
+ pyside2_check()
82
+ run_app()
83
+ else:
84
+ exit_app = QApplication(sys.argv)
85
+ config = TrustPlatformSettings()
86
+ # Add application icon
87
+ icon_path = os.path.join(os.path_dirname(__file__), 'assets', 'app.ico')
88
+ exit_app.setWindowIcon(QIcon(icon_path))
89
+ error_message = QMessageBox()
90
+ error_message.setIcon(QMessageBox.Information)
91
+ error_message.setWindowTitle('Duplicate')
92
+ error_message.setText((
93
+ '''<font color=#0000ff><b>Application is already running</b></font><br>
94
+ <br>Only one instance is allowed. Click OK to close this<br>'''))
95
+ error_message.setStandardButtons(QMessageBox.Ok)
96
+ error_message.exec()
97
+ finally:
98
+ lock_file.unlock()
99
+
100
+
101
+ if __name__ == '__main__':
102
+ tpds_app_launch()
tpds/app/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .main import MainWindow
2
+ from .docks import LoggerDock
3
+ from .tools import WebViewStacked
tpds/app/app.py ADDED
@@ -0,0 +1,135 @@
1
+ import os
2
+ import sys
3
+ import time
4
+
5
+ from PySide2.QtCore import QUrl, QObject, Signal
6
+ from PySide2.QtCore import QThreadPool
7
+ from PySide2.QtWidgets import QApplication, QMessageBox
8
+ from PySide2.QtGui import QIcon
9
+
10
+
11
+ from tpds.settings.tpds_settings import TrustPlatformSettings
12
+ from tpds.launcher import TpdsBackend
13
+ from tpds.helper import LogFacility
14
+ from tpds.update import CheckUpdates
15
+ from .network import NetworkTools
16
+ from .main import MainWindow
17
+ from .vars import set_app_ref, dict_pckg
18
+
19
+
20
+ class GUILogger(QObject):
21
+ def __init__(self, parent):
22
+ super(GUILogger, self).__init__(parent)
23
+
24
+ log_signal = Signal(str)
25
+
26
+
27
+ class TPDSApplication(QApplication):
28
+ """TPDSApplication Trust Platform Design Suite Application Object
29
+
30
+ PySide2 QApplication Object
31
+
32
+ """
33
+ def __init__(self, app_config=None):
34
+ """__init__ Initializes TPDSApplication Object
35
+
36
+ Inherits from QApplication and implement the main Qt GUI
37
+ Starts a logging facility (either in file or in the GUI) then starts
38
+ a Jupyter Notebook server in a separate process and create an
39
+ autobahn python based websocket server in a separate thread to
40
+ handle Javascript Remote procedure calls (RPC).
41
+
42
+ RPCs go through a business logic filter documented in the websocket
43
+ server module.
44
+
45
+ Args:
46
+ app_config: application settings
47
+ """
48
+ super(TPDSApplication, self).__init__([''])
49
+ self._config = TrustPlatformSettings(values=app_config)
50
+ set_app_ref(self)
51
+ # QApplication settings
52
+ self.setApplicationName("TrustPlatformDesignSuite")
53
+ self.setApplicationDisplayName("Trust Platform Design Suite")
54
+ self.setOrganizationDomain("microchip.com")
55
+ self._view = None
56
+ global _core_thread
57
+ _core_thread = QThreadPool()
58
+
59
+ """ Setup logging
60
+ if log_window is False log into
61
+ $HOME/.trustplatform/trustplatform.log
62
+ Log at DEBUG level all messages if log_level_debug is True
63
+ """
64
+ self._logfile = os.path.join(self._config.settings.home_path, 'trustplatform.log')
65
+ if self._config.settings.debug is True:
66
+ self._log = LogFacility(
67
+ logfile=self._config.settings.log_file,
68
+ logstream=self._config.settings.log_window)
69
+ self._log.log('Logging started')
70
+
71
+ # Add application icon
72
+ if os.path.isabs(self._config.settings.icon):
73
+ icon_path = self._config.settings.icon
74
+ else:
75
+ icon_path = os.path.join(os.path.dirname(__file__),
76
+ self._config.settings.icon)
77
+ self.setWindowIcon(QIcon(icon_path))
78
+ self._log.log('App icon:' + icon_path)
79
+
80
+ # Start GUI
81
+ self.start_gui()
82
+
83
+ # Check for updates if internet is availables
84
+ self.network = NetworkTools()
85
+ self.network.network_check_thread(self.check_for_updates)
86
+
87
+ # Launch the backend servers
88
+ self.backend = TpdsBackend()
89
+ self.backend.start()
90
+
91
+ while not self.backend.is_ready():
92
+ time.sleep(1)
93
+
94
+ # Load main tool page
95
+ self.load_start_up_page()
96
+ self._log.log("Qt event loop running")
97
+
98
+ def check_for_updates(self, network_connected):
99
+ status = 'available' if network_connected else 'unavailable'
100
+ self._log.log(f'Network check is completed...it is {status}.')
101
+ if network_connected:
102
+ if self._config.settings.update_on_startup:
103
+ CheckUpdates()
104
+ else:
105
+ nw_message = QMessageBox()
106
+ nw_message.setIcon(QMessageBox.Warning)
107
+ nw_message.setWindowTitle('Network')
108
+ nw_message.setText((
109
+ '''<font color=#0000ff><b>Internet connection is down</b></font><br>'''
110
+ '''<br>Check connection and try again. Without internet connection,'''
111
+ '''few links and functionality will not work.<br>'''
112
+ '''<br>Connect to internet for improved User experience.<br>'''))
113
+ nw_message.setStandardButtons(QMessageBox.Ok)
114
+ nw_message.exec()
115
+
116
+ def start_gui(self):
117
+ self._view = MainWindow(
118
+ None,
119
+ '',
120
+ log_view=self._config.settings.log_window)
121
+ self._view.setWindowTitle(
122
+ "Trust Platform Design Suite")
123
+ if self._config.settings.log_window is True:
124
+ qtlogger = GUILogger(self._view)
125
+ qtlogger.log_signal.connect(self._view.loggerdock.log)
126
+ self._log.set_logger(
127
+ lambda message: qtlogger.log_signal.emit(message))
128
+
129
+ def load_start_up_page(self):
130
+ port = self.backend.api_port()
131
+ self._log.log(f'Opening startup page from http://localhost:{port}/')
132
+ self._view.loadmain(QUrl(f'http://localhost:{port}/'))
133
+
134
+ def stop_backend(self):
135
+ self.backend.stop()
Binary file
Binary file
Binary file
Binary file
tpds/app/control.py ADDED
@@ -0,0 +1,37 @@
1
+
2
+ from PySide2.QtCore import Slot
3
+ from PySide2.QtWidgets import QMessageBox
4
+
5
+ from tpds.settings.tpds_settings import reset_runtime_settings
6
+ from .vars import get_app_ref
7
+ from tpds.helper import log
8
+
9
+
10
+ @Slot()
11
+ def shutdown(message: str = 'Do you want to exit?', force: bool = False):
12
+ app_ref = get_app_ref()
13
+ if app_ref._view is not None:
14
+ if force:
15
+ reply = QMessageBox.critical(
16
+ app_ref._view,
17
+ 'Exit',
18
+ message,
19
+ QMessageBox.Ok,
20
+ QMessageBox.Ok
21
+ )
22
+ else:
23
+ reply = QMessageBox.question(
24
+ app_ref._view,
25
+ 'Exit',
26
+ message,
27
+ QMessageBox.Yes | QMessageBox.No,
28
+ QMessageBox.No)
29
+
30
+ if reply in (QMessageBox.Yes, QMessageBox.Ok):
31
+ log('shutdown')
32
+ reset_runtime_settings()
33
+ app_ref.stop_backend()
34
+ log('quitting')
35
+ app_ref.quit()
36
+ else:
37
+ return False
tpds/app/docks.py ADDED
@@ -0,0 +1,15 @@
1
+ from PySide2.QtWidgets import QDockWidget, QPlainTextEdit
2
+ from PySide2.QtCore import Slot
3
+
4
+
5
+ class LoggerDock(QDockWidget):
6
+
7
+ def __init__(self, *args):
8
+ super(LoggerDock, self).__init__(*args)
9
+ self.textview = QPlainTextEdit(self)
10
+ self.textview.setReadOnly(True)
11
+ self.setWidget(self.textview)
12
+
13
+ @Slot()
14
+ def log(self, message):
15
+ self.textview.appendPlainText(message)