pvplot 0.7.0__tar.gz → 1.0.1__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: 0.7.0
3
+ Version: 1.0.1
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,51 @@
1
+ """ Pvplot configuration for litePeakSimulator, serving port 9710 at localhost.
2
+ The command line to start litePeakSimulator:
3
+ python3 -m liteserver.device.litePeakSimulator -ilo -p9710
4
+ """
5
+ configFormat='pvplot'
6
+
7
+ TITLE="PeakSimulator"
8
+ XLABEL = "Time (us)"
9
+ YLABEL = "V"
10
+ POINTS = 1000# data arrays will be rolled over after accumulating this number of points
11
+
12
+ """ The following attributes are not handled yet:
13
+ YES = 1
14
+ POLLPERIOD = 0
15
+ MINPOLLPERIOD = 0
16
+ POLLBEFOREASYNC = 1
17
+ AVERAGETYPE = none
18
+ LOGFORMAT = logger
19
+ LOGPERIODSEC = 0
20
+ LOGMETHOD = 'continuous'
21
+ LOGDESCRIPTION = ""
22
+ LOGCORRELATION = 'NOTREQUIRED'
23
+ FILLDATA = YES
24
+ LOGTREEPATH = '/operations/app_store/RunData/currentFill/'
25
+ PREFERREDLOGDISPLAY = Snapshot
26
+ DATASTAMPTYPE = 'WCTPERIOD'
27
+ WCTCORRPERIOD_MSEC = 1000
28
+ WCTCORRWINDOW_MSEC = 1000
29
+ SYNCHRONIZED = 0
30
+ YMINAUTOSCALE = 2
31
+ YMAXAUTOSCALE = 2
32
+ YLOGAXIS = 0
33
+ Y2LABEL = ""
34
+ Y2MINAUTOSCALE = 2
35
+ Y2MAXAUTOSCALE = 2
36
+ Y2LOGAXIS = 0
37
+ ERRORBARS = 0
38
+ FONTTYPE = 'Medium'
39
+ KEEPPREVIOUS = 0
40
+ """
41
+
42
+ dev='L:localhost;9710:dev1:'
43
+
44
+ DOCKS = [
45
+ {'YMax':f'device({dev}yMax)',
46
+ 'YMin':f'device({dev}yMin)',
47
+ 'Y[10]':f'device({dev}y[500])',
48
+ },
49
+ {'YvsX':(f'device({dev}x)',f'device({dev}y)'),
50
+ }
51
+ ]
pvplot-1.0.1/config.py ADDED
@@ -0,0 +1,48 @@
1
+ """ Pvplot configuration for litePeakSimulator, serving port 9710 at localhost.
2
+ The command line to start litePeakSimulator:
3
+ python3 -m liteserver.device.litePeakSimulator -ilo -p9710
4
+ """
5
+ configFormat='pvplot'
6
+ TITLE="PeakSimulator"
7
+
8
+ """ The following variables are not handled yet:
9
+ YES = 1
10
+ POLLPERIOD = 0
11
+ MINPOLLPERIOD = 0
12
+ POLLBEFOREASYNC = 1
13
+ AVERAGETYPE = none
14
+ LOGFORMAT = logger
15
+ LOGPERIODSEC = 0
16
+ LOGMETHOD = 'continuous'
17
+ LOGDESCRIPTION = ""
18
+ LOGCORRELATION = 'NOTREQUIRED'
19
+ FILLDATA = YES
20
+ LOGTREEPATH = '/operations/app_store/RunData/currentFill/'
21
+ PREFERREDLOGDISPLAY = Snapshot
22
+ XLABEL = "Time (us)"
23
+ YLABEL = "V"
24
+ DATASTAMPTYPE = 'WCTPERIOD'
25
+ WCTCORRPERIOD_MSEC = 1000
26
+ WCTCORRWINDOW_MSEC = 1000
27
+ SYNCHRONIZED = 0
28
+ YMINAUTOSCALE = 2
29
+ YMAXAUTOSCALE = 2
30
+ YLOGAXIS = 0
31
+ Y2LABEL = ""
32
+ Y2MINAUTOSCALE = 2
33
+ Y2MAXAUTOSCALE = 2
34
+ Y2LOGAXIS = 0
35
+ ERRORBARS = 0
36
+ FONTTYPE = 'Medium'
37
+ KEEPPREVIOUS = 0
38
+ """
39
+ dev='L:localhost;9710:dev1:'
40
+
41
+ DOCKS = [
42
+ {'YMax':f'device({dev}yMax)',
43
+ 'YMin':f'device({dev}yMin)',
44
+ 'Y[10]':f'device({dev}y[500])',
45
+ },
46
+ {'YvsX':(f'device({dev}x)',f'device({dev}y)'),
47
+ }
48
+ ]
@@ -0,0 +1,40 @@
1
+ configFormat='pvplot'
2
+ TITLE="Blue Injection Scope"
3
+ POLLPERIOD 0
4
+ MINPOLLPERIOD 0
5
+ POLLBEFOREASYNC 1
6
+ AVERAGETYPE none
7
+ LOGFORMAT logger
8
+ LOGPERIODSEC 0
9
+ LOGMETHOD continuous
10
+ LOGDESCRIPTION ""
11
+ LOGCORRELATION NOTREQUIRED
12
+ FILLDATA YES
13
+ LOGTREEPATH /operations/app_store/RunData/currentFill/
14
+ PREFERREDLOGDISPLAY Snapshot
15
+ XLABEL "Time (us)"
16
+ YLABEL "kV (at 1 V/div)"
17
+ DATASTAMPTYPE WCTPERIOD
18
+ WCTCORRPERIOD_MSEC 1000
19
+ WCTCORRWINDOW_MSEC 1000
20
+ SYNCHRONIZED 0
21
+ YMINAUTOSCALE 2
22
+ YMAXAUTOSCALE 2
23
+ YLOGAXIS 0
24
+ Y2LABEL ""
25
+ Y2MINAUTOSCALE 2
26
+ Y2MAXAUTOSCALE 2
27
+ Y2LOGAXIS 0
28
+ ERRORBARS 0
29
+ FONTTYPE Medium
30
+ KEEPPREVIOUS 0
31
+ SNAPREFRESHMODE 2
32
+ SNAPSUBCYCLES 1 2 3 4 5 6 7 8 9 10
33
+
34
+ dev='tek5Scope.inject7W_blu:'
35
+
36
+ #STATIC Time= 1.e6*device(tek5Scope.inject7W_blu:tAxis[*])
37
+ DOCKS =
38
+ [
39
+ {f'Module{i}':f'device({dev}c{i}WaveforM:value[*])*a+b' for i in [1,2,3,4]}
40
+ ]
@@ -17,6 +17,10 @@ def main():
17
17
  "Prefix, which will be added to all data objects, e.g: 'L:localhost:dev1:'")
