pvplot 1.3.3__tar.gz → 1.3.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pvplot
3
- Version: 1.3.3
3
+ Version: 1.3.5
4
4
  Summary: Plotting tool for EPICS PVs, ADO and LITE parameters
5
5
  Project-URL: Homepage, https://github.com/ASukhanov/pvplot
6
6
  Project-URL: Bug Tracker, https://github.com/ASukhanov/pvplot/issues
@@ -0,0 +1,191 @@
1
+ """Basic EPICS access API using caproto threading.
2
+ The API is similar to cad_io.
3
+ The devPar argument is tuple (deviceName,parameterName).
4
+ The EPICS PV name is concatenation of the deviceName and parameterName
5
+
6
+ For example: epics.get(('testAPD:scope1:','MaxValue_RBV')) returns
7
+ {('testAPD:scope1:', 'MaxValue_RBV'): {'value': 1.5620877339306638, 'timestamp': 1681488886.923712, 'alarm': 0}}
8
+ """
9
+ __version__ = 'v0.0.2 2023-04-14'# No colon separation when splitting PV name to (device,parameter) tuple.
10
+
11
+ #from time import perf_counter as timer
12
+
13
+ from caproto.threading.client import Context
14
+ _Ctx = Context()
15
+
16
+ _PVCache = {}# cache of PVs
17
+ # the key is EPICS PV name, the fields are as follows:
18
+ _PVC_PV = 0# EPICS PV object
19
+ _PVC_CB = 1# callback
20
+ _PVC_Props = 2# PV properties
21
+ _PVC_DevPar = 3# (deviceName, ParameterName)
22
+
23
+ _Subscriptions = []# list of EPICS PV subscriptions
24
+
25
+ _CA_data_type_STRING = 14
26
+
27
+ _dbg = False
28
+ def _printd(msg):
29
+ if _dbg:
30
+ print(f'CPAccess:{msg}')
31
+
32
+ def init():
33
+ return
34
+
35
+ def _get_pv(devPar:tuple):
36
+ pvName = ''.join(devPar)
37
+ r = _PVCache.get(pvName)
38
+ if r is None:
39
+ _printd(f'register pv {pvName} {devPar}')
40
+ pv,*_ = _Ctx.get_pvs(''.join(pvName), timeout=2)
41
+ _PVCache[pvName] = [pv, None, None, devPar]
42
+ _fill_PVCacheProps(pv)
43
+ else:
44
+ pv,*_ = r
45
+ return pv
46
+
47
+ def _fill_PVCacheProps(pv):
48
+ pvName = pv.name
49
+ pvData = pv.read(data_type='time')
50
+ val = pvData.data
51
+ if len(val) == 1:
52
+ try:
53
+ # treat it as numpy
54
+ val = pvData.data[0].item()
55
+ except:
56
+ # data is not numpy
57
+ val = pvData.data[0]
58
+
59
+ # get properties
60
+ #ISSUE: the caproto reports timestamp as float, the precision for float64
61
+ #presentation is ~300ns
62
+ featureBit2Letter = {1:'R', 2:'WE'}
63
+ featureCode = pv.access_rights
64
+ features = ''
65
+ for bit, letter in featureBit2Letter.items():
66
+ if bit & featureCode:
67
+ features += letter
68
+ pvControl = pv.read(data_type='control')
69
+ #_printd(f'pvcontrol {pvName}: {pvControl}')
70
+ datatype = pvControl.data_type
71
+ #_printd(f'data_type:{datatype}')
72
+ if datatype == _CA_data_type_STRING:# convert text bytearray to str
73
+ val = val.decode()
74
+ props = {'value':val}
75
+ props['timestamp'] = pvData.metadata.timestamp
76
+ props['count'] = len(pvData.data)
77
+ props['features'] = features
78
+ try:
79
+ props['units'] = pvControl.metadata.units.decode()
80
+ if props['units'] == '': props['units'] = None
81
+ except: pass
82
+
83
+ try: props['engLow'] = pvControl.metadata.lower_ctrl_limit
84
+ except: pass
85
+
86
+ try:
87
+ props['engHigh'] = pvControl.metadata.upper_ctrl_limit
88
+ if props['engHigh'] == 0.0 and props['engHigh'] == 0.0:
89
+ props['engHigh'], props['engLow'] = None, None
90
+ except: pass
91
+
92
+ try:
93
+ props['alarm'] = pvControl.metadata.severity
94
+ #_printd(f'status {pvControl.metadata.severity}')
95
+ if props['alarm'] == 17:# UDF
96
+ props['alarm'] = None
97
+ except: pass
98
+
99
+ try: # legalValues
100
+ enum_strings = pvControl.metadata.enum_strings
101
+ props['legalValues'] = [i.decode() for i in enum_strings]
102
+ props['value'] = props['legalValues'][val]
103
+ except:
104
+ #props['legalValues'] = None
105
+ if 'legalValues' in props:
106
+ del props['legalValues']
107
+ #_printd(f'_props {props}')
108
+ _PVCache[pvName][_PVC_Props] = props
109
+
110
+ def info(devPar:tuple):
111
+ """Abridged PV info"""
112
+ pvName = ''.join(devPar)
113
+ pv = _get_pv(devPar)
114
+ return {devPar:_PVCache[pvName][_PVC_Props]}
115
+
116
+ def get(devPar:tuple, *args, **kwargs):
117
+ '''Returns devPar-keyed map of PV properties: {'value','timestamp'...}'''
118
+ pvName = ''.join(devPar)
119
+ pv = _get_pv(devPar)
120
+ pvData = pv.read(data_type='time')
121
+ rDict = _unpack_ReadNotifyResponse(pvName, pvData)
122
+ return rDict
123
+
124
+ def set(devParValue:tuple):
125
+ '''Sets the PV value. The devParValue is (deviceName, ParameterName, value)
126
+ '''
127
+ dev, par, value = devParValue
128
+ #print(f'epicsAccess.set({dev,par,value})')
129
+ pvName = ''.join((dev,par))
130
+ pv = _get_pv((dev,par))
131
+ try: # if PV has legalValues then the value should be index of legalValues
132
+ value = _PVCache[pvName][_PVC_Props]['legalValues'].index(value)
133
+ except Exception as e:
134
+ #print(f'in epicsAccess.set. Value not in legalValues: {e}')
135
+ pass
136
+ pv.write(value)
137
+ return 1
138
+
139
+ def _unpack_ReadNotifyResponse(pvName:str, pvData):
140
+ val = pvData.data
141
+ if len(val) == 1:
142
+ try: #it as numpy
143
+ val = pvData.data[0].item()
144
+ except: # it is not numpy
145
+ val = pvData.data[0]
146
+ #_printd(f'pvData:{pvData}')
147
+ #_printd(f'val:{val}, {pvData.data_type}')
148
+ if pvData.data_type == _CA_data_type_STRING:
149
+ val = val.decode()
150
+
151
+ legalValues = _PVCache[pvName][_PVC_Props].get('legalValues')
152
+ if legalValues is not None:
153
+ #rDict['value'] = legalValues[int(val)]
154
+ val = legalValues[int(val)]
155
+ alarm = pvData.metadata.severity
156
+ key = _PVCache[pvName][_PVC_DevPar]
157
+ rDict = {key: {'value':val\
158
+ , 'timestamp':pvData.metadata.timestamp, 'alarm': alarm}}
159
+ return rDict
160
+
161
+ def _callback(subscription, pvData):
162
+ #tMark = [timer(), 0., 0.]
163
+ pvName = subscription.pv.name
164
+ _printd(f'>epicsAccess._callback: {pvName}')#{pvData})')
165
+ rDict = _unpack_ReadNotifyResponse(pvName, pvData)
166
+ #tMark[1] = timer()
167
+ cache = _PVCache.get(pvName)
168
+ cb = cache[_PVC_CB]
169
+ if cb:
170
+ cb(rDict)
171
+ #tMark[2] = timer() - tMark[1]
172
+ #tMark[1] -= tMark[0]
173
+ ##_printd(f'caproto cb times {tMark}')# 20-30 uS
174
+
175
+ def subscribe(callback:callable, devPar:tuple):
176
+ '''Subscribe callback method to changes of PVs, defined by devPar'''
177
+ pvName = ''.join(devPar)
178
+ pv = _get_pv(devPar)
179
+ subscription = pv.subscribe(data_type='time')
180
+ _PVCache[pvName][_PVC_CB] = callback
181
+ subscription.add_callback(_callback)
182
+ _Subscriptions.append(subscription)
183
+
184
+ def unsubscribe():
185
+ '''Unsubscribe all subscriptions'''
186
+ global _Subscriptions
187
+ for subscription in _Subscriptions:
188
+ #print(f'>epicsAccess clear subs: {subscription}')
189
+ subscription.clear()
190
+ _Subscriptions = []
191
+
@@ -0,0 +1,5 @@
1
+ txt="""Shortcuts:
2
+ ^m: Show statistics: mean, sigma, peak2peak of visible curves.
3
+ ^s: Stop/Start
4
+ ^u: Unzoom
5
+ """
@@ -321,6 +321,12 @@ class Dataset():
321
321
  self.plotWidget.addItem(self.plotItem)
322
322
  self.lastTimePlotted = 0.
323
323
 
324
+ def add_plot(self):
325
+ self.plotWidget.addItem(self.plotItem)
326
+
327
+ def remove_plot(self):
328
+ self.plotWidget.removeItem(self.plotItem)
329
+
324
330
  def __str__(self):
325
331
  return f'Dataset {self.name}, x: {self.data[X].shape}'
326
332
 
@@ -346,12 +352,10 @@ class Dataset():
346
352
  self.viewBox.setXRange(self.viewXRange[0], self.viewXRange[1])
347
353
 
348
354
  def plot(self, ts):
349
- # Plot the dataset
350
- print(f'>plot: {self.name, self.enabled}')
351
- if not self.enabled:
352
- return
355
+ # Plot the dataset. It may be several updates between these calls.
353
356
  if self.lastTimePlotted == ts:
354
357
  return
358
+ printv(f'>plot: {self.name}')
355
359
  self.lastTimePlotted = ts
356
360
  #print(f'>plot: {self.name, {self.dataPtr}, round(ts,3)}')
357
361
  x = self.data[X][:self.dataPtr]
@@ -376,9 +380,6 @@ class Dataset():
376
380
 
377
381
  def update_plot(self, time2plot):
378
382
  curvePars = self.adoPars
