42 from typing
import Any, Callable, Dict, List, Tuple
45 import pyqtgraph
as pg
46 from PyQt5
import QtGui, QtWidgets
47 from PyQt5.QtCore
import QObject, QThread, QTimer, pyqtSignal
48 from PyQt5.uic
import loadUiType
49 from pyqtgraph.dockarea
import Dock, DockArea
55 return loadUiType(os.environ[
"SHESHA_ROOT"] +
56 "/shesha/widgets/%s.ui" % moduleName)
59 BaseWidgetTemplate, BaseClassTemplate =
uiLoader(
'widget_base')
65 """x and y are 2D arrays of shape (Nplots, Nsamples)"""
66 connect = np.ones(x.shape, dtype=bool)
68 self.
path = pg.arrayToQPath(x.flatten(), y.flatten(), connect.flatten())
69 pg.QtGui.QGraphicsPathItem.__init__(self, self.
path)
70 self.setPen(pg.mkPen(
'r'))
73 return pg.QtGui.QGraphicsItem.shape(self)
81 def __init__(self, parent=None, hide_histograms=False) -> None:
82 BaseClassTemplate.__init__(self, parent=parent)
93 if self.
uiBase.wao_Display.isChecked():
103 self.
uiBase.wao_DisplayDock.setWidget(self.
area)
119 self.
uiBase.wao_frameRate.setValue(2)
121 self.
uiBase.wao_load_config.setDisabled(
False)
122 self.
uiBase.wao_init.setDisabled(
True)
134 self.
uiBase.wao_frameRate.setDisabled(state)
144 reply = QtWidgets.QMessageBox.question(
145 self,
'Message',
"Are you sure to quit?", QtWidgets.QMessageBox.Yes |
146 QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
148 if reply == QtWidgets.QMessageBox.Yes:
160 def saveArea(self, widget, filename=None):
162 Callback when a area layout file is double clicked in the file browser
163 Place the selected file name in the browsing drop-down menu,
164 the call the self.load_config callback of the load button.
167 filepath = QtWidgets.QFileDialog(
169 self,
"Select area layout file",
"",
170 "area layout file (*.area);;all files (*)")
171 filename = filepath[0]
174 with open(filename,
"w+")
as f:
175 st = self.
area.saveState()
177 except FileNotFoundError
as err:
178 warnings.warn(filename +
" not loaded: " + err)
182 if disp_checkbox.text() == name:
183 disp_checkbox.setChecked(
True)
185 if name
in self.
docks.keys():
189 typ, contents, _ = state
200 disp_checkbox.setChecked(
False)
201 for dock
in self.
docks.values():
206 filepath = QtWidgets.QFileDialog(
208 self,
"Select area layout file",
"",
209 "area layout file (*.area);;all files (*)")
210 filename = filepath[0]
213 with open(filename,
"r")
as f:
214 st = eval(f.readline())
217 if st[
'main']
is not None:
221 for win
in st[
"float"]:
225 self.
area.restoreState(st)
226 except FileNotFoundError
as err:
227 warnings.warn(filename +
"not loaded: " + err)
231 Callback when a config file is double clicked in the file browser
232 Place the selected file name in the browsing drop-down menu,
233 the call the self.load_config callback of the load button.
235 filepath = QtWidgets.QFileDialog(directory=self.
defaultParPath).getOpenFileName(
236 self,
"Select parameter file",
"",
237 "parameters file (*.py);;hdf5 file (*.h5);;all files (*)")
239 self.
uiBase.wao_selectConfig.clear()
240 self.
uiBase.wao_selectConfig.addItem(str(filepath[0]))
245 guilty_guy = self.sender().text()
246 state = self.sender().isChecked()
248 self.
area.addDock(self.
docks[guilty_guy])
249 elif self.
docks[guilty_guy].isVisible():
250 self.
docks[guilty_guy].close()
252 def add_dispDock(self, name: str, parent, type: str =
"pg_image") -> Dock:
253 checkBox = QtGui.QCheckBox(name, parent)
255 checkableAction = QtGui.QWidgetAction(parent)
256 checkableAction.setDefaultWidget(checkBox)
257 parent.addAction(checkableAction)
262 if type ==
"pg_image":
263 img = pg.ImageItem(border=
'w')
264 self.
imgs[name] = img
266 viewbox = pg.ViewBox()
268 viewbox.setAspectLocked(
True)
271 iv = pg.ImageView(view=viewbox, imageItem=img)
272 viewbox.invertY(
False)
275 iv.ui.histogram.hide()
276 iv.ui.histogram.autoHistogramRange()
277 iv.ui.histogram.setMaximumWidth(100)
281 elif type ==
"pg_plot":
282 img = pg.PlotItem(border=
'w')
283 self.
imgs[name] = img
287 self.
imgs[name] = img
295 Callback when 'LOAD' button is hit
298 self.
uiBase.wao_phasesgroup_tb, self.
uiBase.wao_imagesgroup_tb,
299 self.
uiBase.wao_graphgroup_tb
301 layout = groupbox.menu()
302 while layout
and not layout.isEmpty():
303 w = layout.children()[0]
304 layout.removeAction(w)
309 for _, dock
in self.
docks.items():
319 self.
uiBase.wao_phasesgroup_tb.setText(
'Select')
320 self.
uiBase.wao_phasesgroup_tb.setPopupMode(QtWidgets.QToolButton.InstantPopup)
324 self.
uiBase.wao_graphgroup_tb.setText(
'Select')
325 self.
uiBase.wao_graphgroup_tb.setPopupMode(QtWidgets.QToolButton.InstantPopup)
327 self.
uiBase.wao_imagesgroup_tb.setText(
'Select')
330 self.
uiBase.wao_imagesgroup_tb.setPopupMode(QtWidgets.QToolButton.InstantPopup)
343 self.
uiBase.wao_selectConfig.clear()
344 self.
uiBase.wao_selectConfig.addItems([
345 parlist[i].
split(
'/')[-1]
for i
in range(len(parlist))
350 self.
uiBase.wao_load_config.setDisabled(
True)
351 self.
uiBase.wao_init.setDisabled(
True)
360 self.uiBase.wao_load_config.setDisabled(
False)
361 self.uiBase.wao_init.setDisabled(
False)
362 self.loopLock.release()
365 if not self.
loopLock.acquire(
False):
373 def addSHGrid(self, pg_image, valid_sub, sspsize, pitch):
378 nssp_tot = valid_sub[0].size
379 connect = np.ones((nssp_tot, 5), dtype=bool)
381 roi_x = np.ones((nssp_tot, 5), dtype=int)
382 roi_y = np.ones((nssp_tot, 5), dtype=int)
383 for idx_ssp
in range(nssp_tot):
384 (x, y) = (valid_sub[0][idx_ssp], valid_sub[1][idx_ssp])
385 roi_x[idx_ssp, :] = [x, x, x + sspsize, x + sspsize, x]
386 roi_y[idx_ssp, :] = [y, y + sspsize, y + sspsize, y, y]
392 print(text, end=
'\r', flush=
True)
397 QTimer.singleShot(0, self.
run)
403 QThread.__init__(self)