-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
104 lines (77 loc) · 3.99 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
97
98
99
100
101
102
103
104
import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import pyqtSignal
from pyFormGen.units import convert
from pyFileIO import fileIO
from lib.sensorProfileManager import SensorProfileManager
from lib.preferencesManager import PreferencesManager
from lib.logger import logger
from lib.fileTypes import FILE_TYPES
from lib.migrations import *
from ui.mainWindow import MainWindow
class App(QApplication):
NAME = 'RMTS'
VERSION = (0, 3, 2)
newConverter = pyqtSignal(object)
newFiringConfig = pyqtSignal(object)
def __init__(self, args):
super().__init__(args)
self.setupFileIO()
self.sensorProfileManager = SensorProfileManager()
self.sensorProfileManager.loadProfiles()
self.preferencesManager = PreferencesManager()
self.preferencesManager.loadPreferences()
logger.log('Application version: {}.{}.{}'.format(*self.VERSION))
self.window = MainWindow(self)
logger.log('Showing window')
self.window.show()
def outputMessage(self, content, title='RMTS'):
msg = QMessageBox()
msg.setText(content)
msg.setWindowTitle(title)
msg.exec_()
def outputException(self, exception, text, title='RMTS - Error'):
msg = QMessageBox()
msg.setText(text)
msg.setInformativeText(str(exception))
msg.setWindowTitle(title)
msg.exec_()
def convertToUserUnits(self, value, units):
return self.preferencesManager.preferences.convert(value, units)
def convertFromUserUnits(self, value, baseUnit):
inUnit = self.preferencesManager.preferences.getUnit(baseUnit)
return convert(value, inUnit, baseUnit)
def convertAllToUserUnits(self, values, units):
return self.preferencesManager.preferences.convertAll(values, units)
def convertToUserAndFormat(self, value, units, places):
return self.preferencesManager.preferences.convFormat(value, units, places)
def getUserUnit(self, unit):
return self.preferencesManager.preferences.getUnit(unit)
def getPreferences(self):
return self.preferencesManager.preferences
def newResult(self, motorInfo, fileName = None):
self.window.ui.pageResults.showResults(motorInfo, fileName)
def configureLiveResults(self, size):
self.window.ui.pageResults.setupLive(size)
# No packet argument because this is just for resetting data age
def newResultsPacket(self):
self.window.ui.pageResults.newResultsPacket()
def newCalibration(self, calibration):
self.window.ui.pageCalibration.newCalibration(calibration)
def setupFileIO(self):
fileIO.setAppInfo(self.NAME, self.VERSION)
fileIO.registerFileType(FILE_TYPES.PREFERENCES)
fileIO.registerFileType(FILE_TYPES.TRANSDUCERS)
fileIO.registerFileType(FILE_TYPES.FIRING)
fileIO.registerMigration(FILE_TYPES.PREFERENCES, (0, 1, 0), (0, 2, 0), lambda data: data)
fileIO.registerMigration(FILE_TYPES.TRANSDUCERS, (0, 1, 0), (0, 2, 0), lambda data: data)
fileIO.registerMigration(FILE_TYPES.FIRING, (0, 1, 0), (0, 2, 0), migrateFiring_0_1_0_to_0_2_0)
fileIO.registerMigration(FILE_TYPES.PREFERENCES, (0, 2, 0), (0, 3, 0), lambda data: data)
fileIO.registerMigration(FILE_TYPES.TRANSDUCERS, (0, 2, 0), (0, 3, 0), lambda data: data)
fileIO.registerMigration(FILE_TYPES.FIRING, (0, 2, 0), (0, 3, 0), lambda data: data)
fileIO.registerMigration(FILE_TYPES.PREFERENCES, (0, 3, 0), (0, 3, 1), lambda data: data)
fileIO.registerMigration(FILE_TYPES.TRANSDUCERS, (0, 3, 0), (0, 3, 1), lambda data: data)
fileIO.registerMigration(FILE_TYPES.FIRING, (0, 3, 0), (0, 3, 1), lambda data: data)
fileIO.registerMigration(FILE_TYPES.PREFERENCES, (0, 3, 1), (0, 3, 2), lambda data: data)
fileIO.registerMigration(FILE_TYPES.TRANSDUCERS, (0, 3, 1), (0, 3, 2), lambda data: data)
fileIO.registerMigration(FILE_TYPES.FIRING, (0, 3, 1), (0, 3, 2), lambda data: data)