etho-python 0.22.0__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/__init__.py +9 -0
- etho/app.py +569 -0
- etho/assets/etho_icon1_pipeline_dark.svg +23 -0
- etho/assets/etho_icon1_pipeline_light.svg +30 -0
- etho/cli.py +215 -0
- etho/client.py +384 -0
- etho/services/ANAZeroService.py +123 -0
- etho/services/BLTZeroService.py +108 -0
- etho/services/DAQZeroService.py +326 -0
- etho/services/DLPZeroService.py +240 -0
- etho/services/GCMZeroService.py +271 -0
- etho/services/GOVZeroService.py +231 -0
- etho/services/NICounterZeroService.py +92 -0
- etho/services/NITriggerZeroService.py +120 -0
- etho/services/TemplateZeroService.py +98 -0
- etho/services/ZeroService.py +272 -0
- etho/services/__init__.py +0 -0
- etho/services/callbacks/__init__.py +19 -0
- etho/services/callbacks/_base.py +92 -0
- etho/services/callbacks/_image.py +798 -0
- etho/services/callbacks/_trace.py +456 -0
- etho/services/camera/__init__.py +13 -0
- etho/services/camera/base.py +164 -0
- etho/services/camera/basler.py +201 -0
- etho/services/camera/dummy.py +139 -0
- etho/services/camera/hamamatsu.py +133 -0
- etho/services/camera/spinnaker.py +317 -0
- etho/services/camera/ximea.py +167 -0
- etho/services/daq/IOTask.py +311 -0
- etho/services/daq/ai.py +174 -0
- etho/services/dlp/dlp_make_warpfiles.py +131 -0
- etho/services/dlp/dlp_runners.py +238 -0
- etho/services/utils/__init__.py +0 -0
- etho/services/utils/concurrent_task.py +236 -0
- etho/services/utils/log_exceptions.py +39 -0
- etho/utils/__init__.py +0 -0
- etho/utils/calibration.py +88 -0
- etho/utils/config.py +41 -0
- etho/utils/runner.py +121 -0
- etho/utils/shuffled_cycle.py +45 -0
- etho/utils/sound.py +336 -0
- etho/utils/tui.py +105 -0
- etho/utils/zeroclient.py +95 -0
- etho_python-0.22.0.dist-info/METADATA +49 -0
- etho_python-0.22.0.dist-info/RECORD +47 -0
- etho_python-0.22.0.dist-info/WHEEL +4 -0
- etho_python-0.22.0.dist-info/entry_points.txt +3 -0
etho/__init__.py
ADDED
etho/app.py
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import yaml
|
|
3
|
+
import rich
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Union, Optional
|
|
7
|
+
import os
|
|
8
|
+
import logging
|
|
9
|
+
import time
|
|
10
|
+
import psutil
|
|
11
|
+
import threading
|
|
12
|
+
import queue
|
|
13
|
+
|
|
14
|
+
from qtpy import QtWidgets
|
|
15
|
+
from qtpy.QtGui import QIcon, QPalette
|
|
16
|
+
from qtpy.QtWidgets import (
|
|
17
|
+
QApplication,
|
|
18
|
+
QTableView,
|
|
19
|
+
QGridLayout,
|
|
20
|
+
QWidget,
|
|
21
|
+
QMainWindow,
|
|
22
|
+
QPushButton,
|
|
23
|
+
QVBoxLayout,
|
|
24
|
+
QCheckBox,
|
|
25
|
+
QMessageBox,
|
|
26
|
+
QDialog,
|
|
27
|
+
QDialogButtonBox,
|
|
28
|
+
QLabel,
|
|
29
|
+
QSplitter,
|
|
30
|
+
QProgressBar,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
from qtpy.QtCore import QAbstractTableModel, Qt, QTimer
|
|
34
|
+
|
|
35
|
+
from pyqtgraph.parametertree import Parameter, ParameterTree
|
|
36
|
+
|
|
37
|
+
from .utils.sound import parse_table
|
|
38
|
+
from . import client
|
|
39
|
+
from .utils.config import readconfig
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
logger = logging.getLogger(__name__)
|
|
43
|
+
|
|
44
|
+
_ICON_DIR = Path(__file__).with_name("assets")
|
|
45
|
+
_LIGHT_ICON = _ICON_DIR / "etho_icon1_pipeline_light.svg"
|
|
46
|
+
_DARK_ICON = _ICON_DIR / "etho_icon1_pipeline_dark.svg"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _system_icon(app: QApplication) -> QIcon:
|
|
50
|
+
icon_path = _LIGHT_ICON
|
|
51
|
+
try:
|
|
52
|
+
window_role = getattr(getattr(QPalette, "ColorRole", QPalette), "Window")
|
|
53
|
+
if app.palette().color(window_role).lightness() < 128:
|
|
54
|
+
icon_path = _DARK_ICON
|
|
55
|
+
except Exception:
|
|
56
|
+
pass
|
|
57
|
+
if not icon_path.exists():
|
|
58
|
+
icon_path = _LIGHT_ICON
|
|
59
|
+
return QIcon(icon_path.as_posix())
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class PandasModel(QAbstractTableModel):
|
|
63
|
+
def __init__(self, data, editable: bool = False):
|
|
64
|
+
QAbstractTableModel.__init__(self)
|
|
65
|
+
self._data = data
|
|
66
|
+
self._editable = editable
|
|
67
|
+
|
|
68
|
+
def rowCount(self, parent=None):
|
|
69
|
+
return self._data.shape[0]
|
|
70
|
+
|
|
71
|
+
def columnCount(self, parent=None):
|
|
72
|
+
return self._data.shape[1]
|
|
73
|
+
|
|
74
|
+
def data(self, index, role=Qt.DisplayRole):
|
|
75
|
+
if index.isValid():
|
|
76
|
+
if role == Qt.DisplayRole or role == Qt.EditRole:
|
|
77
|
+
value = self._data.iloc[index.row(), index.column()]
|
|
78
|
+
return str(value)
|
|
79
|
+
|
|
80
|
+
def setData(self, index, value, role):
|
|
81
|
+
if role == Qt.EditRole:
|
|
82
|
+
self._data.iloc[index.row(), index.column()] = value
|
|
83
|
+
return True
|
|
84
|
+
|
|
85
|
+
def headerData(self, col, orientation, role):
|
|
86
|
+
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
|
|
87
|
+
return self._data.columns[col]
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
def flags(self, index):
|
|
91
|
+
if self._editable:
|
|
92
|
+
return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
|
|
93
|
+
else:
|
|
94
|
+
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
|
|
95
|
+
|
|
96
|
+
def replaceData(self, data):
|
|
97
|
+
self.beginResetModel()
|
|
98
|
+
self._data = data
|
|
99
|
+
self.endResetModel()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class TableView(QTableView):
|
|
103
|
+
def __init__(self, model, child=None, folder=None):
|
|
104
|
+
QTableView.__init__(self)
|
|
105
|
+
self._child = child
|
|
106
|
+
self._folder = folder
|
|
107
|
+
|
|
108
|
+
self.setModel(model)
|
|
109
|
+
self.selectionModel().selectionChanged.connect(self.update_child)
|
|
110
|
+
self.doubleClicked.connect(self.edit_file)
|
|
111
|
+
|
|
112
|
+
header = self.horizontalHeader()
|
|
113
|
+
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
|
|
114
|
+
header.setStretchLastSection(True)
|
|
115
|
+
self.resizeRowsToContents()
|
|
116
|
+
self.data = None
|
|
117
|
+
self.selected_string = None
|
|
118
|
+
|
|
119
|
+
def update_child(self, selected, deselected):
|
|
120
|
+
if self._child is not None:
|
|
121
|
+
selected_row = selected.indexes()[0].row()
|
|
122
|
+
self.selected_string = str(self.model()._data.iloc[selected_row, 0])
|
|
123
|
+
self.data = self._child.data_from_filename(self.selected_string)
|
|
124
|
+
self._child.replaceData(self.data)
|
|
125
|
+
|
|
126
|
+
def edit_file(self):
|
|
127
|
+
if self._folder is not None:
|
|
128
|
+
print(f"code {self.folder}/{self.selected_string}")
|
|
129
|
+
os.system(f"code {self.folder}/{self.selected_string}")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _parameter_item(name, value):
|
|
133
|
+
item = {"name": str(name)}
|
|
134
|
+
|
|
135
|
+
if isinstance(value, dict):
|
|
136
|
+
item["type"] = "group"
|
|
137
|
+
item["original_type"] = "dict"
|
|
138
|
+
item["children"] = [_parameter_item(key, val) for key, val in value.items()]
|
|
139
|
+
elif isinstance(value, list):
|
|
140
|
+
item["type"] = "group"
|
|
141
|
+
item["original_type"] = "list"
|
|
142
|
+
scalar_names = [str(val) for val in value if not isinstance(val, (dict, list))]
|
|
143
|
+
use_checkboxes = len(scalar_names) == len(value) and len(set(scalar_names)) == len(scalar_names)
|
|
144
|
+
if use_checkboxes:
|
|
145
|
+
item["list_mode"] = "checkbox"
|
|
146
|
+
item["children"] = [{"name": str(val), "type": "bool", "value": True, "original_value": val} for val in value]
|
|
147
|
+
else:
|
|
148
|
+
item["children"] = [_parameter_item(idx, val) for idx, val in enumerate(value)]
|
|
149
|
+
elif isinstance(value, bool):
|
|
150
|
+
item["type"] = "bool"
|
|
151
|
+
item["value"] = value
|
|
152
|
+
elif isinstance(value, int):
|
|
153
|
+
item["type"] = "int"
|
|
154
|
+
item["value"] = value
|
|
155
|
+
elif isinstance(value, float):
|
|
156
|
+
item["type"] = "float"
|
|
157
|
+
item["value"] = value
|
|
158
|
+
elif value is None:
|
|
159
|
+
item["type"] = "str"
|
|
160
|
+
item["value"] = ""
|
|
161
|
+
item["original_type"] = "none"
|
|
162
|
+
else:
|
|
163
|
+
item["type"] = "str"
|
|
164
|
+
item["value"] = str(value)
|
|
165
|
+
|
|
166
|
+
return item
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
# format to parametertree
|
|
170
|
+
def from_yaml(d, readonly=True):
|
|
171
|
+
pt = [_parameter_item(key, val) for key, val in d.items()]
|
|
172
|
+
p = Parameter.create(name="Protocol parameters", type="group", children=pt)
|
|
173
|
+
if readonly:
|
|
174
|
+
children_read_only(p.children())
|
|
175
|
+
return p
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def children_read_only(children):
|
|
179
|
+
for child in children:
|
|
180
|
+
if child.children():
|
|
181
|
+
children_read_only(child.children())
|
|
182
|
+
else:
|
|
183
|
+
child.setReadonly()
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def to_yaml(p):
|
|
187
|
+
if p.children():
|
|
188
|
+
if p.opts.get("original_type") == "list":
|
|
189
|
+
if p.opts.get("list_mode") == "checkbox":
|
|
190
|
+
return [child.opts.get("original_value", child.name()) for child in p.children() if child.value()]
|
|
191
|
+
return [to_yaml(child) for child in p.children()]
|
|
192
|
+
return {child.name(): to_yaml(child) for child in p.children()}
|
|
193
|
+
|
|
194
|
+
value = p.value()
|
|
195
|
+
if p.opts.get("original_type") == "none":
|
|
196
|
+
return yaml.safe_load(value)
|
|
197
|
+
return value
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def load(filename: str):
|
|
201
|
+
with open(filename, "r") as f:
|
|
202
|
+
d = yaml.load(f, Loader=yaml.SafeLoader)
|
|
203
|
+
return d
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def save(d, filename: str):
|
|
207
|
+
pass
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def kill_child_processes():
|
|
211
|
+
try:
|
|
212
|
+
parent = psutil.Process()
|
|
213
|
+
except psutil.NoSuchProcess:
|
|
214
|
+
return
|
|
215
|
+
children = parent.children(recursive=True)
|
|
216
|
+
for child in children:
|
|
217
|
+
child.terminate() # friendly termination
|
|
218
|
+
_, still_alive = psutil.wait_procs(children, timeout=3)
|
|
219
|
+
for child in still_alive:
|
|
220
|
+
child.kill() # unfriendly termination
|
|
221
|
+
# os.kill(child.pid, signal.SIGKILL)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class RunDialog(QDialog):
|
|
225
|
+
def __init__(self, stop_event, done_event, queue_total):
|
|
226
|
+
super().__init__()
|
|
227
|
+
|
|
228
|
+
self.stop_event = stop_event
|
|
229
|
+
self.done_event = done_event
|
|
230
|
+
self.queue_total = queue_total
|
|
231
|
+
|
|
232
|
+
self.setWindowTitle("Progress")
|
|
233
|
+
|
|
234
|
+
QBtn = QDialogButtonBox.Cancel
|
|
235
|
+
|
|
236
|
+
self.message = QLabel("Running")
|
|
237
|
+
self.message.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
|
|
238
|
+
self.pbar = QProgressBar(self)
|
|
239
|
+
self.pbar.setValue(0)
|
|
240
|
+
|
|
241
|
+
self.buttonBox = QDialogButtonBox(QBtn)
|
|
242
|
+
self.buttonBox.accepted.connect(self.accept)
|
|
243
|
+
self.buttonBox.rejected.connect(self.reject)
|
|
244
|
+
|
|
245
|
+
self.layout = QVBoxLayout()
|
|
246
|
+
self.layout.addWidget(self.message)
|
|
247
|
+
self.layout.addWidget(self.pbar)
|
|
248
|
+
self.layout.addWidget(self.buttonBox)
|
|
249
|
+
self.setLayout(self.layout)
|
|
250
|
+
self.total = queue_total.get()
|
|
251
|
+
|
|
252
|
+
self.monitor_thread = threading.Thread(
|
|
253
|
+
target=monitor,
|
|
254
|
+
args=[self.done_event, self.stop_event, self.accept, self.pbar, self.total],
|
|
255
|
+
)
|
|
256
|
+
self.monitor_thread.start()
|
|
257
|
+
|
|
258
|
+
def reject(self):
|
|
259
|
+
self.stop_event.set()
|
|
260
|
+
super().reject()
|
|
261
|
+
|
|
262
|
+
def accept(self):
|
|
263
|
+
self.stop_event.set()
|
|
264
|
+
super().accept()
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def monitor(event1, event2, callback, progress=None, progress_total=100):
|
|
268
|
+
cnt = 0
|
|
269
|
+
RUN = True
|
|
270
|
+
while RUN:
|
|
271
|
+
if event1.is_set():
|
|
272
|
+
callback()
|
|
273
|
+
RUN = False
|
|
274
|
+
if event2.is_set():
|
|
275
|
+
RUN = False
|
|
276
|
+
cnt += 1
|
|
277
|
+
if progress is not None:
|
|
278
|
+
progress.setValue(int(100 * cnt / progress_total))
|
|
279
|
+
time.sleep(1)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class MainWindow(QMainWindow):
|
|
283
|
+
def __init__(
|
|
284
|
+
self,
|
|
285
|
+
protocol_folder: Optional[Union[str, os.PathLike]] = None,
|
|
286
|
+
playlist_folder: Optional[Union[str, os.PathLike]] = None,
|
|
287
|
+
):
|
|
288
|
+
super(MainWindow, self).__init__()
|
|
289
|
+
|
|
290
|
+
# rich.print(config)
|
|
291
|
+
if protocol_folder is None:
|
|
292
|
+
config = readconfig()
|
|
293
|
+
protocol_folder = config["protocolfolder"]
|
|
294
|
+
self.protocol_folder = Path(protocol_folder)
|
|
295
|
+
|
|
296
|
+
if not self.protocol_folder.exists():
|
|
297
|
+
raise FileExistsError(f"{self.protocol_folder} does not exist!")
|
|
298
|
+
|
|
299
|
+
logging.info(f"Loading protocols from {self.protocol_folder}.")
|
|
300
|
+
|
|
301
|
+
if playlist_folder is None:
|
|
302
|
+
config = readconfig()
|
|
303
|
+
playlist_folder = config["playlistfolder"]
|
|
304
|
+
self.playlist_folder = Path(playlist_folder)
|
|
305
|
+
|
|
306
|
+
if not self.playlist_folder.exists():
|
|
307
|
+
raise FileExistsError(f"{self.playlist_folder} does not exist!")
|
|
308
|
+
|
|
309
|
+
logging.info(f"Loading playlists from {self.playlist_folder}.")
|
|
310
|
+
|
|
311
|
+
self.setWindowTitle("etho control")
|
|
312
|
+
self.run_thread = None
|
|
313
|
+
self.stop_event = None
|
|
314
|
+
self.done_event = None
|
|
315
|
+
self.run_timer = QTimer(self)
|
|
316
|
+
self.run_timer.setInterval(200)
|
|
317
|
+
self.run_timer.timeout.connect(self.sync_run_state)
|
|
318
|
+
|
|
319
|
+
# Buttons
|
|
320
|
+
buttons = QVBoxLayout()
|
|
321
|
+
self.button = {}
|
|
322
|
+
self.button["Refresh lists"] = QPushButton("Refresh lists")
|
|
323
|
+
self.button["Refresh lists"].clicked.connect(self.refresh_lists)
|
|
324
|
+
self.button["Start"] = QPushButton("Start")
|
|
325
|
+
self.button["Start"].clicked.connect(self.start)
|
|
326
|
+
self.button["Stop"] = QPushButton("Stop")
|
|
327
|
+
self.button["Stop"].clicked.connect(self.request_stop)
|
|
328
|
+
self.button["Camera_preview"] = QPushButton("Camera preview")
|
|
329
|
+
self.button["Camera_preview"].clicked.connect(self.camera_preview)
|
|
330
|
+
self.button["Debug"] = QCheckBox("Debug")
|
|
331
|
+
self.button["Progress"] = QCheckBox("Show Progress")
|
|
332
|
+
self.button["Progress"].setChecked(True)
|
|
333
|
+
|
|
334
|
+
[buttons.addWidget(b) for b in self.button.values()]
|
|
335
|
+
|
|
336
|
+
self.help = QtWidgets.QLabel(
|
|
337
|
+
"<br>"
|
|
338
|
+
"<br>"
|
|
339
|
+
"<B>Instructions</B><br>"
|
|
340
|
+
"<br>"
|
|
341
|
+
"Single Click on<br>"
|
|
342
|
+
" playlist or protocol.<br>"
|
|
343
|
+
"previews the file.<br>"
|
|
344
|
+
"<br>"
|
|
345
|
+
"Double Click opens<br>"
|
|
346
|
+
"playlist or protocol<br>"
|
|
347
|
+
"in VS code.<br>"
|
|
348
|
+
)
|
|
349
|
+
buttons.addWidget(self.help)
|
|
350
|
+
|
|
351
|
+
# Layout
|
|
352
|
+
self.layout = QGridLayout()
|
|
353
|
+
self.layout.addLayout(buttons, 0, 0)
|
|
354
|
+
self.refresh_lists(init=True)
|
|
355
|
+
|
|
356
|
+
self.layout.setColumnMinimumWidth(1, 200)
|
|
357
|
+
self.layout.setColumnMinimumWidth(2, 600)
|
|
358
|
+
self.layout.setColumnStretch(2, 1)
|
|
359
|
+
self.layout.setColumnStretch(1, 2)
|
|
360
|
+
|
|
361
|
+
widget = QWidget()
|
|
362
|
+
widget.setLayout(self.layout)
|
|
363
|
+
self.setCentralWidget(widget)
|
|
364
|
+
self.set_run_buttons(False)
|
|
365
|
+
|
|
366
|
+
def on_protocol_changed(self, param, changes):
|
|
367
|
+
self.current_protocol = to_yaml(param)
|
|
368
|
+
|
|
369
|
+
def refresh_lists(self, init: bool = False):
|
|
370
|
+
playlist_files = sorted(self.playlist_folder.glob("*.txt"))
|
|
371
|
+
if len(playlist_files) == 0:
|
|
372
|
+
raise FileNotFoundError(f"No files found in {self.playlist_folder}.")
|
|
373
|
+
|
|
374
|
+
df_playlists = pd.DataFrame({"playlist": sorted([Path(plf).name for plf in playlist_files])})
|
|
375
|
+
playlist_file = Path(playlist_files[0]).name
|
|
376
|
+
playlist_from_filename = lambda filename: parse_table((self.playlist_folder / filename).as_posix())
|
|
377
|
+
playlist_model = PandasModel(playlist_from_filename(playlist_file))
|
|
378
|
+
playlist_model.data_from_filename = playlist_from_filename
|
|
379
|
+
playlist_view = TableView(playlist_model)
|
|
380
|
+
playlist_view.setAlternatingRowColors(True)
|
|
381
|
+
|
|
382
|
+
# List of playlist files
|
|
383
|
+
playlists_model = PandasModel(df_playlists, editable=False)
|
|
384
|
+
playlists_view = TableView(playlists_model, playlist_model, self.playlist_folder)
|
|
385
|
+
playlists_view.setAlternatingRowColors(True)
|
|
386
|
+
playlists_view.folder = self.playlist_folder
|
|
387
|
+
playlists_view.selectRow(0)
|
|
388
|
+
|
|
389
|
+
# Protocols
|
|
390
|
+
protocol_files = sorted(self.protocol_folder.glob("*.yml"))
|
|
391
|
+
if len(protocol_files) == 0:
|
|
392
|
+
raise FileNotFoundError(f"No files found in {self.protocol_folder}.")
|
|
393
|
+
|
|
394
|
+
df_protocols = pd.DataFrame({"protocol": sorted([Path(plf).name for plf in protocol_files])})
|
|
395
|
+
# Content of selected protocol file
|
|
396
|
+
protocol_file = Path(protocol_files[0]).name
|
|
397
|
+
protocol_from_filename = lambda filename: from_yaml(load(self.protocol_folder / filename), readonly=False)
|
|
398
|
+
protocol_model = protocol_from_filename(protocol_file)
|
|
399
|
+
|
|
400
|
+
protocol_view = ParameterTree()
|
|
401
|
+
|
|
402
|
+
def set_protocol_model(parameter):
|
|
403
|
+
self.current_protocol = to_yaml(parameter)
|
|
404
|
+
parameter.sigTreeStateChanged.connect(self.on_protocol_changed)
|
|
405
|
+
protocol_view.protocol_model = parameter
|
|
406
|
+
protocol_view.setParameters(parameter, showTop=False)
|
|
407
|
+
|
|
408
|
+
set_protocol_model(protocol_model)
|
|
409
|
+
protocol_view.replaceData = set_protocol_model
|
|
410
|
+
protocol_view.data_from_filename = protocol_from_filename
|
|
411
|
+
|
|
412
|
+
# List of protocol files
|
|
413
|
+
protocols_model = PandasModel(df_protocols, editable=False)
|
|
414
|
+
protocols_view = TableView(protocols_model, protocol_view, self.protocol_folder)
|
|
415
|
+
protocols_view.setAlternatingRowColors(True)
|
|
416
|
+
protocols_view.folder = self.protocol_folder
|
|
417
|
+
protocols_view.selectRow(0)
|
|
418
|
+
|
|
419
|
+
if init:
|
|
420
|
+
self.playlist_view = playlist_view
|
|
421
|
+
self.playlists_view = playlists_view
|
|
422
|
+
self.protocol_view = protocol_view
|
|
423
|
+
self.protocols_view = protocols_view
|
|
424
|
+
# splitter = QSplitter(QtCore.Qt.Vertical)
|
|
425
|
+
# splitter.addWidget(self.playlists_view)
|
|
426
|
+
# splitter.addWidget(self.protocols_view)
|
|
427
|
+
|
|
428
|
+
# # self.layout.addWidget(splitter)
|
|
429
|
+
|
|
430
|
+
# splitter2 = QSplitter(QtCore.Qt.Vertical)
|
|
431
|
+
# splitter2.addWidget(self.playlist_view)
|
|
432
|
+
# splitter2.addWidget(self.protocol_view)
|
|
433
|
+
|
|
434
|
+
# splitterH = QSplitter(QtCore.Qt.Horizontal)
|
|
435
|
+
# splitterH.addWidget(splitter)
|
|
436
|
+
# splitterH.addWidget(splitter2)
|
|
437
|
+
# self.layout.addWidget(splitterH, 0, 1, 1, 1)
|
|
438
|
+
|
|
439
|
+
self.layout.addWidget(self.playlists_view, 0, 1, 1, 1)
|
|
440
|
+
self.layout.addWidget(self.playlist_view, 0, 2, 1, 5)
|
|
441
|
+
self.layout.addWidget(self.protocols_view, 1, 1, 1, 1)
|
|
442
|
+
self.layout.addWidget(self.protocol_view, 1, 2, 1, 5)
|
|
443
|
+
else:
|
|
444
|
+
self.layout.replaceWidget(self.playlists_view, playlists_view)
|
|
445
|
+
self.layout.replaceWidget(self.playlist_view, playlist_view)
|
|
446
|
+
self.layout.replaceWidget(self.protocols_view, protocols_view)
|
|
447
|
+
self.layout.replaceWidget(self.protocol_view, protocol_view)
|
|
448
|
+
self.playlist_view = playlist_view
|
|
449
|
+
self.playlists_view = playlists_view
|
|
450
|
+
self.protocol_view = protocol_view
|
|
451
|
+
self.protocols_view = protocols_view
|
|
452
|
+
|
|
453
|
+
def start(self, preview: bool = False):
|
|
454
|
+
if self.run_thread is not None and self.run_thread.is_alive():
|
|
455
|
+
return
|
|
456
|
+
|
|
457
|
+
msg = []
|
|
458
|
+
if self.playlists_view.selected_string is None:
|
|
459
|
+
msg.append("playlist")
|
|
460
|
+
|
|
461
|
+
if self.protocols_view.selected_string is None:
|
|
462
|
+
msg.append("protocol")
|
|
463
|
+
|
|
464
|
+
if len(msg):
|
|
465
|
+
dlg = QMessageBox(self)
|
|
466
|
+
dlg.setWindowTitle("Error: Could not start the experiment.")
|
|
467
|
+
dlg.setText(f"Please select a {' and a '.join(msg)}.")
|
|
468
|
+
dlg.exec_()
|
|
469
|
+
return
|
|
470
|
+
|
|
471
|
+
stop_event = threading.Event()
|
|
472
|
+
done_event = threading.Event()
|
|
473
|
+
|
|
474
|
+
kwargs = {
|
|
475
|
+
"playlistfile": (self.playlist_folder / self.playlists_view.selected_string).as_posix(),
|
|
476
|
+
"protocolfile": (self.protocol_folder / self.protocols_view.selected_string).as_posix(),
|
|
477
|
+
"protocol": self.current_protocol,
|
|
478
|
+
"debug": self.button["Debug"].isChecked(),
|
|
479
|
+
"show_progress": self.button["Progress"].isChecked(),
|
|
480
|
+
"monitor": True,
|
|
481
|
+
"save_prefix": None,
|
|
482
|
+
"preview": preview,
|
|
483
|
+
"_stop_event": stop_event,
|
|
484
|
+
"_done_event": done_event,
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
rich.print("Starting experiment with these args:")
|
|
488
|
+
rich.print(kwargs)
|
|
489
|
+
|
|
490
|
+
self.stop_event = stop_event
|
|
491
|
+
self.done_event = done_event
|
|
492
|
+
self.run_thread = threading.Thread(target=self.run_client, kwargs=kwargs, daemon=True)
|
|
493
|
+
self.set_run_buttons(True)
|
|
494
|
+
self.run_thread.start()
|
|
495
|
+
self.run_timer.start()
|
|
496
|
+
|
|
497
|
+
# dlg = RunDialog(stop_event, done_event, queue_total)
|
|
498
|
+
# dlg.exec_()
|
|
499
|
+
|
|
500
|
+
def run_client(self, **kwargs):
|
|
501
|
+
done_event = kwargs.get("_done_event")
|
|
502
|
+
try:
|
|
503
|
+
client.client(**kwargs)
|
|
504
|
+
except Exception:
|
|
505
|
+
logging.exception("Experiment failed.")
|
|
506
|
+
finally:
|
|
507
|
+
if done_event is not None:
|
|
508
|
+
done_event.set()
|
|
509
|
+
|
|
510
|
+
def request_stop(self):
|
|
511
|
+
if self.stop_event is None:
|
|
512
|
+
return
|
|
513
|
+
self.stop_event.set()
|
|
514
|
+
self.set_run_buttons(True, stopping=True)
|
|
515
|
+
|
|
516
|
+
def sync_run_state(self):
|
|
517
|
+
if self.run_thread is None:
|
|
518
|
+
self.run_timer.stop()
|
|
519
|
+
self.set_run_buttons(False)
|
|
520
|
+
return
|
|
521
|
+
|
|
522
|
+
if self.stop_event is not None and self.stop_event.is_set():
|
|
523
|
+
self.set_run_buttons(True, stopping=True)
|
|
524
|
+
|
|
525
|
+
if self.run_thread.is_alive():
|
|
526
|
+
return
|
|
527
|
+
|
|
528
|
+
if self.done_event is not None and not self.done_event.is_set():
|
|
529
|
+
return
|
|
530
|
+
|
|
531
|
+
self.run_timer.stop()
|
|
532
|
+
self.run_thread = None
|
|
533
|
+
self.stop_event = None
|
|
534
|
+
self.done_event = None
|
|
535
|
+
self.set_run_buttons(False)
|
|
536
|
+
|
|
537
|
+
def set_run_buttons(self, running: bool, stopping: bool = False):
|
|
538
|
+
self.button["Start"].setEnabled(not running)
|
|
539
|
+
self.button["Camera_preview"].setEnabled(not running)
|
|
540
|
+
self.button["Refresh lists"].setEnabled(not running)
|
|
541
|
+
self.button["Stop"].setEnabled(running and not stopping)
|
|
542
|
+
self.button["Stop"].setText("Stopping..." if stopping else "Stop")
|
|
543
|
+
|
|
544
|
+
def camera_preview(self):
|
|
545
|
+
self.start(preview=True)
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def main(protocol_folder: Optional[str] = None, playlist_folder: Optional[str] = None):
|
|
549
|
+
"""Opens the graphical user interface.
|
|
550
|
+
|
|
551
|
+
Args:
|
|
552
|
+
protocol_folder (Optional[str]): Folder with protocol files.
|
|
553
|
+
Defaults to value ['HEAD']['protocolfolder'] from `~/ethoconfig.yml`.
|
|
554
|
+
playlist_folder (Optional[str]): Folder with playlist files.
|
|
555
|
+
Defaults to value ['HEAD']['playlistfolder'] from `~/ethoconfig.yml`.
|
|
556
|
+
"""
|
|
557
|
+
app = QApplication(sys.argv)
|
|
558
|
+
icon = _system_icon(app)
|
|
559
|
+
app.setWindowIcon(icon)
|
|
560
|
+
|
|
561
|
+
m = MainWindow(protocol_folder, playlist_folder)
|
|
562
|
+
m.setWindowIcon(icon)
|
|
563
|
+
m.show()
|
|
564
|
+
|
|
565
|
+
sys.exit(app.exec_())
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
if __name__ == "__main__":
|
|
569
|
+
main()
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +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>
|