forked from reilleya/openMotor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
96 lines (81 loc) · 3.87 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtGui import QIcon
import motorlib
from motorlib import simResult
from uilib import preferencesManager, propellantManager, simulationManager, fileManager, toolManager
from uilib import importExportManager
import uilib.widgets.mainWindow
from uilib.logger import logger
class App(QApplication):
def __init__(self, args):
super().__init__(args)
self.icon = QIcon('resources/oMIconCyclesSmall.png')
self.headless = '-h' in args
self.preferencesManager = uilib.preferencesManager.PreferencesManager()
self.propellantManager = uilib.propellantManager.PropellantManager()
self.preferencesManager.preferencesChanged.connect(self.propellantManager.setPreferences)
self.simulationManager = uilib.simulationManager.SimulationManager()
self.preferencesManager.preferencesChanged.connect(self.simulationManager.setPreferences)
self.fileManager = uilib.fileManager.FileManager(self)
startupFileLoaded = False
if len(args) > 1 and args[-1][0] != '-':
startupFileLoaded = self.fileManager.load(args[-1])
self.propellantManager.updated.connect(self.fileManager.updatePropellant)
self.toolManager = uilib.toolManager.ToolManager(self)
self.preferencesManager.preferencesChanged.connect(self.toolManager.setPreferences)
self.importExportManager = uilib.importExportManager.ImportExportManager(self)
self.preferencesManager.preferencesChanged.connect(self.importExportManager.setPreferences)
self.simulationManager.newSimulationResult.connect(self.importExportManager.acceptSimRes)
self.fileManager.newMotor.connect(self.importExportManager.acceptNewMotor)
if self.headless:
if len(args) < 3:
print('Not enough arguments. Headless mode requires an input file.')
elif not startupFileLoaded:
print('Could not load motor file')
sys.exit(1)
else:
motor = self.fileManager.getCurrentMotor()
simulationResult = motor.runSimulation()
for alert in simulationResult.alerts:
print('{} ({}, {}): {}'.format(motorlib.simResult.alertLevelNames[alert.level],
motorlib.simResult.alertTypeNames[alert.type],
alert.location,
alert.description))
print()
if '-o' in args:
with open(args[args.index('-o') + 1], 'w') as outputFile:
outputFile.write(simulationResult.getCSV(self.preferencesManager.preferences))
else:
print(simulationResult.getCSV(self.preferencesManager.preferences))
sys.exit(0)
else:
logger.log('Opening window')
self.window = uilib.widgets.mainWindow.Window(self)
self.preferencesManager.publishPreferences()
if startupFileLoaded:
self.fileManager.sendTitleUpdate()
self.window.show()
logger.log('Window opened')
def outputMessage(self, content, title='openMotor'):
if self.headless:
print(content)
else:
logger.log(content)
msg = QMessageBox()
msg.setWindowIcon(self.icon)
msg.setText(content)
msg.setWindowTitle(title)
msg.exec_()
def outputException(self, exception, text, title='openMotor - Error'):
if self.headless:
print(text + " " + str(exception))
else:
logger.error(text)
logger.error(exception)
msg = QMessageBox()
msg.setWindowIcon(self.icon)
msg.setText(text)
msg.setInformativeText(str(exception))
msg.setWindowTitle(title)
msg.exec_()