18
18
  #TODO:parser.add_argument('-H', '--histogram', help=\
19
19
  # 'Plot the space-separated parameters as histograms')
20
+ parser.add_argument('-c','--configDir',default='/operations/app_store/pvplot',
21
+ help='Configuration directory')
22
+ parser.add_argument('-f', '--file', help=
23
+ 'Configuration file')
20
24
  parser.add_argument('-l', '--limit', type=int, default=1048576,
21
25
  help='Upper limit for number of points to store')
22
26
  parser.add_argument('-s', '--sleepTime', type=float, default=0.1,
@@ -2,4 +2,5 @@ txt="""
2
2
  Shortcuts
3
3
  ^s: Stop
4
4
  ^q: Continue
5
+ ^u: Unzoom
5
6
  """
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  """Plotting package for EPICS PVs, ADO and LITE parameters.
3
3
  """
4
- __version__ = 'v0.7.0 2024-07-24'# corrected vert. cursor for stripcharts, QShortcuts, --limit
4
+ __version__ = 'v1.0.1 2024-07-28'# sys.path.append(pargs.configDir,
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
@@ -17,6 +17,7 @@ from pyqtgraph import dockarea
17
17
  from functools import partial
18
18
  from collections import deque
19
19
  import traceback
20
+ from importlib import import_module
20
21
 
21
22
  #````````````````````````````Constants````````````````````````````````````````
22
23
  X,Y = 0,1
@@ -102,7 +103,6 @@ def get_pv(adopar:str, prop='value'):
102
103
  return val, ts
103
104
 
104
105
  def change_plotOption(curveName,color=None,width=None,symbolSize=None,scolor=None):
105
- printv('change_plotOption color,width,size,color: '+str((color,width,symbolSize,scolor)))
106
106
  dataset = MapOfDatasets.dtsDict[curveName]
107
107
  if color != None:
108
108
  prop = 'color'
@@ -135,27 +135,6 @@ def split_slice(parNameSlice):
135
135
  vslice = (r0, int(vrange[1]))
136
136
  return devParSlice[0], vslice
137
137
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
138
-
139
- def new_dock(dataset):
140
- docks = [x.split('.')[0] for x in MapOfDatasets.dtsDict]
141
- i = 0
142
- while '#'+str(i) in docks: i += 1
143
- v = '#'+str(i)+' '+dataset
144
- printv('adding plot: '+str(v))
145
-
146
- def close_dock(dname):
147
- """remove datasets and curves and close the dock widget"""
148
- print('closing dock '+dname)
149
- for curveName in MapOfDatasets.dtsDict.keys():
150
- printv('looking: '+curveName)
151
- dock = curveName.split('.')[0]
152
- if dock == dname:
153
- printv('removing: '+curveName)
154
- MapOfDatasets.remove(curveName)
155
- printv('MapOfDatasets.dtsDict: '+str(MapOfDatasets.dtsDict))
156
- PVPlot.mapOfDocks[dname].close()
157
- del PVPlot.mapOfPlotWidgets[dname]
158
-
159
138
  def update_data():
160
139
  """ called on QtCore.qTimer() event to update plots."""
161
140
  tstart = timer()
@@ -188,30 +167,25 @@ def get_statistics():
188
167
  txt += f'{key},\t{v["xrange"]},\t{v["mean"]},\t{v["std"]}\n'
189
168
  return txt
190
169
 
191
- def set_legend(dockName:str, state:bool):
170
+ def set_legend(dockNum:int, state:bool):
192
171
  if state: # legend enabled
193
- printv('add legend for '+str(dockName))
194
- widget = PVPlot.mapOfPlotWidgets[dockName]
172
+ printv(f'add legends to dock{dockNum}')
173
+ widget = PVPlot.mapOfPlotWidgets[dockNum]
195
174
  listOfItems = widget.getPlotItem().listDataItems()
196
175
  l = pg.LegendItem((100,60), offset=(70,30)) # args are (size, offset)
197
176
  l.setParentItem(widget.graphicsItem())
198
- PVPlot.legend[dockName] = l
177
+ PVPlot.legend[dockNum] = l
199
178
  for item in listOfItems:
200
179
  iname = item.name()
201
- txt = MapOfDatasets.dtsDict[iname].adoPars[0][0]
202
- # show only parameter name
203
- ltxt = txt.rsplit(':',1)[-1]
204
- if '[' in txt:
205
- ltxt = ':'.join(txt.rsplit(':',2)[-2:])
206
- printv('set_legend: '+iname+' par: '+ltxt)
207
- l.addItem(item, ltxt)
180
+ printv(f'set_legend {iname} in dock{dockNum}')
181
+ l.addItem(item, iname)
208
182
  else: # legend disabled
209
- printv('remove legend from '+dockName)
183
+ printv(f'remove legend from dock{dockNum}')
210
184
  try:
211
- PVPlot.legend[dockName].scene().removeItem(PVPlot.legend[dockName])
212
- del PVPlot.legend[dockName]
185
+ PVPlot.legend[dockNum].scene().removeItem(PVPlot.legend[dockNum])
186
+ del PVPlot.legend[dockNum]
213
187
  except Exception as e:
214
- printe('failed to remove legend '+dockName+':'+str(e))
188
+ printe('failed to remove legend '+dockNum+':'+str(e))
215
189
  #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
216
190
  #```````````````````````````DateAxis class: time scale for bottom plot scale``
217
191
  class DateAxis(pg.AxisItem):
@@ -241,7 +215,8 @@ class DateAxis(pg.AxisItem):
241
215
  class Dataset():
242
216
  """ dataset storage, keeps everything what is necessary to plot the curve.
243
217
  """
244
- def __init__(self,name,paramAndCount):
218
+ def __init__(self, dockNum:int, name, paramAndCount):
219
+ self.dockNum = dockNum
245
220
  self.name = name
246
221
  self.adoPars = paramAndCount # list of max 2 of (adoPar,count)
247
222
  self.plotItem = None # plotting object PlotDataItem
@@ -249,7 +224,6 @@ class Dataset():
249
224
  self.width = 1 # pen width
250
225
  self.lastTimePlotted = 0.
251
226
  self.lastTimeUpdated = 0.
252
- self.timestampReported = 0 # time of the last title update
253
227
  self.plotWidget = None
254
228
  self.viewBox = None
255
229
  # members for stripchart plot
@@ -273,55 +247,54 @@ class Dataset():
273
247
  self.statistics = {}
274
248
 
275
249
  # ``````````````````` Add plotItem ``````````````````````````````````````
276
- dock = name.split('.')[0]
277
- printv('plotItem for: '+str([s for s in self.adoPars])+', name:'+str(dock))
250
+ #dockNum = name.split('.')[0]
251
+ printv('plotItem for: '+str([s for s in self.adoPars])+', name:'+str(dockNum))
278
252
  initialWidth = 16
279
253
  self.data = [np.empty(initialWidth),np.empty(initialWidth)]# [X,U] data storage
280
254
  self.dataPtr = 0
281
255
  count = self.adoPars[0][1] #
282
256
  printv(f'adoPars,count: {self.adoPars,count}')
283
-
284
- # create plotItem with proper pen
285
- lineNumber = 0
286
- try: lineNumber = int(name.split('.')[1])
287
- except: pass
288
257
  isCorrelationPlot = len(self.adoPars) >= 2
289
- self.pen = pg.mkPen(lineNumber)
290
- if self.adoPars[0][0] == '':
291
- printv('no dataset - no plotItem')
292
- else:
293
- self.plotItem = pg.PlotDataItem(name=name, pen=self.pen)
294
258
 
295
259
  # assign the plotwidget
296
- if dock in PVPlot.mapOfPlotWidgets:
260
+ if dockNum in PVPlot.mapOfPlotWidgets:
297
261
  # dock already exist, use the existing plotwidget
298
- self.plotWidget = PVPlot.mapOfPlotWidgets[dock]
262
+ self.plotWidget = PVPlot.mapOfPlotWidgets[dockNum]
299
263
  self.viewBox = self.plotWidget.getViewBox()
300
264
  else:
301
- # new dock need to be created
265
+ # viewbox for new dock need to be created
302
266
  # create vewBox with plotwidget
303
- self.viewBox = CustomViewBox(dock, self)
267
+ self.viewBox = CustomViewBox(dockNum, self)
304
268
  self.viewBox.setMouseMode(self.viewBox.RectMode)
305
269
  self.viewBox.sigRangeChangedManually.connect(self.xrangeChanged)
306
- printv('Creating new dock:'+dock)
270
+ printv(f'Creating new dock{dockNum}')
307
271
  title = None
308
272
  if count == 1 and not isCorrelationPlot:
309
273
  self.plotWidget = pg.PlotWidget(title=title, viewBox=self.viewBox,
310
274
  axisItems={'bottom':DateAxis(orientation='bottom')})
311
275
  self.timeAxis = True
312
- if dock != '#0':
313
- self.plotWidget.setXLink(PVPlot.mapOfPlotWidgets['#0'])
276
+ if dockNum != 0:
277
+ self.plotWidget.setXLink(PVPlot.mapOfPlotWidgets[0])
314
278
  else:
315
279
  self.plotWidget = pg.PlotWidget(title=title, viewBox=self.viewBox)
316
280
  #self.plotWidget.showGrid(True,True)
317
- PVPlot.mapOfPlotWidgets[dock] = self.plotWidget
318
- PVPlot.mapOfDocks[dock].addWidget(self.plotWidget)
319
- if isCorrelationPlot:
320
- self.plotWidget.setLabel('bottom',self.adoPars[1][0])
321
- elif count == 1:
322
- self.plotWidget.setLabel('bottom','time', units='date', unitPrefix='')
281
+ PVPlot.mapOfPlotWidgets[dockNum] = self.plotWidget
282
+ PVPlot.mapOfDocks[dockNum].addWidget(self.plotWidget)
283
+ printv(f'docks: {PVPlot.mapOfDocks.keys()}, widgets: {PVPlot.mapOfPlotWidgets.keys()}')
284
+
285
+ c = PVPlot.config
286
+ #print(f'd:{self.dockNum}, X,Y: {c.XLABEL,c.YLABEL}')
287
+ if self.dockNum == 0 and c.YLABEL != 'LabelY':
288
+ self.plotWidget.setLabel('left',c.YLABEL)
289
+ if self.dockNum == 0 and c.XLABEL != 'LabelX':
290
+ self.plotWidget.setLabel('bottom',c.XLABEL)
323
291
  else:
324
- self.plotWidget.setLabel('bottom',PVPlot.scaleUnits[X][Units])
292
+ if isCorrelationPlot:
293
+ self.plotWidget.setLabel('bottom',self.adoPars[1][0])
294
+ elif count == 1:
295
+ self.plotWidget.setLabel('bottom','time', units='date', unitPrefix='')
296
+ else:
297
+ self.plotWidget.setLabel('bottom',PVPlot.scaleUnits[X][Units])
325
298
 
326
299
  # set X and Y ranges
327
300
  rangeMap = {X: (PVPlot.pargs.xrange, self.plotWidget.setXRange),
@@ -333,6 +306,14 @@ class Dataset():
333
306
  r = [float(i) for i in v[0].split(':')]
334
307
  func(*r)
335
308
 
309
+ # create plotItem with proper pen
310
+ lineNumber = len(PVPlot.mapOfPlotWidgets[self.dockNum].getPlotItem().listDataItems())
311
+ self.pen = pg.mkPen(lineNumber)
312
+ if self.adoPars[0][0] == '':
313
+ printv('no dataset - no plotItem')
314
+ else:
315
+ self.plotItem = pg.PlotDataItem(name=name, pen=self.pen)
316
+
336
317
  if self.plotItem:
337
318
  self.plotWidget.addItem(self.plotItem)
338
319
  self.lastTimePlotted = 0.
@@ -455,8 +436,8 @@ class Dataset():
455
436
  self.dataPtr = ptr
456
437
 
457
438
  # re-alocate arrays,if necessary
458
- #print(f'ptr: {ptr,self.data[Y].shape[0]}')
459
- if (ptr <= PVPlot.pargs.limit/2) & (ptr >= self.data[Y].shape[0]):
439
+ if (ptr >= self.data[Y].shape[0]):
440
+ #print(f'realllocate: ptr: {ptr,self.data[Y].shape[0]}')
460
441
  tmp = self.data
461
442
  self.data = [np.empty(self.data[Y].shape[0] * 2),
462
443
  np.empty(self.data[Y].shape[0] * 2)]
@@ -504,46 +485,44 @@ class Dataset():
504
485
  class MapOfDatasets():
505
486
  """Global dictionary of Datasets, provides safe methods to add and remove
506
487
  the datasets"""
507
- dtsDict = {}
488
+ dtsDict = {} #{curveName:dataset,,,}
508
489
 
509
- def add(name, adoPars):
490
+ def add(dockNum:int, mapOfCurves):
510
491
  """add new datasets, the adoPars is the space delimited string of
511
492
  source ado:parameters."""
512
- printv(f'>MapOfDatasets.add({adoPars})')
513
- if name in MapOfDatasets.dtsDict:
514
- printv('Need to remove '+name)
515
- MapOfDatasets.remove(name)
516
- for i, token in enumerate(adoPars.split()):
517
- dname = f'{name}.{i}'
518
- pnameAndCount = [];
519
- alist = token.split(',')
520
- #alist = alist[:2] # we cannot handle more than 2 curves in correlation plot
521
- if len(alist) == 0:
522
- #MapOfDatasets.dtsDict[dname] = Dataset(dname,[('',0)])
523
- #print(f'added dataset {str(MapOfDatasets.dtsDict[dname])}')
524
- print(f'Logic error: MapOfDatasets({adoPars})')
525
- sys.exit(1)
493
+ printv(f'>MapOfDatasets.add({dockNum, mapOfCurves})')
494
+ for i, kv in enumerate(mapOfCurves.items()):
495
+ curveName,devList = kv
496
+ printv(f'curveName: {curveName,devList}')
497
+ if isinstance(devList,str):
498
+ devList = [devList]
526
499
  else:
527
- alist.reverse()
528
- for adoPar in alist:
529
- ap = PVPlot.pargs.prefix+adoPar
530
- try:
531
- printv(f'check if {ap}, is alive')
532
- valts = get_pv(ap) # check if parameter is alive
533
- if valts is None:
534
- printw('Could not add {ap}')
535
- return 2
536
- except Exception as e:
537
- printw(f'Exception in getting parameter {ap}')
538
- return 1
539
- val,ts = valts
540
- newName = ap
541
- try: count = len(val)
542
- except: count = 1
543
- pnameAndCount.append((newName,count))
544
- printv('adding '+str(pnameAndCount)+' to datasets['+dname+']')
545
- MapOfDatasets.dtsDict[dname] = Dataset(dname,pnameAndCount)
546
- printv(f'MapOfDatasets: {[(k,v.adoPars) for k,v in MapOfDatasets.dtsDict.items()]}')
500
+ devList = list(devList)
501
+ devList.reverse()
502
+ pnameAndCount = []
503
+ for adoPar in devList:
504
+ adoPar = adoPar.lstrip()#remove leading whitespaces
505
+ printv(f'adoPar: {adoPar}')
506
+ if adoPar.startswith('device('):
507
+ e = adoPar.index(')')
508
+ rest = adoPar[e+1:]# it could be arithmetics
509
+ adoPar = adoPar[7:e]
510
+ try:
511
+ printv(f'check if {adoPar}, is alive')
512
+ valts = get_pv(adoPar) # check if parameter is alive
513
+ if valts is None:
514
+ printw('Could not add {adoPar}')
515
+ return 2
516
+ except Exception as e:
517
+ printw(f'Exception in getting parameter {adoPar}: {e}')
518
+ return 1
519
+ val,ts = valts
520
+ try: count = len(val)
521
+ except: count = 1
522
+ pnameAndCount.append((adoPar,count))
523
+ printv('adding '+str(pnameAndCount)+' to datasets['+curveName+']')
524
+ MapOfDatasets.dtsDict[curveName] = Dataset(dockNum, curveName, pnameAndCount)
525
+ printv(f'MapOfDatasets: {[(k,v.adoPars) for k ,v in MapOfDatasets.dtsDict.items()]}')
547
526
  return 0
548
527
 
549
528
  def remove(name):
@@ -552,7 +531,7 @@ class MapOfDatasets():
552
531
  dataset.plotWidget.removeItem(dataset.plotItem)
553
532
  del MapOfDatasets.dtsDict[dataset.name]
554
533
 
555
- class PopupWindow(QW.QWidget):
534
+ class PopupWindow(QW.QWidget):
556
535
  """ This "window" is a QWidget. If it has no parent, it
557
536
  will appear as a free-floating window as we want.
558
537
  Note: The created window will not be closed on app exit.
@@ -573,12 +552,12 @@ class PopupWindow(QW.QWidget):
573
552
  class CustomViewBox(pg.ViewBox):
574
553
  """ defines actions, activated on the right mouse click in the dock
575
554
  """
576
- def __init__(self, name, dataset):
577
- #self.dockName = kwds['name'] # cannot use name due to an issue in demo
555
+ def __init__(self, dockNum:int, dataset):
556
+ #self.dockNum = kwds['name'] # cannot use name due to an issue in demo
578
557
  #del kwds['name'] # the name in ViewBox.init fails in demo
579
- self.dockName = name
558
+ self.dockNum = dockNum
580
559
  self.dataset = dataset# master dataset, it defines horizontal axis
581
- #print('CustomViewBox: '+str(self.dockName))
560
+ #print('CustomViewBox: '+str(self.dockNum))
582
561
 
583
562
  # call the init method of the parent class
584
563
  super(CustomViewBox, self).__init__()
@@ -607,9 +586,9 @@ class CustomViewBox(pg.ViewBox):
607
586
  if self.menu:
608
587
  printv('menu exist')
609
588
  return self.menu
610
- printv('getContextMenus for '+str(self.dockName))
589
+ printv('getContextMenus for '+str(self.dockNum))
611
590
  self.menu = ViewBoxMenu(self)
612
- self.menu.setTitle(str(self.dockName)+ " options..")
591
+ self.menu.setTitle(f'dock{self.dockNum} options..')
613
592
 
614
593
  # unzoom last
615
594
  unzoom = self.menu.addAction("&UnZoom")
@@ -631,13 +610,13 @@ class CustomViewBox(pg.ViewBox):
631
610
  action.triggered.connect(partial(self.cursorAction,cursor))
632
611
 
633
612
  labelX = QW.QWidgetAction(self.menu)
634
- self.labelXGui = QW.QLineEdit('LabelX')
613
+ self.labelXGui = QW.QLineEdit(PVPlot.config.XLABEL)
635
614
  self.labelXGui.returnPressed.connect(
636
615
  lambda: self.set_label('bottom',self.labelXGui))
637
616
  labelX.setDefaultWidget(self.labelXGui)
638
617
  self.menu.addAction(labelX)
639
618
  labelY = QW.QWidgetAction(self.menu)
640
- self.labelYGui = QW.QLineEdit('LabelY')
619
+ self.labelYGui = QW.QLineEdit(PVPlot.config.YLABEL)
641
620
  self.labelYGui.returnPressed.connect(
642
621
  lambda: self.set_label('left',self.labelYGui))
643
622
  labelY.setDefaultWidget(self.labelYGui)
@@ -687,7 +666,7 @@ class CustomViewBox(pg.ViewBox):
687
666
 
688
667
  def cursorAction(self, direction):
689
668
  angle = {'Vertical':90, 'Horizontal':0}[direction]
690
- pwidget = PVPlot.mapOfPlotWidgets[self.dockName]
669
+ pwidget = PVPlot.mapOfPlotWidgets[self.dockNum]
691
670
  vid = {'Vertical':0, 'Horizontal':1}[direction]
692
671
  vr = pwidget.getPlotItem().viewRange()
693
672
  #print(f'vid: {vid,vr[vid]}')
@@ -704,7 +683,7 @@ class CustomViewBox(pg.ViewBox):
704
683
  def cursorPositionChanged(self, cursor):
705
684
  pos = cursor.value()
706
685
  horizontal = cursor.angle == 0.
707
- pwidget = PVPlot.mapOfPlotWidgets[self.dockName]
686
+ pwidget = PVPlot.mapOfPlotWidgets[self.dockNum]
708
687
  viewRange = pwidget.getPlotItem().viewRange()[horizontal]
709
688
  if pos > viewRange[1]:
710
689
  pwidget.removeItem(cursor)
@@ -715,21 +694,21 @@ class CustomViewBox(pg.ViewBox):
715
694
  def changed_datasetOptions(self):
716
695
  """Dialog Plotting Options"""
717
696
  dlg = QW.QDialog()
718
- dlg.setWindowTitle("Dataset plotting config")
697
+ dlg.setWindowTitle(f"Dataset of dock{self.dockNum}")
719
698
  dlg.setWindowModality(QtCore.Qt.ApplicationModal)
720
699
  dlgSize = 500,200
721
700
  dlg.setMinimumSize(*dlgSize)
722
701
  rowCount,columnCount = 0,6
723
702
  tbl = QW.QTableWidget(rowCount, columnCount, dlg)
724
- tbl.setHorizontalHeaderLabels(['Dataset','Color','Width','Symbol','Size','Color'])
725
- for column,width in ((1,30),(3,50),(5,30)): # change column widths
703
+ tbl.setHorizontalHeaderLabels(['Name','PV','Color','Width','Symbol','Size','Color'])
704
+ for column,width in ((0,50),(1,100),(2,30),(3,80),(4,40),(5,80)): # change column widths
726
705
  tbl.setColumnWidth(column, width)
727
706
  tbl.setShowGrid(False)
728
707
  tbl.setSizeAdjustPolicy(
729
708
  QW.QAbstractScrollArea.AdjustToContents)
730
709
  tbl.resize(*dlgSize)
731
710
 
732
- listOfItems = PVPlot.mapOfPlotWidgets[self.dockName].getPlotItem().listDataItems()
711
+ listOfItems = PVPlot.mapOfPlotWidgets[self.dockNum].getPlotItem().listDataItems()
733
712
  for row,dataitem in enumerate(listOfItems):
734
713
  tbl.insertRow(row)
735
714
  curveName = dataitem.name()
@@ -738,16 +717,15 @@ class CustomViewBox(pg.ViewBox):
738
717
  adoparName = dataset.adoPars[0][0]
739
718
 
740
719
  printv(f'dataset:{adoparName}')
741
- item = QW.QTableWidgetItem(adoparName.rsplit(':',1)[1])
742
- #DNW#item.setTextAlignment(QtCore.Qt.AlignRight)
743
- tbl.setItem(row, 0, item)
720
+ tbl.setItem(row, 0, QW.QTableWidgetItem(curveName))
721
+ tbl.setItem(row, 1, QW.QTableWidgetItem(adoparName))
744
722
 
745
723
  # color button for line
746
724
  colorButton = pg.ColorButton(color=dataset.pen.color())
747
725
  colorButton.setObjectName(curveName)
748
726
  colorButton.sigColorChanging.connect(lambda x:
749
727
  change_plotOption(str(self.sender().objectName()),color=x.color()))
750
- tbl.setCellWidget(row, 1, colorButton)
728
+ tbl.setCellWidget(row, 2, colorButton)
751
729
 
752
730
  # slider for changing the line width
753
731
  widthSlider = QW.QSlider()
@@ -757,14 +735,14 @@ class CustomViewBox(pg.ViewBox):
757
735
  widthSlider.setValue(1)
758
736
  widthSlider.valueChanged.connect(lambda x:
759
737
  change_plotOption(str(self.sender().objectName()),width=x))
760
- tbl.setCellWidget(row, 2, widthSlider)
738
+ tbl.setCellWidget(row, 3, widthSlider)
761
739
 
762
740
  # symbol, selected from a comboBox
763
741
  self.symbol = QW.QComboBox() # TODO: why self?
764
742
  for symbol in ' ostd+x': self.symbol.addItem(symbol)
765
743
  self.symbol.setObjectName(curveName)
766
744
  self.symbol.currentIndexChanged.connect(self.set_symbol)
767
- tbl.setCellWidget(row, 3, self.symbol)
745
+ tbl.setCellWidget(row, 4, self.symbol)
768
746
 
769
747
  # slider for changing the line width
770
748
  symbolSizeSlider = QW.QSlider()
@@ -774,14 +752,14 @@ class CustomViewBox(pg.ViewBox):
774
752
  symbolSizeSlider.setValue(1)
775
753
  symbolSizeSlider.valueChanged.connect(lambda x:
776
754
  change_plotOption(str(self.sender().objectName()),symbolSize=x))
777
- tbl.setCellWidget(row, 4, symbolSizeSlider)
755
+ tbl.setCellWidget(row, 5, symbolSizeSlider)
778
756
 
779
757
  # color button for symbol
780
758
  symbolColorButton = pg.ColorButton(color=dataset.pen.color())
781
759
  symbolColorButton.setObjectName(curveName)
782
760
  symbolColorButton.sigColorChanging.connect(lambda x:
783
761
  change_plotOption(str(self.sender().objectName()),scolor=x.color()))
784
- tbl.setCellWidget(row, 5,symbolColorButton)
762
+ tbl.setCellWidget(row, 6,symbolColorButton)
785
763
  dlg.exec_()
786
764
 
787
765
  def set_symbol(self, x):
@@ -803,7 +781,7 @@ class CustomViewBox(pg.ViewBox):
803
781
  pass
804
782
 
805
783
  def set_label(self,side,labelGui):
806
- dock,label = self.dockName,str(labelGui.text())
784
+ dock,label = self.dockNum,str(labelGui.text())
807
785
  printv('changed_label '+side+': '+str((dock,label)))
808
786
  PVPlot.mapOfPlotWidgets[dock].setLabel(side,label, units='')
809
787
  # it might be useful to return the prompt back:
@@ -811,8 +789,7 @@ class CustomViewBox(pg.ViewBox):
811
789
 
812
790
  def set_legend(self, state):
813
791
  state = (state==QtCore.Qt.Checked)
814
- print(f'set_legend {state}')
815
- set_legend(self.dockName, state)
792
+ set_legend(self.dockNum, state)
816
793
 
817
794
  def set_stop(self, state):
818
795
  PVPlot.stop(state == QtCore.Qt.Checked)
@@ -871,42 +848,64 @@ def callback(args):
871
848
  printv(f'axis={axis}, units={units}, scale={scale}')
872
849
  PVPlot.scaleUnits[axis][Scale] = scale
873
850
 
874
- def add_curves(dock:str, adopars:str):
851
+ def add_curves(dockNum:int, curveMap:str):
875
852
  # if dock name is new then create new dock, otherwise extend the
876
853
  # existing one with new curve
877
854
 
878
- curves = [x for x in MapOfDatasets.dtsDict]
879
- docks = [x.split('.')[0] for x in curves]
855
+ #curves = [x for x in MapOfDatasets.dtsDict]
856
+ #docks = [x.split('.')[0] for x in curves]
857
+ curves = MapOfDatasets.dtsDict.keys()
858
+ docks = PVPlot.mapOfDocks.keys()
880
859
  printv(f'>addcurves curves,docks:{curves,docks}')
881
- if dock in docks:
882
- printv('extending dock '+str(dock))
883
- for i in range(MaxCurvesPerPlot):
884
- newSlot = dock+'.'+str(i+1)
885
- if newSlot not in curves: break
886
- dock = newSlot
887
- else:
888
- printv('adding new dock '+dock)
889
- PVPlot.mapOfDocks[dock] = dockarea.Dock(dock, size=(500,200), hideTitle=True)
890
- if dock == '#0':
891
- PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dock], 'right', closable=True)
860
+ if dockNum not in docks:
861
+ printv(f'adding new dock{dockNum}')
862
+ PVPlot.mapOfDocks[dockNum] = dockarea.Dock(str(dockNum),
863
+ size=(500,200), hideTitle=True)
864
+ if dockNum == 0:
865
+ PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dockNum], 'right',
866
+ closable=True)
892
867
  else:
893
- PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dock],
894
- 'top', PVPlot.mapOfDocks['#0'], closable=True) #TODO:closable does not work
895
- if MapOfDatasets.add(dock, adopars):
896
- printe('in add_curves: '+str((dock, adopars)))
868
+ PVPlot.dockArea.addDock(PVPlot.mapOfDocks[dockNum],
869
+ 'top', PVPlot.mapOfDocks[0], closable=True) #TODO:closable does not work
870
+ if MapOfDatasets.add(dockNum, curveMap):
871
+ printe(f'in add_curves: {dockNum, curveMap}')
897
872
 
898
873
  def excepthook(exc_type, exc_value, exc_tb):
899
874
  """To uncover exceptions, missed in Qt"""
900
875
  tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
901
876
  print("error caught!:")
902
877
  print("error message:\n", tb)
903
- QtWidgets.QApplication.quit()
904
- # or QtWidgets.QApplication.exit(0)
878
+ QApplication.quit()
879
+ # or QApplication.exit(0)
880
+
881
+ class tmpClass():
882
+ DOCKS = [{}]
883
+
884
+ def parse_input_parameters(pargs):
885
+ fn = pargs.file
886
+ if fn:
887
+ sys.path.append(pargs.configDir)
888
+ printv(f'importing {fn}')
889
+ try:
890
+ ConfigModule = import_module(fn)
891
+ configFormat = ConfigModule.configFormat
892
+ except ModuleNotFoundError as e:
893
+ printe(f'Trying to import {pargs.configDir}/{fn}: {e}')
894
+ sys.exit(0)
895
+ return ConfigModule
896
+ else:
897
+ for parm in pargs.parms.split():
898
+ parms = (pargs.prefix+parm).split(',')
899
+ if len(parms) == 2:
900
+ parms = (parms[0],pargs.prefix+parms[1])
901
+ tmpClass.DOCKS[0][parm] = parms
902
+ return tmpClass
905
903
 
906
904
  class PVPlot():
905
+ config = None
907
906
  pargs = None
908
- mapOfDocks = {}
909
907
  mapOfPlotWidgets = {}
908
+ mapOfDocks = {}
910
909
  padding = 0.1
911
910
  scaleUnits = [[1,'Sample'],[1,'Count']]
912
911
  subscribedParMap = {}
@@ -925,7 +924,7 @@ class PVPlot():
925
924
 
926
925
  def start():
927
926
  pargs = PVPlot.pargs
928
- print(f'pargs: {PVPlot.pargs}')
927
+ printv(f'pargs: {PVPlot.pargs}')
929
928
 
930
929
  try: os.environ["QT_SCALE_FACTOR"] = str(pargs.zoomin)
931
930
  except: pass
@@ -938,8 +937,6 @@ class PVPlot():
938
937
  pg.setConfigOption('background', 'w')
939
938
  pg.setConfigOption('foreground', 'k')
940
939
 
941
- PVPlot.qWin.setWindowTitle(f'pvplot {pargs.parms}')
942
-
943
940
  # Shortcuts
944
941
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+H"), PVPlot.qWin)
945
942
  shortcut.activated.connect(PVPlot.actionHelp)
@@ -947,27 +944,33 @@ class PVPlot():
947
944
  shortcut.activated.connect(partial(PVPlot.actionStop,True))
948
945
  shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+Q"), PVPlot.qWin)
949
946
  shortcut.activated.connect(partial(PVPlot.actionStop,False))
950
- #shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+U"), PVPlot.qWin)
951
- #shortcut.activated.connect(partial(PVPlot.actionStop,False))
947
+ shortcut = QW.QShortcut(QtGui.QKeySequence("Ctrl+U"), PVPlot.qWin)
948
+ shortcut.activated.connect(PVPlot.actionUnzoom)
952
949
  from . import helptxt
953
950
  PVPlot.helptxt = helptxt.txt
954
951
 
955
- # plots for other docks
956
- if pargs.dock:
957
- for par in pargs.dock:
958
- dock = par[0][0]
959
- adopar = par[0][1:].lstrip()
960
- dock = '#'+dock
961
- add_curves(dock, adopar)
962
- else:
963
- # plots for the main dock
964
- add_curves('#0', pargs.parms)
952
+ #``````````process configuration file
953
+ if pargs.file is not None:
954
+ PVPlot.config = parse_input_parameters(pargs)
955
+
956
+ try: pargs.limit = PVPlot.config.POINTS
957
+ except: pass
958
+
959
+ try: title = PVPlot.config.TITLE
960
+ except: title = title = f'pvplot {pargs.parms}'
961
+ PVPlot.qWin.setWindowTitle(title)
962
+ dockList = PVPlot.config.DOCKS
963
+ for dockNum,curveMap in enumerate(dockList):
964
+ printv(f'add_curves to dock{dockNum}, {curveMap}')
965
+ add_curves(dockNum, curveMap)
966
+ #,,,,,,,,,,
967
+
965
968
  if len(MapOfDatasets.dtsDict) == 0:
966
969
  printe(f'No datasets created')
967
970
  sys.exit(1)
968
971
 
969
- for dock in PVPlot.mapOfDocks:
970
- set_legend(str(dock), True)
972
+ for dockNum in PVPlot.mapOfDocks:
973
+ set_legend(dockNum, True)
971
974
 
972
975
  # Subscriptions. Only LITE system is supported.
973
976
  if pargs.xscale is not None:
@@ -1004,19 +1007,25 @@ class PVPlot():
1004
1007
  print('Application exited')
1005
1008
  sys.exit(ret)
1006
1009
 
1007
- def actionStop(state:bool):
1008
- print(f'actionStop {state}')
1009
- PVPlot.stop(state)
1010
-
1011
1010
  def stop(state):
1012
- print(f'>PVPlot.stop {state}')
1013
1011
  PVPlot.stopped = state
1014
1012
  if state == True:
1015
1013
  PVPlot.qTimer.stop()
1016
1014
  else:
1017
1015
  PVPlot.qTimer.start(int(PVPlot.pargs.sleepTime*1000))
1018
1016
 
1017
+ #``````````Shorthcut handlers
1019
1018
  def actionHelp():
1020
1019
  PVPlot.helpWin = PopupWindow()
1021
1020
  PVPlot.helpWin.label.setText(PVPlot.helptxt)
1022
1021
  PVPlot.helpWin.show()
1022
+
1023
+ def actionStop(state:bool):
1024
+ PVPlot.stop(state)
1025
+
1026
+ def actionUnzoom():
1027
+ md = PVPlot.mapOfDocks
1028
+ docks = md.keys()
1029
+ for dockNum in docks:
1030
+ vb = PVPlot.mapOfPlotWidgets[dockNum].getPlotItem().getViewBox()
1031
+ vb.unzoom()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pvplot"
7
- version = "0.7.0"
7
+ version = "1.0.1"
8
8
  authors = [
9
9
  { name="Andrei Sukhanov", email="cyxandr@gmail.com" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes