forked from SvenBo90/Py2DSpectroscopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPy2DSpectroscopy.py
147 lines (109 loc) · 5.35 KB
/
Py2DSpectroscopy.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# general imports
import sys
import threading
import time
# import PyQt5 elements
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QApplication
# import map classes
from maps import MapList
# import window classes
from aboutWindow import AboutWindow
from backgroundWindow import BackgroundWindow
from fittingWindow import FittingWindow
from mapWindow import MapWindow
from pixelInformationWindow import PixelInformationWindow
from spectrumWindow import SpectrumWindow
class StoppableThread(threading.Thread):
def __init__(self, name, target):
super(StoppableThread, self).__init__(name=name, target=target)
self._stop_event = threading.Event()
def stop(self):
self._stop_event.set()
def stopped(self):
return self._stop_event.is_set()
class Py2DSpectroscopy(QApplication):
"""
Py2DSpectroscopy
This is the main class of the application. It controls the different windows
and saves the maps in a map list.
"""
# define list signals
map_added = pyqtSignal(int) # int: map id
map_removed = pyqtSignal(int) # int: map id
selected_map_changed = pyqtSignal(int) # int: map id
# define map signals
fit_changed = pyqtSignal(int) # int: map id
focus_changed = pyqtSignal(int) # int: map id
geometry_changed = pyqtSignal(int) # int: map id
interval_changed = pyqtSignal(int) # int: map id
selected_data_changed = pyqtSignal(int) # int: map id
spectrum_changed = pyqtSignal(int) # int: map id
def __init__(self):
# call super init
super().__init__(sys.argv)
# connect exit method
self.aboutToQuit.connect(self.exit_app)
# list for all loaded maps
self.maps = MapList()
# dictionary for all windows
self.windows = {
"aboutWindow": AboutWindow(),
"backgroundWindow": BackgroundWindow(),
"fittingWindow": FittingWindow(),
"mapWindow": MapWindow(),
"pixelInformationWindow": PixelInformationWindow(),
"spectrumWindow": SpectrumWindow()
}
# thread for live plotting
self._live_plotting_thread = None
# connect to map list signals
self.map_added.connect(self.windows['backgroundWindow'].add_widget)
self.map_added.connect(self.windows['fittingWindow'].add_widget)
self.map_added.connect(self.windows['pixelInformationWindow'].add_widget)
self.map_added.connect(self.windows['spectrumWindow'].add_widget)
self.map_removed.connect(self.windows['backgroundWindow'].remove_widget)
self.map_removed.connect(self.windows['fittingWindow'].remove_widget)
self.map_removed.connect(self.windows['pixelInformationWindow'].remove_widget)
self.map_removed.connect(self.windows['spectrumWindow'].remove_widget)
self.selected_map_changed.connect(self.windows['backgroundWindow'].change_widget)
self.selected_map_changed.connect(self.windows['fittingWindow'].change_widget)
self.selected_map_changed.connect(self.windows['pixelInformationWindow'].change_widget)
self.selected_map_changed.connect(self.windows['spectrumWindow'].change_widget)
# connect to map signals
self.fit_changed.connect(self.windows['mapWindow'].update_data)
self.fit_changed.connect(self.windows['mapWindow'].update_data_selection_combo_box)
self.fit_changed.connect(self.windows['pixelInformationWindow'].update_data)
self.fit_changed.connect(self.windows['spectrumWindow'].update_data)
self.focus_changed.connect(self.windows['mapWindow'].update_crosshair)
self.focus_changed.connect(self.windows['pixelInformationWindow'].update_data)
self.focus_changed.connect(self.windows['spectrumWindow'].update_data)
self.geometry_changed.connect(self.windows['mapWindow'].update_data)
self.geometry_changed.connect(self.windows['mapWindow'].update_crosshair)
self.interval_changed.connect(self.windows['mapWindow'].update_data)
self.interval_changed.connect(self.windows['pixelInformationWindow'].update_data)
self.interval_changed.connect(self.windows['spectrumWindow'].update_data)
self.selected_data_changed.connect(self.windows['mapWindow'].update_data)
self.spectrum_changed.connect(self.windows['mapWindow'].update_data)
self.spectrum_changed.connect(self.windows['pixelInformationWindow'].update_data)
self.spectrum_changed.connect(self.windows['spectrumWindow'].update_data)
# show the map window
self.windows['mapWindow'].show()
def live_plotting(self):
while not threading.current_thread().stopped():
time.sleep(0.5)
self.windows['mapWindow'].update_data(self.maps.get_selected_map().get_id())
self.windows['mapWindow'].update_data(self.maps.get_selected_map().get_id())
def start_live_plotting(self):
self._live_plotting_thread = StoppableThread(name='live_plotting', target=self.live_plotting)
self._live_plotting_thread.start()
def stop_live_plotting(self):
self._live_plotting_thread.stop()
@staticmethod
def exit_app():
print('Thanks for using me!')
if __name__ == "__main__":
# create app
app = Py2DSpectroscopy()
# execute app and close system afterwards
sys.exit(app.exec_())