etho-python 1.2.5__py3-none-any.whl → 1.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.
- etho/assets/etho_icon1_pipeline_dark.svg +23 -23
- etho/assets/etho_icon1_pipeline_light.svg +30 -30
- etho/res_app.py +225 -225
- etho/resumable.py +283 -283
- etho/services/DAQZeroService.py +2 -2
- etho/services/GOVZeroService.py +291 -291
- etho/services/__init__.py +52 -52
- etho/services/camera/spinnaker_old.py +312 -312
- etho/services/daq/IOTask.py +16 -9
- etho/services/resumable.py +476 -476
- etho/utils/calibration.py +88 -88
- etho/utils/runner.py +121 -121
- {etho_python-1.2.5.dist-info → etho_python-1.2.6.dist-info}/METADATA +1 -1
- {etho_python-1.2.5.dist-info → etho_python-1.2.6.dist-info}/RECORD +17 -17
- {etho_python-1.2.5.dist-info → etho_python-1.2.6.dist-info}/licenses/LICENSE +21 -21
- {etho_python-1.2.5.dist-info → etho_python-1.2.6.dist-info}/WHEEL +0 -0
- {etho_python-1.2.5.dist-info → etho_python-1.2.6.dist-info}/entry_points.txt +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
|
2
|
-
<title>etho minimal pipeline glyph dark mode</title>
|
|
3
|
-
<g shape-rendering="geometricPrecision">
|
|
4
|
-
<rect x="28" y="52" width="44" height="32" rx="8" fill="#F3F5F7"/>
|
|
5
|
-
<rect x="34" y="58" width="12" height="8" rx="2" fill="#1F2430"/>
|
|
6
|
-
<rect x="104" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
7
|
-
<rect x="118" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
8
|
-
<rect x="132" y="38" width="8" height="60" rx="2" fill="#6FB64F"/>
|
|
9
|
-
<rect x="146" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
10
|
-
<rect x="160" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
11
|
-
<path d="M192 54L224 74L192 94Z" fill="#6FB64F"/>
|
|
12
|
-
<rect x="84" y="70" width="12" height="4" rx="2" fill="#F3F5F7"/>
|
|
13
|
-
<rect x="174" y="70" width="12" height="4" rx="2" fill="#F3F5F7"/>
|
|
14
|
-
<path d="M48 96V120C48 124.418 51.582 128 56 128H124M208 96V120C208 124.418 204.418 128 200 128H132" stroke="#F3F5F7" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
|
|
15
|
-
<path d="M128 112V160" stroke="#F3F5F7" stroke-width="8" stroke-linecap="round"/>
|
|
16
|
-
<circle cx="128" cy="128" r="6" fill="#F3F5F7"/>
|
|
17
|
-
<ellipse cx="128" cy="180" rx="36" ry="12" fill="#6FB64F"/>
|
|
18
|
-
<path d="M92 180V212C92 218.627 108.118 224 128 224C147.882 224 164 218.627 164 212V180" fill="#F3F5F7"/>
|
|
19
|
-
<path d="M92 196C92 202.627 108.118 208 128 208C147.882 208 164 202.627 164 196" stroke="#1F2430" stroke-width="4" stroke-linecap="round"/>
|
|
20
|
-
<circle cx="154" cy="198" r="3" fill="#1F2430"/>
|
|
21
|
-
<circle cx="154" cy="214" r="3" fill="#1F2430"/>
|
|
22
|
-
</g>
|
|
23
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
|
2
|
+
<title>etho minimal pipeline glyph dark mode</title>
|
|
3
|
+
<g shape-rendering="geometricPrecision">
|
|
4
|
+
<rect x="28" y="52" width="44" height="32" rx="8" fill="#F3F5F7"/>
|
|
5
|
+
<rect x="34" y="58" width="12" height="8" rx="2" fill="#1F2430"/>
|
|
6
|
+
<rect x="104" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
7
|
+
<rect x="118" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
8
|
+
<rect x="132" y="38" width="8" height="60" rx="2" fill="#6FB64F"/>
|
|
9
|
+
<rect x="146" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
10
|
+
<rect x="160" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
11
|
+
<path d="M192 54L224 74L192 94Z" fill="#6FB64F"/>
|
|
12
|
+
<rect x="84" y="70" width="12" height="4" rx="2" fill="#F3F5F7"/>
|
|
13
|
+
<rect x="174" y="70" width="12" height="4" rx="2" fill="#F3F5F7"/>
|
|
14
|
+
<path d="M48 96V120C48 124.418 51.582 128 56 128H124M208 96V120C208 124.418 204.418 128 200 128H132" stroke="#F3F5F7" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
|
|
15
|
+
<path d="M128 112V160" stroke="#F3F5F7" stroke-width="8" stroke-linecap="round"/>
|
|
16
|
+
<circle cx="128" cy="128" r="6" fill="#F3F5F7"/>
|
|
17
|
+
<ellipse cx="128" cy="180" rx="36" ry="12" fill="#6FB64F"/>
|
|
18
|
+
<path d="M92 180V212C92 218.627 108.118 224 128 224C147.882 224 164 218.627 164 212V180" fill="#F3F5F7"/>
|
|
19
|
+
<path d="M92 196C92 202.627 108.118 208 128 208C147.882 208 164 202.627 164 196" stroke="#1F2430" stroke-width="4" stroke-linecap="round"/>
|
|
20
|
+
<circle cx="154" cy="198" r="3" fill="#1F2430"/>
|
|
21
|
+
<circle cx="154" cy="214" r="3" fill="#1F2430"/>
|
|
22
|
+
</g>
|
|
23
|
+
</svg>
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
|
2
|
-
<title>etho minimal pipeline glyph</title>
|
|
3
|
-
<g shape-rendering="geometricPrecision">
|
|
4
|
-
<!-- camera -->
|
|
5
|
-
<rect x="28" y="52" width="44" height="32" rx="8" fill="#1F2430"/>
|
|
6
|
-
<rect x="34" y="58" width="12" height="8" rx="2" fill="#F3F5F7"/>
|
|
7
|
-
<!-- signal -->
|
|
8
|
-
<rect x="104" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
9
|
-
<rect x="118" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
10
|
-
<rect x="132" y="38" width="8" height="60" rx="2" fill="#6FB64F"/>
|
|
11
|
-
<rect x="146" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
12
|
-
<rect x="160" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
13
|
-
<!-- opto triangle -->
|
|
14
|
-
<path d="M192 54L224 74L192 94Z" fill="#6FB64F"/>
|
|
15
|
-
<!-- tiny separators -->
|
|
16
|
-
<rect x="84" y="70" width="12" height="4" rx="2" fill="#1F2430"/>
|
|
17
|
-
<rect x="174" y="70" width="12" height="4" rx="2" fill="#1F2430"/>
|
|
18
|
-
<!-- bus -->
|
|
19
|
-
<path d="M48 96V120C48 124.418 51.582 128 56 128H124M208 96V120C208 124.418 204.418 128 200 128H132" stroke="#1F2430" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
|
|
20
|
-
<path d="M128 112V160" stroke="#1F2430" stroke-width="8" stroke-linecap="round"/>
|
|
21
|
-
<!-- junction -->
|
|
22
|
-
<circle cx="128" cy="128" r="6" fill="#1F2430"/>
|
|
23
|
-
<!-- database -->
|
|
24
|
-
<ellipse cx="128" cy="180" rx="36" ry="12" fill="#6FB64F"/>
|
|
25
|
-
<path d="M92 180V212C92 218.627 108.118 224 128 224C147.882 224 164 218.627 164 212V180" fill="#1F2430"/>
|
|
26
|
-
<path d="M92 196C92 202.627 108.118 208 128 208C147.882 208 164 202.627 164 196" stroke="#F3F5F7" stroke-width="4" stroke-linecap="round"/>
|
|
27
|
-
<circle cx="154" cy="198" r="3" fill="#F3F5F7"/>
|
|
28
|
-
<circle cx="154" cy="214" r="3" fill="#F3F5F7"/>
|
|
29
|
-
</g>
|
|
30
|
-
</svg>
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256" fill="none">
|
|
2
|
+
<title>etho minimal pipeline glyph</title>
|
|
3
|
+
<g shape-rendering="geometricPrecision">
|
|
4
|
+
<!-- camera -->
|
|
5
|
+
<rect x="28" y="52" width="44" height="32" rx="8" fill="#1F2430"/>
|
|
6
|
+
<rect x="34" y="58" width="12" height="8" rx="2" fill="#F3F5F7"/>
|
|
7
|
+
<!-- signal -->
|
|
8
|
+
<rect x="104" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
9
|
+
<rect x="118" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
10
|
+
<rect x="132" y="38" width="8" height="60" rx="2" fill="#6FB64F"/>
|
|
11
|
+
<rect x="146" y="50" width="8" height="36" rx="2" fill="#6FB64F"/>
|
|
12
|
+
<rect x="160" y="62" width="8" height="12" rx="2" fill="#6FB64F"/>
|
|
13
|
+
<!-- opto triangle -->
|
|
14
|
+
<path d="M192 54L224 74L192 94Z" fill="#6FB64F"/>
|
|
15
|
+
<!-- tiny separators -->
|
|
16
|
+
<rect x="84" y="70" width="12" height="4" rx="2" fill="#1F2430"/>
|
|
17
|
+
<rect x="174" y="70" width="12" height="4" rx="2" fill="#1F2430"/>
|
|
18
|
+
<!-- bus -->
|
|
19
|
+
<path d="M48 96V120C48 124.418 51.582 128 56 128H124M208 96V120C208 124.418 204.418 128 200 128H132" stroke="#1F2430" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
|
|
20
|
+
<path d="M128 112V160" stroke="#1F2430" stroke-width="8" stroke-linecap="round"/>
|
|
21
|
+
<!-- junction -->
|
|
22
|
+
<circle cx="128" cy="128" r="6" fill="#1F2430"/>
|
|
23
|
+
<!-- database -->
|
|
24
|
+
<ellipse cx="128" cy="180" rx="36" ry="12" fill="#6FB64F"/>
|
|
25
|
+
<path d="M92 180V212C92 218.627 108.118 224 128 224C147.882 224 164 218.627 164 212V180" fill="#1F2430"/>
|
|
26
|
+
<path d="M92 196C92 202.627 108.118 208 128 208C147.882 208 164 202.627 164 196" stroke="#F3F5F7" stroke-width="4" stroke-linecap="round"/>
|
|
27
|
+
<circle cx="154" cy="198" r="3" fill="#F3F5F7"/>
|
|
28
|
+
<circle cx="154" cy="214" r="3" fill="#F3F5F7"/>
|
|
29
|
+
</g>
|
|
30
|
+
</svg>
|
etho/res_app.py
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import sys
|
|
3
|
-
import threading
|
|
4
|
-
from typing import Optional
|
|
5
|
-
|
|
6
|
-
from qtpy.QtCore import QObject, Signal
|
|
7
|
-
from qtpy.QtWidgets import QApplication, QLabel, QMessageBox, QPushButton, QSizePolicy
|
|
8
|
-
|
|
9
|
-
from .app import MainWindow as EthoMainWindow
|
|
10
|
-
from .app import _system_icon
|
|
11
|
-
from .resumable import ResumableExperimentRunner
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
logger = logging.getLogger(__name__)
|
|
15
|
-
CONTROL_COLUMN_WIDTH = 145
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class WorkerSignals(QObject):
|
|
19
|
-
finished = Signal(str)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class MainWindow(EthoMainWindow):
|
|
23
|
-
def __init__(self, protocol_folder: Optional[str] = None, playlist_folder: Optional[str] = None):
|
|
24
|
-
super().__init__(protocol_folder, playlist_folder)
|
|
25
|
-
self.setWindowTitle("etho resumable control")
|
|
26
|
-
self.runner = None
|
|
27
|
-
self.worker = None
|
|
28
|
-
self.progress_thread = None
|
|
29
|
-
self.progress_stop_event = None
|
|
30
|
-
self.run_active = False
|
|
31
|
-
self.signals = WorkerSignals()
|
|
32
|
-
self.signals.finished.connect(self.on_worker_finished)
|
|
33
|
-
try:
|
|
34
|
-
self.run_timer.timeout.disconnect(self.sync_run_state)
|
|
35
|
-
except (TypeError, RuntimeError):
|
|
36
|
-
pass
|
|
37
|
-
self.run_timer.stop()
|
|
38
|
-
|
|
39
|
-
buttons = self.layout.itemAtPosition(0, 0).layout()
|
|
40
|
-
self.button["Initialize hardware"] = QPushButton("Initialize hardware")
|
|
41
|
-
self.button["Initialize hardware"].clicked.connect(self.initialize_hardware)
|
|
42
|
-
self.button["Shutdown hardware"] = QPushButton("Shutdown hardware")
|
|
43
|
-
self.button["Shutdown hardware"].clicked.connect(self.shutdown_hardware)
|
|
44
|
-
self.status_label = QLabel("Select a protocol and initialize hardware.")
|
|
45
|
-
self.status_label.setWordWrap(True)
|
|
46
|
-
self.status_label.setFixedWidth(CONTROL_COLUMN_WIDTH)
|
|
47
|
-
self.status_label.setMinimumHeight(72)
|
|
48
|
-
self.status_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
|
|
49
|
-
|
|
50
|
-
buttons.insertWidget(1, self.button["Initialize hardware"])
|
|
51
|
-
buttons.insertWidget(2, self.button["Shutdown hardware"])
|
|
52
|
-
buttons.insertSpacing(3, 12)
|
|
53
|
-
buttons.insertSpacing(6, 8)
|
|
54
|
-
buttons.insertWidget(buttons.count() - 1, self.status_label)
|
|
55
|
-
self.layout.setColumnMinimumWidth(0, CONTROL_COLUMN_WIDTH)
|
|
56
|
-
self.layout.setColumnStretch(0, 0)
|
|
57
|
-
for button in self.button.values():
|
|
58
|
-
if hasattr(button, "setFixedWidth"):
|
|
59
|
-
button.setFixedWidth(CONTROL_COLUMN_WIDTH)
|
|
60
|
-
self.set_resumable_buttons("idle")
|
|
61
|
-
|
|
62
|
-
def refresh_lists(self, init: bool = False):
|
|
63
|
-
super().refresh_lists(init)
|
|
64
|
-
if self.playlists_view.selected_string is None:
|
|
65
|
-
self.playlists_view.selected_string = str(self.playlists_view.model()._data.iloc[0, 0])
|
|
66
|
-
if self.protocols_view.selected_string is None:
|
|
67
|
-
self.protocols_view.selected_string = str(self.protocols_view.model()._data.iloc[0, 0])
|
|
68
|
-
|
|
69
|
-
def selected_playlist(self):
|
|
70
|
-
if self.playlists_view.selected_string is None:
|
|
71
|
-
return None
|
|
72
|
-
return (self.playlist_folder / self.playlists_view.selected_string).as_posix()
|
|
73
|
-
|
|
74
|
-
def run_background(self, message, target):
|
|
75
|
-
if self.worker is not None and self.worker.is_alive():
|
|
76
|
-
return
|
|
77
|
-
self.status_label.setText(message)
|
|
78
|
-
self.set_resumable_buttons("busy")
|
|
79
|
-
|
|
80
|
-
def wrapped():
|
|
81
|
-
try:
|
|
82
|
-
status = target()
|
|
83
|
-
except Exception as e:
|
|
84
|
-
logger.exception("Resumable GUI action failed.")
|
|
85
|
-
self.run_active = False
|
|
86
|
-
status = f"Error: {e}"
|
|
87
|
-
self.signals.finished.emit(status)
|
|
88
|
-
|
|
89
|
-
self.worker = threading.Thread(target=wrapped, daemon=True)
|
|
90
|
-
self.worker.start()
|
|
91
|
-
|
|
92
|
-
def on_worker_finished(self, status):
|
|
93
|
-
self.worker = None
|
|
94
|
-
self.status_label.setText(status)
|
|
95
|
-
if not self.run_active:
|
|
96
|
-
self.run_timer.stop()
|
|
97
|
-
elif self.progress_thread is None or not self.progress_thread.is_alive():
|
|
98
|
-
self.start_progress_monitor()
|
|
99
|
-
self.set_resumable_buttons("ready" if self.runner else "idle")
|
|
100
|
-
|
|
101
|
-
def initialize_hardware(self):
|
|
102
|
-
if self.runner is not None:
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
def work():
|
|
106
|
-
logging.getLogger().setLevel(logging.DEBUG if self.button["Debug"].isChecked() else logging.INFO)
|
|
107
|
-
runner = ResumableExperimentRunner(protocol=self.current_protocol)
|
|
108
|
-
runner.setup_hardware()
|
|
109
|
-
self.runner = runner
|
|
110
|
-
services = ", ".join(runner.services)
|
|
111
|
-
return f"Hardware {services} initialized. Ready to run an experiment"
|
|
112
|
-
|
|
113
|
-
self.run_background("Initializing hardware...", work)
|
|
114
|
-
|
|
115
|
-
def shutdown_hardware(self):
|
|
116
|
-
if self.runner is None:
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
def work():
|
|
120
|
-
self.runner.close()
|
|
121
|
-
self.runner = None
|
|
122
|
-
self.run_active = False
|
|
123
|
-
if self.progress_stop_event is not None:
|
|
124
|
-
self.progress_stop_event.set()
|
|
125
|
-
return "Hardware shut down."
|
|
126
|
-
|
|
127
|
-
self.run_background("Shutting down hardware...", work)
|
|
128
|
-
|
|
129
|
-
def start(self, preview: bool = False):
|
|
130
|
-
if self.runner is None:
|
|
131
|
-
QMessageBox.warning(self, "Hardware not initialized", "Initialize hardware first.")
|
|
132
|
-
return
|
|
133
|
-
playlist = self.selected_playlist()
|
|
134
|
-
if playlist is None:
|
|
135
|
-
QMessageBox.warning(self, "Missing playlist", "Select a playlist first.")
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
def work():
|
|
139
|
-
logging.getLogger().setLevel(logging.DEBUG if self.button["Debug"].isChecked() else logging.INFO)
|
|
140
|
-
if self.progress_stop_event is not None:
|
|
141
|
-
self.progress_stop_event.set()
|
|
142
|
-
if self.progress_thread is not None and self.progress_thread.is_alive():
|
|
143
|
-
self.progress_thread.join(timeout=0.2)
|
|
144
|
-
self.runner.stop_run()
|
|
145
|
-
self.progress_stop_event = threading.Event()
|
|
146
|
-
self.runner.prepare_playlist_run(playlist, preview=preview)
|
|
147
|
-
self.runner.start()
|
|
148
|
-
self.run_active = True
|
|
149
|
-
return "Camera preview running." if preview else "Experiment running."
|
|
150
|
-
|
|
151
|
-
self.run_background("Starting experiment...", work)
|
|
152
|
-
|
|
153
|
-
def request_stop(self):
|
|
154
|
-
if self.runner is None:
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
def work():
|
|
158
|
-
if self.progress_stop_event is not None:
|
|
159
|
-
self.progress_stop_event.set()
|
|
160
|
-
self.runner.stop_run()
|
|
161
|
-
self.run_active = False
|
|
162
|
-
return "Experiment stopped."
|
|
163
|
-
|
|
164
|
-
self.run_background("Stopping experiment...", work)
|
|
165
|
-
|
|
166
|
-
def camera_preview(self):
|
|
167
|
-
self.start(preview=True)
|
|
168
|
-
|
|
169
|
-
def start_progress_monitor(self):
|
|
170
|
-
if self.runner is None or self.progress_stop_event is None:
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
def monitor():
|
|
174
|
-
try:
|
|
175
|
-
self.runner.monitor_progress(
|
|
176
|
-
show_progress=self.button["Progress"].isChecked(),
|
|
177
|
-
stop_event=self.progress_stop_event,
|
|
178
|
-
)
|
|
179
|
-
finally:
|
|
180
|
-
if self.run_active and self.progress_stop_event is not None and not self.progress_stop_event.is_set():
|
|
181
|
-
self.runner.stop_run()
|
|
182
|
-
self.run_active = False
|
|
183
|
-
self.signals.finished.emit("Experiment finished.")
|
|
184
|
-
|
|
185
|
-
self.progress_thread = threading.Thread(target=monitor, daemon=True)
|
|
186
|
-
self.progress_thread.start()
|
|
187
|
-
|
|
188
|
-
def set_resumable_buttons(self, state):
|
|
189
|
-
busy = state == "busy"
|
|
190
|
-
ready = self.runner is not None
|
|
191
|
-
running = ready and self.run_active
|
|
192
|
-
self.button["Refresh lists"].setEnabled(not busy and not ready)
|
|
193
|
-
self.button["Initialize hardware"].setEnabled(not busy and not ready)
|
|
194
|
-
self.button["Shutdown hardware"].setEnabled(not busy and ready)
|
|
195
|
-
self.button["Start"].setEnabled(not busy and ready)
|
|
196
|
-
self.button["Stop"].setEnabled(not busy and running)
|
|
197
|
-
self.button["Camera_preview"].setEnabled(not busy and ready)
|
|
198
|
-
self.button["Debug"].setEnabled(not busy)
|
|
199
|
-
self.button["Progress"].setEnabled(not busy)
|
|
200
|
-
self.button["Exit"].setEnabled(not busy)
|
|
201
|
-
self.protocols_view.setEnabled(not busy and not ready)
|
|
202
|
-
self.protocol_view.setEnabled(not busy and not ready)
|
|
203
|
-
self.playlists_view.setEnabled(not busy)
|
|
204
|
-
self.playlist_view.setEnabled(not busy)
|
|
205
|
-
|
|
206
|
-
def closeEvent(self, event):
|
|
207
|
-
if self.progress_stop_event is not None:
|
|
208
|
-
self.progress_stop_event.set()
|
|
209
|
-
if self.runner is not None:
|
|
210
|
-
self.runner.close()
|
|
211
|
-
self.runner = None
|
|
212
|
-
self.run_active = False
|
|
213
|
-
event.accept()
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
def main(protocol_folder: Optional[str] = None, playlist_folder: Optional[str] = None):
|
|
217
|
-
app = QApplication(sys.argv)
|
|
218
|
-
icon = _system_icon(app)
|
|
219
|
-
app.setWindowIcon(icon)
|
|
220
|
-
|
|
221
|
-
window = MainWindow(protocol_folder, playlist_folder)
|
|
222
|
-
window.setWindowIcon(icon)
|
|
223
|
-
window.show()
|
|
224
|
-
|
|
225
|
-
sys.exit(app.exec_())
|
|
1
|
+
import logging
|
|
2
|
+
import sys
|
|
3
|
+
import threading
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from qtpy.QtCore import QObject, Signal
|
|
7
|
+
from qtpy.QtWidgets import QApplication, QLabel, QMessageBox, QPushButton, QSizePolicy
|
|
8
|
+
|
|
9
|
+
from .app import MainWindow as EthoMainWindow
|
|
10
|
+
from .app import _system_icon
|
|
11
|
+
from .resumable import ResumableExperimentRunner
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
CONTROL_COLUMN_WIDTH = 145
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class WorkerSignals(QObject):
|
|
19
|
+
finished = Signal(str)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MainWindow(EthoMainWindow):
|
|
23
|
+
def __init__(self, protocol_folder: Optional[str] = None, playlist_folder: Optional[str] = None):
|
|
24
|
+
super().__init__(protocol_folder, playlist_folder)
|
|
25
|
+
self.setWindowTitle("etho resumable control")
|
|
26
|
+
self.runner = None
|
|
27
|
+
self.worker = None
|
|
28
|
+
self.progress_thread = None
|
|
29
|
+
self.progress_stop_event = None
|
|
30
|
+
self.run_active = False
|
|
31
|
+
self.signals = WorkerSignals()
|
|
32
|
+
self.signals.finished.connect(self.on_worker_finished)
|
|
33
|
+
try:
|
|
34
|
+
self.run_timer.timeout.disconnect(self.sync_run_state)
|
|
35
|
+
except (TypeError, RuntimeError):
|
|
36
|
+
pass
|
|
37
|
+
self.run_timer.stop()
|
|
38
|
+
|
|
39
|
+
buttons = self.layout.itemAtPosition(0, 0).layout()
|
|
40
|
+
self.button["Initialize hardware"] = QPushButton("Initialize hardware")
|
|
41
|
+
self.button["Initialize hardware"].clicked.connect(self.initialize_hardware)
|
|
42
|
+
self.button["Shutdown hardware"] = QPushButton("Shutdown hardware")
|
|
43
|
+
self.button["Shutdown hardware"].clicked.connect(self.shutdown_hardware)
|
|
44
|
+
self.status_label = QLabel("Select a protocol and initialize hardware.")
|
|
45
|
+
self.status_label.setWordWrap(True)
|
|
46
|
+
self.status_label.setFixedWidth(CONTROL_COLUMN_WIDTH)
|
|
47
|
+
self.status_label.setMinimumHeight(72)
|
|
48
|
+
self.status_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
|
|
49
|
+
|
|
50
|
+
buttons.insertWidget(1, self.button["Initialize hardware"])
|
|
51
|
+
buttons.insertWidget(2, self.button["Shutdown hardware"])
|
|
52
|
+
buttons.insertSpacing(3, 12)
|
|
53
|
+
buttons.insertSpacing(6, 8)
|
|
54
|
+
buttons.insertWidget(buttons.count() - 1, self.status_label)
|
|
55
|
+
self.layout.setColumnMinimumWidth(0, CONTROL_COLUMN_WIDTH)
|
|
56
|
+
self.layout.setColumnStretch(0, 0)
|
|
57
|
+
for button in self.button.values():
|
|
58
|
+
if hasattr(button, "setFixedWidth"):
|
|
59
|
+
button.setFixedWidth(CONTROL_COLUMN_WIDTH)
|
|
60
|
+
self.set_resumable_buttons("idle")
|
|
61
|
+
|
|
62
|
+
def refresh_lists(self, init: bool = False):
|
|
63
|
+
super().refresh_lists(init)
|
|
64
|
+
if self.playlists_view.selected_string is None:
|
|
65
|
+
self.playlists_view.selected_string = str(self.playlists_view.model()._data.iloc[0, 0])
|
|
66
|
+
if self.protocols_view.selected_string is None:
|
|
67
|
+
self.protocols_view.selected_string = str(self.protocols_view.model()._data.iloc[0, 0])
|
|
68
|
+
|
|
69
|
+
def selected_playlist(self):
|
|
70
|
+
if self.playlists_view.selected_string is None:
|
|
71
|
+
return None
|
|
72
|
+
return (self.playlist_folder / self.playlists_view.selected_string).as_posix()
|
|
73
|
+
|
|
74
|
+
def run_background(self, message, target):
|
|
75
|
+
if self.worker is not None and self.worker.is_alive():
|
|
76
|
+
return
|
|
77
|
+
self.status_label.setText(message)
|
|
78
|
+
self.set_resumable_buttons("busy")
|
|
79
|
+
|
|
80
|
+
def wrapped():
|
|
81
|
+
try:
|
|
82
|
+
status = target()
|
|
83
|
+
except Exception as e:
|
|
84
|
+
logger.exception("Resumable GUI action failed.")
|
|
85
|
+
self.run_active = False
|
|
86
|
+
status = f"Error: {e}"
|
|
87
|
+
self.signals.finished.emit(status)
|
|
88
|
+
|
|
89
|
+
self.worker = threading.Thread(target=wrapped, daemon=True)
|
|
90
|
+
self.worker.start()
|
|
91
|
+
|
|
92
|
+
def on_worker_finished(self, status):
|
|
93
|
+
self.worker = None
|
|
94
|
+
self.status_label.setText(status)
|
|
95
|
+
if not self.run_active:
|
|
96
|
+
self.run_timer.stop()
|
|
97
|
+
elif self.progress_thread is None or not self.progress_thread.is_alive():
|
|
98
|
+
self.start_progress_monitor()
|
|
99
|
+
self.set_resumable_buttons("ready" if self.runner else "idle")
|
|
100
|
+
|
|
101
|
+
def initialize_hardware(self):
|
|
102
|
+
if self.runner is not None:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
def work():
|
|
106
|
+
logging.getLogger().setLevel(logging.DEBUG if self.button["Debug"].isChecked() else logging.INFO)
|
|
107
|
+
runner = ResumableExperimentRunner(protocol=self.current_protocol)
|
|
108
|
+
runner.setup_hardware()
|
|
109
|
+
self.runner = runner
|
|
110
|
+
services = ", ".join(runner.services)
|
|
111
|
+
return f"Hardware {services} initialized. Ready to run an experiment"
|
|
112
|
+
|
|
113
|
+
self.run_background("Initializing hardware...", work)
|
|
114
|
+
|
|
115
|
+
def shutdown_hardware(self):
|
|
116
|
+
if self.runner is None:
|
|
117
|
+
return
|
|
118
|
+
|
|
119
|
+
def work():
|
|
120
|
+
self.runner.close()
|
|
121
|
+
self.runner = None
|
|
122
|
+
self.run_active = False
|
|
123
|
+
if self.progress_stop_event is not None:
|
|
124
|
+
self.progress_stop_event.set()
|
|
125
|
+
return "Hardware shut down."
|
|
126
|
+
|
|
127
|
+
self.run_background("Shutting down hardware...", work)
|
|
128
|
+
|
|
129
|
+
def start(self, preview: bool = False):
|
|
130
|
+
if self.runner is None:
|
|
131
|
+
QMessageBox.warning(self, "Hardware not initialized", "Initialize hardware first.")
|
|
132
|
+
return
|
|
133
|
+
playlist = self.selected_playlist()
|
|
134
|
+
if playlist is None:
|
|
135
|
+
QMessageBox.warning(self, "Missing playlist", "Select a playlist first.")
|
|
136
|
+
return
|
|
137
|
+
|
|
138
|
+
def work():
|
|
139
|
+
logging.getLogger().setLevel(logging.DEBUG if self.button["Debug"].isChecked() else logging.INFO)
|
|
140
|
+
if self.progress_stop_event is not None:
|
|
141
|
+
self.progress_stop_event.set()
|
|
142
|
+
if self.progress_thread is not None and self.progress_thread.is_alive():
|
|
143
|
+
self.progress_thread.join(timeout=0.2)
|
|
144
|
+
self.runner.stop_run()
|
|
145
|
+
self.progress_stop_event = threading.Event()
|
|
146
|
+
self.runner.prepare_playlist_run(playlist, preview=preview)
|
|
147
|
+
self.runner.start()
|
|
148
|
+
self.run_active = True
|
|
149
|
+
return "Camera preview running." if preview else "Experiment running."
|
|
150
|
+
|
|
151
|
+
self.run_background("Starting experiment...", work)
|
|
152
|
+
|
|
153
|
+
def request_stop(self):
|
|
154
|
+
if self.runner is None:
|
|
155
|
+
return
|
|
156
|
+
|
|
157
|
+
def work():
|
|
158
|
+
if self.progress_stop_event is not None:
|
|
159
|
+
self.progress_stop_event.set()
|
|
160
|
+
self.runner.stop_run()
|
|
161
|
+
self.run_active = False
|
|
162
|
+
return "Experiment stopped."
|
|
163
|
+
|
|
164
|
+
self.run_background("Stopping experiment...", work)
|
|
165
|
+
|
|
166
|
+
def camera_preview(self):
|
|
167
|
+
self.start(preview=True)
|
|
168
|
+
|
|
169
|
+
def start_progress_monitor(self):
|
|
170
|
+
if self.runner is None or self.progress_stop_event is None:
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
def monitor():
|
|
174
|
+
try:
|
|
175
|
+
self.runner.monitor_progress(
|
|
176
|
+
show_progress=self.button["Progress"].isChecked(),
|
|
177
|
+
stop_event=self.progress_stop_event,
|
|
178
|
+
)
|
|
179
|
+
finally:
|
|
180
|
+
if self.run_active and self.progress_stop_event is not None and not self.progress_stop_event.is_set():
|
|
181
|
+
self.runner.stop_run()
|
|
182
|
+
self.run_active = False
|
|
183
|
+
self.signals.finished.emit("Experiment finished.")
|
|
184
|
+
|
|
185
|
+
self.progress_thread = threading.Thread(target=monitor, daemon=True)
|
|
186
|
+
self.progress_thread.start()
|
|
187
|
+
|
|
188
|
+
def set_resumable_buttons(self, state):
|
|
189
|
+
busy = state == "busy"
|
|
190
|
+
ready = self.runner is not None
|
|
191
|
+
running = ready and self.run_active
|
|
192
|
+
self.button["Refresh lists"].setEnabled(not busy and not ready)
|
|
193
|
+
self.button["Initialize hardware"].setEnabled(not busy and not ready)
|
|
194
|
+
self.button["Shutdown hardware"].setEnabled(not busy and ready)
|
|
195
|
+
self.button["Start"].setEnabled(not busy and ready)
|
|
196
|
+
self.button["Stop"].setEnabled(not busy and running)
|
|
197
|
+
self.button["Camera_preview"].setEnabled(not busy and ready)
|
|
198
|
+
self.button["Debug"].setEnabled(not busy)
|
|
199
|
+
self.button["Progress"].setEnabled(not busy)
|
|
200
|
+
self.button["Exit"].setEnabled(not busy)
|
|
201
|
+
self.protocols_view.setEnabled(not busy and not ready)
|
|
202
|
+
self.protocol_view.setEnabled(not busy and not ready)
|
|
203
|
+
self.playlists_view.setEnabled(not busy)
|
|
204
|
+
self.playlist_view.setEnabled(not busy)
|
|
205
|
+
|
|
206
|
+
def closeEvent(self, event):
|
|
207
|
+
if self.progress_stop_event is not None:
|
|
208
|
+
self.progress_stop_event.set()
|
|
209
|
+
if self.runner is not None:
|
|
210
|
+
self.runner.close()
|
|
211
|
+
self.runner = None
|
|
212
|
+
self.run_active = False
|
|
213
|
+
event.accept()
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def main(protocol_folder: Optional[str] = None, playlist_folder: Optional[str] = None):
|
|
217
|
+
app = QApplication(sys.argv)
|
|
218
|
+
icon = _system_icon(app)
|
|
219
|
+
app.setWindowIcon(icon)
|
|
220
|
+
|
|
221
|
+
window = MainWindow(protocol_folder, playlist_folder)
|
|
222
|
+
window.setWindowIcon(icon)
|
|
223
|
+
window.show()
|
|
224
|
+
|
|
225
|
+
sys.exit(app.exec_())
|