379
- if not self.enabled:
380
- return
381
- print(f'update_plot: {self.name,curvePars}')
382
383
  yd,ts = None,None
383
384
  try:
384
385
  #Limitation: only one (first) curve will be plotted
@@ -390,10 +391,11 @@ class Dataset():
390
391
  if ts:
391
392
  if ts == self.lastTimeUpdated:
392
393
  self.dataChanged = False
393
- #print(f'curve {self.name} did not change {round(ts,3)}')
394
- if time2plot:
395
- self.plot(ts)
394
+ printv(f'curve {self.name} did not change {round(ts,3)}')
395
+ #if time2plot:
396
+ # self.plot(ts)
396
397
  return
398
+ printv(f'update_plot: {self.name,curvePars}')
397
399
  self.dataChanged = True
398
400
  self.lastTimeUpdated = ts
399
401
  #printv(f'update_plot: {curvePars}, data:{yd}')
@@ -531,6 +533,7 @@ class MapOfDatasets():
531
533
  pnameAndCount.append((adoPar,count))
532
534
  printv('adding '+str(pnameAndCount)+' to datasets['+curveName+']')
533
535
  MapOfDatasets.dtsDict[curveName] = Dataset(dockNum, curveName, pnameAndCount)
536
+ PVPlot.mapOfCurves[dockNum].append(curveName)
534
537
  printv(f'MapOfDatasets: {[(k,v.adoPars) for k ,v in MapOfDatasets.dtsDict.items()]}')
535
538
  return 0
536
539
 
@@ -717,22 +720,21 @@ class CustomViewBox(pg.ViewBox):
717
720
  tbl.setShowGrid(False)
718
721
  tbl.setSizeAdjustPolicy(
719
722
  QW.QAbstractScrollArea.AdjustToContents)
720
- tbl.resize(*dlgSize)
723
+ #tbl.resize(*dlgSize)
724
+ tbl.resize()
721
725
 
722
- listOfItems = PVPlot.mapOfPlotWidgets[self.dockNum].getPlotItem().listDataItems()
723
- for row,dataitem in enumerate(listOfItems):
726
+ for row,curveName in enumerate(PVPlot.mapOfCurves[self.dockNum]):
724
727
  tbl.insertRow(row)
725
- curveName = dataitem.name()
726
728
  printv(f'curveName:{curveName}')
729
+ dataset = MapOfDatasets.dtsDict[curveName]
727
730
  col = 0
728
731
  cbox = QW.QCheckBox()
729
- cbox.setChecked(True)
732
+ cbox.setChecked(dataset.enabled)
730
733
  #cbox.stateChanged.connect(lambda x: self.enable_dataset(x))
731
734
  cbox.stateChanged.connect(self.enable_dataset)
732
735
  cbox.setObjectName(curveName)
733
736
  tbl.setCellWidget(row, col, cbox)
734
737
  col+=1
735
- dataset = MapOfDatasets.dtsDict[curveName]
736
738
  adoparName = dataset.adoPars[0][0]
737
739
  tbl.setItem(row, col, QW.QTableWidgetItem(curveName))
738
740
  col+=1
@@ -856,7 +858,10 @@ class CustomViewBox(pg.ViewBox):
856
858
  def enable_dataset(self, state):
857
859
  dtsetName = str(self.sender().objectName())
858
860
  print(f'enable_dataset {dtsetName, (state==QtCore.Qt.Checked)}')
859
- MapOfDatasets.dtsDict[dtsetName].enabled = (state==QtCore.Qt.Checked)
861
+ dataset = MapOfDatasets.dtsDict[dtsetName]
862
+ enabled = (state==QtCore.Qt.Checked)
863
+ dataset.enabled = enabled
864
+ dataset.add_plot() if enabled else dataset.remove_plot()
860
865
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
861
866
 
862
867
  def callback(args):
@@ -891,6 +896,7 @@ def add_curves(dockNum:int, curveMap:str):
891
896
  else:
892
897
  PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dockNum],
893
898
  'top', PVPlot.mapOfDocks[0], closable=True) #TODO:closable does not work
899
+ PVPlot.mapOfCurves[dockNum] = []
894
900
  if MapOfDatasets.add(dockNum, curveMap):
895
901
  printe(f'in add_curves: {dockNum, curveMap}')
896
902
 
@@ -928,8 +934,9 @@ def parse_input_parameters(pargs):
928
934
  class PVPlot():
929
935
  config = None
930
936
  pargs = None
931
- mapOfPlotWidgets = {}
932
- mapOfDocks = {}
937
+ mapOfPlotWidgets = {}# active plotItems
938
+ mapOfDocks = {}# dockAreas
939
+ mapOfCurves = {}
933
940
  padding = 0.1
934
941
  scaleUnits = [[1,'Sample'],[1,'Count']]
935
942
  subscribedParMap = {}
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env python3
2
2
  """Plotting package for EPICS PVs, ADO and LITE parameters.
3
3
  """
4
- __version__ = 'v1.3.3 2024-08-21'# Statistics shows full name of parameter
4
+ __version__ = 'v1.3.5 2024-10-23'# cad_epics integrated
5
5
  #TODO: if backend times out the gui is not responsive
6
6
  #TODO: move Add Dataset to Dataset options
7
7
  #TODO: add dataset arithmetics
8
- #TODO: Use rich text in statistics, make it as table or use pprint
9
8
 
10
9
  import sys, os, time, datetime
11
10
  timer = time.perf_counter
@@ -64,7 +63,7 @@ def prettyDict(rDict, lineLimit=75):
64
63
  r += croppedText(f' {parVals}',lineLimit)+'\n'
65
64
  return r
66
65
 
67
- try: from cad_epics import epics as EPICSAccess
66
+ try: from pvplot import cad_epics as EPICSAccess
68
67
  except Exception as e:
69
68
  EPICSAccess = None
70
69
  printw(f'EPICS devices are not supported on this host: {e}')
@@ -147,23 +146,118 @@ def split_slice(parNameSlice):
147
146
  else:
148
147
  vslice = (r0, int(vrange[1]))
149
148
  return devParSlice[0], vslice
149
+
150
+ def get_statistics():
151
+ statList = []
152
+ for dataset in MapOfDatasets.dtsDict.values():
153
+ #if dataset.dockNum != PVPlot.statDock:
154
+ # continue
155
+ s = dataset.get_statistics()
156
+ #print(f's: {s}')
157
+ if len(s) != 0:
158
+ for key,v in s.items():
159
+ statList.append([key, *v["xrange"],
160
+ f'{v["mean"]:.6g}', f'{v["std"]:.6g}',
161
+ f'{v["p2p"]:.6g}'])
162
+ return statList
163
+
164
+ class PopupWindow(QW.QWidget):
165
+ """ This "window" is a QWidget. If it has no parent, it
166
+ will appear as a free-floating window as we want.
167
+ Note: The created window will not be closed on app exit.
168
+ To make it happen, the MainWindow should call close this widget in its closeEvent()
169
+ """
170
+ def __init__(self):
171
+ super().__init__()
172
+ qr = PVPlot.qWin.geometry()
173
+ self.setGeometry(QtCore.QRect(qr.x(), qr.y(), 0, 0))
174
+ self.setWindowTitle('Statistics')
175
+ layout = QW.QVBoxLayout()
176
+ self.label = QW.QLabel()
177
+ self.label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
178
+ layout.addWidget(self.label)
179
+ self.setLayout(layout)
180
+
181
+ class TableModel(QtCore.QAbstractTableModel):
182
+ def __init__(self, data, headers):
183
+ super(TableModel, self).__init__()
184
+ self._data = data
185
+ self.headers = headers
186
+
187
+ def headerData(self, section: int, orientation: QtCore.Qt.Orientation, role=QtCore.Qt.DisplayRole):
188
+ if role == QtCore.Qt.DisplayRole and orientation == QtCore.Qt.Horizontal:
189
+ try: r = self.headers[section]
190
+ except: r = f's{section+1}'
191
+ return r
192
+
193
+ def data(self, index, role):
194
+ if role == QtCore.Qt.DisplayRole:
195
+ # See below for the nested-list data structure.
196
+ # .row() indexes into the outer list,
197
+ # .column() indexes into the sub-list
198
+ return self._data[index.row()][index.column()]
199
+
200
+ def rowCount(self, parent=QtCore.QModelIndex()):
201
+ # The length of the outer list.
202
+ return len(self._data)
203
+
204
+ def columnCount(self, parent=QtCore.QModelIndex()):
205
+ # The following takes the first sub-list, and returns
206
+ # the length (only works if all rows are an equal length)
207
+ return len(self._data[0])
208
+
209
+ def refresh_data(self, data):
210
+ self._data = data
211
+ #print(f'>refresh_data: {self._data}')
212
+ topLeft = self.createIndex(0, 0)
213
+ bottomRight = self.createIndex(self.rowCount(), self.columnCount())
214
+ self.dataChanged.emit(topLeft, bottomRight)
215
+
216
+ class TableWindow(QW.QWidget):
217
+ """
218
+ This "window" is a QWidget. If it has no parent, it
219
+ will appear as a free-floating window.
220
+ """
221
+ def __init__(self, data, headers=[]):
222
+ super().__init__()
223
+ self.setWindowTitle('Statistics')
224
+ layout = QW.QVBoxLayout()
225
+ self.table = QW.QTableView()
226
+ self.model = TableModel(data, headers)
227
+ self.table.setModel(self.model)
228
+ hh = self.table.horizontalHeader()
229
+ #DNW#hh.setSectionResizeMode(QW.QHeaderView.ResizeToContents)
230
+ #hh.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
231
+ hh.setSectionResizeMode(0, QW.QHeaderView.ResizeMode.ResizeToContents)
232
+ hh.setSectionResizeMode(1, QW.QHeaderView.ResizeMode.ResizeToContents)
233
+ hh.setSectionResizeMode(2, QW.QHeaderView.ResizeMode.ResizeToContents)
234
+ layout.addWidget(self.table)
235
+ self.setLayout(layout)
236
+
237
+ qr = PVPlot.qWin.geometry()
238
+ '''
239
+ vh = self.table.verticalHeader()
240
+ extra = (30,30)
241
+ sz = (hh.length() + vh.width() + extra[X],
242
+ vh.length() + hh.height() + extra[Y])
243
+ self.setGeometry(QtCore.QRect(qr.x(), qr.y(), sz[0], sz[1]))
244
+ '''
245
+ self.move(qr.x(), qr.y())
246
+ self.table.setShowGrid(False)
247
+ self.table.setSizeAdjustPolicy(
248
+ QW.QAbstractScrollArea.AdjustToContents)
150
249
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
151
250
  def update_data():
152
251
  """ called on QtCore.qTimer() event to update plots."""
153
252
  tstart = timer()
154
253
  tt = round(time.time(),6)
155
- if tt > PVPlot.lastPlotTime + PVPlot.minPlottingPeriod:
156
- time2plot = True
157
- PVPlot.lastPlotTime = tt
158
- else:
159
- time2plot = False
160
254
 
161
255
  for dataset in MapOfDatasets.dtsDict.values():
162
- dataset.update_plot(time2plot)
256
+ dataset.update_plot()
163
257
  if dataset.dataChanged:
164
- printvv(f'updating {dataset.adoPars}')
165
- if PVPlot.statisticsWindow is None:
166
- continue
258
+ if tt > dataset.lastPlotted + PVPlot.minPlottingPeriod:
259
+ dataset.lastPlotted = tt
260
+ dataset.plot(tt)
167
261
 
168
262
  if PVPlot.perfmon:
169
263
  v = timer()-tstart
@@ -248,6 +342,7 @@ class Dataset():
248
342
  self.timeAxis = False
249
343
  self.statistics = {}
250
344
  self.enabled = True
345
+ self.lastPlotted = 0
251
346
 
252
347
  # ``````````````````` Add plotItem ``````````````````````````````````````
253
348
  #dockNum = name.split('.')[0]
@@ -382,7 +477,7 @@ class Dataset():
382
477
  #TODO:pxMode = self.pxMode,
383
478
  )
384
479
 
385
- def update_plot(self, time2plot):
480
+ def update_plot(self):
386
481
  curvePars = self.adoPars
387
482
  yd,ts = None,None
388
483
  try:
@@ -457,9 +552,6 @@ class Dataset():
457
552
  self.data[X][:tmp[X].shape[0]] = tmp[X]
458
553
  #printi(f'adjust {self.name} from {tmp[X].shape} to {self.data[X].shape}')
459
554
 
460
- if time2plot:
461
- self.plot(ts)
462
-
463
555
  def _visibleRange(self):
464
556
  npt = self.dataPtr
465
557
  #print(f'viewRange={self.viewBox.viewRange()}')
@@ -545,23 +637,6 @@ class MapOfDatasets():
545
637
  dataset = MapOfDatasets.dtsDict[name]
546
638
  dataset.plotWidget.removeItem(dataset.plotItem)
547
639
  del MapOfDatasets.dtsDict[dataset.name]
548
-
549
- class PopupWindow(QW.QWidget):
550
- """ This "window" is a QWidget. If it has no parent, it
551
- will appear as a free-floating window as we want.
552
- Note: The created window will not be closed on app exit.
553
- To make it happen, the MainWindow should call close this widget in its closeEvent()
554
- """
555
- def __init__(self):
556
- super().__init__()
557
- qr = PVPlot.qWin.geometry()
558
- self.setGeometry(QtCore.QRect(qr.x(), qr.y(), 0, 0))
559
- self.setWindowTitle('Statistics')
560
- layout = QW.QVBoxLayout()
561
- self.label = QW.QLabel()
562
- self.label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
563
- layout.addWidget(self.label)
564
- self.setLayout(layout)
565
640
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
566
641
  #`````````````````````````````````````````````````````````````````````````````
567
642
  class CustomViewBox(pg.ViewBox):
@@ -613,10 +688,10 @@ class CustomViewBox(pg.ViewBox):
613
688
  setDatasets = self.menu.addAction('Datasets &Options')
614
689
  setDatasets.triggered.connect(self.changed_datasetOptions)
615
690
 
616
- _statistics = self.menu.addAction('&Print Statistics')
691
+ _statistics = self.menu.addAction('Show &Mean,sigma')
617
692
  _statistics.triggered.connect(self.show_statistics)
618
693
 
619
- _yProjection = self.menu.addAction('Show yProjection')
694
+ _yProjection = self.menu.addAction('Show &YProjection')
620
695
  _yProjection.triggered.connect(self.show_yProjection)
621
696
 
622
697
  cursorMenu = self.menu.addMenu('Add &Cursor')
@@ -638,7 +713,7 @@ class CustomViewBox(pg.ViewBox):
638
713
  self.menu.addAction(labelY)
639
714
 
640
715
  backgroundAction = QW.QWidgetAction(self.menu)
641
- backgroundGui = QW.QCheckBox('&Black background')
716
+ backgroundGui = QW.QCheckBox('Black background')
642
717
  backgroundGui.stateChanged.connect(
643
718
  lambda x: self.setBackgroundColor(\
644
719
  'k' if x == QtCore.Qt.Checked else 'w'))
@@ -646,7 +721,7 @@ class CustomViewBox(pg.ViewBox):
646
721
  self.menu.addAction(backgroundAction)
647
722
 
648
723
  legenAction = QW.QWidgetAction(self.menu)
649
- legendGui = QW.QCheckBox('&Legend')
724
+ legendGui = QW.QCheckBox('Legend')
650
725
  legendGui.setChecked(True)
651
726
  legendGui.stateChanged.connect(lambda x: self.set_legend(x))
652
727
  legenAction.setDefaultWidget(legendGui)
@@ -845,7 +920,7 @@ class CustomViewBox(pg.ViewBox):
845
920
 
846
921
  def show_statistics(self):
847
922
  #print(f'print statistics for {self.dockNum}')
848
- PVPlot.statDock = self.dockNum
923
+ #PVPlot.statDock = self.dockNum
849
924
  PVPlot.actionStatistics()
850
925
 
851
926
  def show_yProjection(self):
@@ -856,7 +931,7 @@ class CustomViewBox(pg.ViewBox):
856
931
 
857
932
  PVPlot.yProjectionWindow.show()
858
933
  PVPlot.yProjectionWindow.setWindowTitle(
859
- f'Vertical projection of {self.dataset.adoPars[0][0].rsplit(":",1)[1]}')
934
+ f'Vertical projection of {self.dataset.name}')
860
935
  self.dataset.show_yProjection()
861
936
 
862
937
  def enable_dataset(self, state):
@@ -936,6 +1011,15 @@ def parse_input_parameters(pargs):
936
1011
  tmpClass.DOCKS[0][parm] = parms
937
1012
  return tmpClass
938
1013
 
1014
+ class MainWindow(QW.QMainWindow):
1015
+ def closeEvent(self,event):
1016
+ print('Closing all windows')
1017
+ try: PVPlot.statisticsWindow.close()
1018
+ except: pass
1019
+ try: PVPlot.helpWin.close()
1020
+ except: pass
1021
+ event.accept()
1022
+
939
1023
  class PVPlot():
940
1024
  config = None
941
1025
  pargs = None
@@ -957,7 +1041,7 @@ class PVPlot():
957
1041
  yProjectionWindow = None
958
1042
  yProjectionPlotItem = None
959
1043
  stopped = False
960
- statDock = 0
1044
+ #statDock = 0
961
1045
 
962
1046
  def start():
963
1047
  pargs = PVPlot.pargs
@@ -966,7 +1050,7 @@ class PVPlot():
966
1050
  try: os.environ["QT_SCALE_FACTOR"] = str(pargs.zoomin)
967
1051
  except: pass
968
1052
  qApp = QApplication([])
969
- PVPlot.qWin = QMainWindow()
1053
+ PVPlot.qWin = MainWindow()
970
1054
  PVPlot.dockArea = dockarea.DockArea()
971
1055
  PVPlot.qWin.setCentralWidget(PVPlot.dockArea)
972
1056
  PVPlot.qWin.resize(1000,500)
@@ -977,12 +1061,12 @@ class PVPlot():
977
1061
  # Shortcuts
978
1062
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+H"), PVPlot.qWin)
979
1063
  shortcut.activated.connect(PVPlot.actionHelp)
980
- shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+P"), PVPlot.qWin)
1064
+ shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+M"), PVPlot.qWin)
981
1065
  shortcut.activated.connect(partial(PVPlot.actionStatistics))
1066
+ #shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+O"), PVPlot.qWin)
1067
+ #shortcut.activated.connect(partial(PVPlot.actionDatasetOptions))
982
1068
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+S"), PVPlot.qWin)
983
1069
  shortcut.activated.connect(partial(PVPlot.actionStop))
984
- #shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+Q"), PVPlot.qWin)
985
- #shortcut.activated.connect(partial(PVPlot.actionStop,False))
986
1070
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+U"), PVPlot.qWin)
987
1071
  shortcut.activated.connect(PVPlot.actionUnzoom)
988
1072
  from . import helptxt
@@ -1090,22 +1174,10 @@ class PVPlot():
1090
1174
 
1091
1175
  def actionStatistics():
1092
1176
  #print(f'>actionStatistics {PVPlot.statDock}')
1093
- def get_statistics():
1094
- statistics = {}
1095
- for dataset in MapOfDatasets.dtsDict.values():
1096
- if dataset.dockNum != PVPlot.statDock:
1097
- continue
1098
- s = dataset.get_statistics()
1099
- if len(s) != 0:
1100
- statistics.update(s)
1101
- txt = ('Parameter\t\tRange \tMean \tSTD \tPeak2Peak\n'
1102
- '---------\t\t------\t------\t------\t---------\n')
1103
- for key,v in statistics.items():
1104
- txt += f'{key}:\t{v["xrange"]}\t{v["mean"]:.6g}\t{v["std"]:.6g}\t{v["p2p"]:.6g}\n'
1105
- return txt
1177
+ sl = get_statistics()
1106
1178
  if PVPlot.statisticsWindow is None:
1107
- PVPlot.statisticsWindow = PopupWindow()
1108
- txt = get_statistics()
1109
- PVPlot.statisticsWindow.label.setText(txt)
1110
- PVPlot.statisticsWindow.show()
1111
- PVPlot.statistics = {}
1179
+ header = ['Parameter','XMin','XMax','Mean','StDev','Peak2Peak']
1180
+ PVPlot.statisticsWindow = TableWindow(sl, header)
1181
+ PVPlot.statisticsWindow.model.refresh_data(sl)
1182
+ PVPlot.statisticsWindow.show()
1183
+
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pvplot"
7
- version = "1.3.3"
7
+ version = "1.3.5"
8
8
  authors = [
9
9
  { name="Andrei Sukhanov", email="cyxandr@gmail.com" },
10
10
  ]