-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathQSpsWidget.py
More file actions
1133 lines (1022 loc) · 48.3 KB
/
Copy pathQSpsWidget.py
File metadata and controls
1133 lines (1022 loc) · 48.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#/*##########################################################################
# Copyright (C) 2004-2023 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__author__ = "E. Papillon, V.A. Sole - ESRF"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import logging
from PyMca5.PyMcaIO import spswrap as sps
from PyMca5.PyMcaGui import PyMcaQt as qt
from PyMca5.PyMcaGui.io import SpecFileCntTable
from PyMca5.PyMcaGui.plotting import MaskImageWidget
QTVERSION = qt.qVersion()
from PyMca5.PyMcaGui.plotting import PyMca_Icons as icons
_logger = logging.getLogger(__name__)
SOURCE_TYPE = 'SPS'
SCAN_MODE = True
class QGridLayout(qt.QGridLayout):
def addMultiCellWidget(self, w, r0, r1, c0, c1, *var):
self.addWidget(w, r0, c0, 1 + r1 - r0, 1 + c1 - c0)
class SPSFramesMcaWidget(qt.QWidget):
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setContentsMargins(0, 0, 0, 0)
self.mainLayout.setSpacing(0)
self.graphWidget = MaskImageWidget.MaskImageWidget(self,
imageicons=False,
selection=False)
self.graph = self.graphWidget.graphWidget.graph
self.mainLayout.addWidget(self.graphWidget)
def setInfo(self, info):
self.setDataSize(info["rows"], info["cols"])
self.setTitle(info["Key"])
self.info=info
def setDataSource(self, data):
self.data = data
self.data.sigUpdated.connect(self._update)
dataObject = self._getDataObject()
self.graphWidget.setImageData(dataObject.data)
self.lastDataObject = dataObject
def _update(self, ddict):
targetwidgetid = ddict.get('targetwidgetid', None)
if targetwidgetid not in [None, id(self)]:
return
dataObject = self._getDataObject(ddict['Key'],
selection=None)
if dataObject is not None:
self.graphWidget.setImageData(dataObject.data)
self.lastDataObject = dataObject
def _getDataObject(self, key=None, selection=None):
if key is None:
key = self.info['Key']
dataObject = self.data.getDataObject(key,
selection=None,
poll=False)
if dataObject is not None:
dataObject.info['legend'] = self.info['Key']
dataObject.info['imageselection'] = False
dataObject.info['scanselection'] = False
dataObject.info['targetwidgetid'] = id(self)
self.data.addToPoller(dataObject)
return dataObject
def setDataSize(self,rows,cols,selsize=None):
self.rows= rows
self.cols= cols
if self.cols<=self.rows:
self.idx='cols'
else:
self.idx='rows'
def setTitle(self, title):
self.graph.setTitle("%s"%title)
def getSelection(self):
keys = {"plot":self.idx,"x":0,"y":1}
return [keys]
class SPSScanArrayWidget(SpecFileCntTable.SpecFileCntTable):
def setInfo(self, info):
_logger.debug("info = %s", info)
if "LabelNames" in info:
# new style
cntList = info.get("LabelNames", [])
self.build(cntList)
return
elif "envdict" in info:
# old style
if len(info["envdict"].keys()):
#We have environment information
if "datafile" in info["envdict"]:
if info["envdict"]["datafile"] != "/dev/null":
_logger.debug("I should send a signal, either from here or from the parent to the dispatcher")
_logger.debug("SPEC data file = %s", info["envdict"]["datafile"])
#usefull keys = ["datafile", "scantype", "axistitles","plotlist", "xlabel", "ylabel"]
#
#info = self.data.getKeyInfo(sel[0])
#except Exception:
# info, data = self.data.LoadSource(sel[0])
cntList = info.get("LabelNames", [])
ycntidx = info["envdict"].get('plotlist', "")
if len(ycntidx):
ycntidx = ycntidx.split(',')
self.build(cntList)
#self.cntTable.setCounterSelection(self._oldCntSelection)
return
if info['cols'] > 0:
#arrayname = info['Key']
arrayname = 'Column'
cntList = []
for i in range(info['cols']):
cntList.append('%s_%03d' % (arrayname, i))
self.build(cntList)
def getSelection(self):
#get selected counter keys
cnt_sel = self.getCounterSelection()
sel_list = []
#build the appropriate selection for mca's
if len(cnt_sel['cntlist']):
if len(cnt_sel['y']): #if there is something to plot
for index in cnt_sel['y']:
sel = {}
sel['selection'] = {}
sel['plot'] = 'scan'
sel['scanselection'] = True
sel['selection']['x'] = cnt_sel['x']
sel['selection']['y'] = [index]
sel['selection']['m'] = cnt_sel['m']
sel['selection']['cntlist'] = cnt_sel['cntlist']
sel_list.append(sel)
return sel_list
class SPSMcaArrayWidget(qt.QWidget):
def __init__(self, parent=None, name="SPS_MCA_DATA", fl=0, title="MCA", size=(0,8192)):
qt.QWidget.__init__(self, parent)
self.setWindowTitle(name)
layout= QGridLayout(self)
layout.setContentsMargins(5, 5, 5, 5)
layout.setSpacing(0)
self.title= qt.QLabel(self)
font= self.title.font()
font.setBold(1)
self.title.setFont(font)
#layout.addMultiCellWidget(self.title, 0, 0, 0, 1, qt.Qt.AlignCenter)
layout.addWidget(self.title, 0, 0)
layout.setAlignment(self.title, qt.Qt.AlignCenter)
self.setTitle(title)
def setInfo(self, info):
self.setDataSize(info["rows"], info["cols"])
self.setTitle(info["Key"])
def setDataSize(self,rows,cols,selsize=None):
self.rows= rows
self.cols= cols
if self.cols<=self.rows:
self.idx='cols'
else:
self.idx='rows'
def setTitle(self, title):
self.title.setText("%s"%title)
def getSelection(self):
keys = {"plot":self.idx,"x":0,"y":1}
return [keys]
class SPSXiaArrayWidget(qt.QWidget):
def __init__(self, parent=None, name="SPS_XIA_DATA", fl=0, title="XIA", size=(0,8192)):
qt.QWidget.__init__(self, parent)
layout= qt.QGridLayout(self)
layout.setContentsMargins(5, 5, 5, 5)
layout.setSpacing(0)
self.title= qt.QLabel(self)
font= self.title.font()
font.setBold(1)
self.title.setFont(font)
self.title.setText(title)
self.detList= qt.QListWidget(self)
self.detList.setSelectionMode(qt.QAbstractItemView.ExtendedSelection)
layout.addWidget(self.title, 0, 0)
layout.setAlignment(self.title, qt.Qt.AlignCenter)
##layout.addRowSpacing(0, 40)
_logger.debug("row spacing")
layout.addWidget(self.detList, 1, 0)
def setTitle(self, title):
self.title.setText("%s"%title)
def setInfo(self, info):
self.setDataSize(info["rows"], info["cols"], info.get("Detectors", None))
self.setTitle(info["Key"])
def setDataSize(self, rows, cols, dets=None):
self.rows= rows
self.cols= cols
if dets is None or (len(dets)!=(rows-1)):
dets= range(self.rows)
self.detList.clear()
for idx in range(1, self.rows):
self.detList.addItem("Detector %d"%dets[idx-1])
def getSelection(self):
selection= []
itemlist = self.detList.selectedItems()
ylist = [int(str(item.text()).split()[-1]) for item in itemlist]
for y in ylist:
selection.append({"plot":"XIA", "x":0, "y":y})
return selection
class SPS_ImageArray(qt.QWidget):
def __init__(self, parent=None, name="SPS_ImageArray", fl=0, title="MCA", size=(0,8192)):
qt.QWidget.__init__(self, parent)
self.setWindowTitle(name)
layout= QGridLayout(self)
layout.setContentsMargins(5, 5, 5, 5)
layout.setSpacing(0)
self.title= qt.QLabel(self)
font= self.title.font()
font.setBold(1)
self.title.setFont(font)
#layout.addMultiCellWidget(self.title, 0, 0, 0, 1, qt.Qt.AlignCenter)
layout.addWidget(self.title, 0, 0)
layout.setAlignment(self.title, qt.Qt.AlignCenter)
self.setTitle(title)
def setInfo(self, info):
self.setDataSize(info["rows"], info["cols"])
self.setTitle(info["Key"])
def setDataSize(self,rows,cols,selsize=None):
self.rows= rows
self.cols= cols
def setTitle(self, title):
self.title.setText("%s"%title)
def getSelection(self):
#get selected counter keys
sel_list = []
sel = {}
sel['selection'] = {}
sel['plot'] = 'image'
sel['scanselection'] = False
sel['selection'] = None
sel_list.append(sel)
return sel_list
class SPS_StandardArray(qt.QWidget):
def __init__(self, parent=None, name="SPS_StandardArray", fl=0, rows=0, cols=0):
qt.QWidget.__init__(self, parent)
layout= qt.QGridLayout(self)
layout.setContentsMargins(5, 5, 5, 5)
layout.setSpacing(0)
plab= qt.QLabel("Plot", self)
xlab= qt.QLabel("X :", self)
ylab= qt.QLabel("Y :", self)
layout.addWidget(plab, 0, 0, qt.Qt.AlignRight)
layout.addWidget(xlab, 1, 0, qt.Qt.AlignRight)
layout.addWidget(ylab, 2, 0, qt.Qt.AlignRight|qt.Qt.AlignTop)
self.plotCombo= qt.QComboBox(self)
self.plotCombo.setEditable(0)
self.plotCombo.addItem("Rows")
self.plotCombo.addItem("Columns")
self.xCombo= qt.QComboBox(self)
self.xCombo.setEditable(0)
self.yList= qt.QListWidget(self)
self.yList.setSelectionMode(qt.QAbstractItemView.ExtendedSelection)
layout.addWidget(self.plotCombo, 0, 1)
layout.addWidget(self.xCombo, 1, 1)
layout.addWidget(self.yList, 2, 1)
self.plotCombo.activated[int].connect(self.__plotChanged)
self.setDataSize(rows, cols)
def setDataSize(self, rows, cols):
self.rows= rows
self.cols= cols
idx= self.cols<=self.rows
self.plotCombo.setCurrentIndex(idx)
self.__plotChanged(idx)
def __plotChanged(self, index):
if index==1:
txt= "Column"
val= self.cols
else:
txt= "Row"
val= self.rows
self.xCombo.clear()
self.xCombo.addItem("Array Index")
self.yList.clear()
for x in range(val):
self.xCombo.addItem("%s %d"%(txt,x))
self.yList.addItem("%s %d"%(txt,x))
if val==2:
self.xCombo.setCurrentIndex(0)
self.__xChanged(0)
def __xChanged(self, index):
pass
def getSelection(self):
selection= []
idx= self.plotCombo.currentIndex()
if idx==1: plot= "cols"
else: plot= "rows"
idx= self.xCombo.currentIndex()
if idx==0: x= None
else: x= idx-1
itemlist = self.yList.selectedItems()
ylist = [int(str(item.text()).split()[-1]) for item in itemlist]
for y in ylist:
selection.append({"plot":plot, "x":x, "y":y})
return selection
class QSpsWidget(qt.QWidget):
HiddenArrays= ["MCA_DATA_PARAM", "XIA_STAT", "XIA_DET"]
WidgetArrays= {"scan":SPSScanArrayWidget,
"xia": SPSXiaArrayWidget,
"mca": SPSMcaArrayWidget,
"array": SPS_StandardArray,
"image": SPS_ImageArray,
"frames_mca":SPSFramesMcaWidget,
"frames_image":qt.QWidget,
"empty": qt.QWidget}
TypeArrays= {"MCA_DATA": "mca", "XIA_PLOT": "mca",
"XIA_DATA": "xia", "XIA_BASELINE":"xia",
"SCAN_D": "scan", "image_data":"image" }
sigAddSelection = qt.pyqtSignal(object)
sigRemoveSelection = qt.pyqtSignal(object)
sigReplaceSelection = qt.pyqtSignal(object)
sigOtherSignals = qt.pyqtSignal(object)
def __init__(self, parent=None, name="SPSSelector", fl=0):
qt.QWidget.__init__(self, parent)
self.dataSource= None
self.data= None
self.currentSpec= None
self.currentArray= None
self.selection= None
self.openFile = self.refreshSpecList
self.selectPixmap= qt.QPixmap(icons.selected)
self.unselectPixamp= qt.QPixmap(icons.unselected)
mainLayout= qt.QVBoxLayout(self)
# --- spec name selection
specWidget= qt.QWidget(self)
self.specCombo= qt.QComboBox(specWidget)
self.specCombo.setEditable(0)
self.reload_= qt.QIcon(qt.QPixmap(icons.reload_))
refreshButton= qt.QToolButton(specWidget)
refreshButton.setIcon(self.reload_)
self.closeIcon= qt.QIcon(qt.QPixmap(icons.fileclose))
closeButton= qt.QToolButton(specWidget)
closeButton.setIcon(self.closeIcon)
refreshButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
closeButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
specLayout= qt.QHBoxLayout(specWidget)
specLayout.addWidget(self.specCombo)
specLayout.addWidget(refreshButton)
specLayout.addWidget(closeButton)
refreshButton.clicked.connect(self.refreshSpecList)
closeButton.clicked.connect(self.closeCurrentSpec)
if hasattr(self.specCombo, "textActivated"):
self.specCombo.textActivated[str].connect(self.refreshArrayList)
else:
self.specCombo.activated[str].connect(self.refreshArrayList)
# --- splitter
self.splitter= qt.QSplitter(self)
self.splitter.setOrientation(qt.Qt.Vertical)
# --- shm array list
self.arrayList= qt.QTreeWidget(self.splitter)
labels = ["","Array Name", "Rows","Cols"]
self.arrayList.setColumnCount(len(labels))
self.arrayList.setHeaderLabels(labels)
self.arrayList.setSelectionMode(qt.QAbstractItemView.SingleSelection)
self.arrayList.itemSelectionChanged[()].connect(self.__arraySelection)
# --- array parameter
self.paramIndex= {}
self.paramWidget= qt.QStackedWidget(self.splitter)
for wtype in self.WidgetArrays.keys():
widclass= self.WidgetArrays[wtype]
wid= widclass(self.paramWidget)
self.paramWidget.addWidget(wid)
self.paramIndex[wtype]= self.paramWidget.indexOf(wid)
# --- command buttons
butWidget= qt.QWidget(self)
butWidget.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Minimum,
qt.QSizePolicy.Minimum))
addButton= qt.QPushButton("Add", butWidget)
removeButton= qt.QPushButton("Remove", butWidget)
replaceButton= qt.QPushButton("Replace", butWidget)
butLayout= qt.QHBoxLayout(butWidget)
butLayout.addWidget(addButton)
butLayout.addWidget(removeButton)
butLayout.addWidget(replaceButton)
butLayout.setContentsMargins(5, 5, 5, 5)
addButton.clicked.connect(self.__addClicked)
replaceButton.clicked.connect(self.__replaceClicked)
removeButton.clicked.connect(self.__removeClicked)
# --- main layout
mainLayout.setContentsMargins(5, 5, 5, 5)
mainLayout.setSpacing(5)
mainLayout.addWidget(specWidget)
if __name__ != "__main__":
specWidget.hide()
mainLayout.addWidget(self.splitter)
mainLayout.addWidget(butWidget)
def setData(self,data=None):
_logger.debug("setData(self, data) called")
_logger.debug("spec data = %s", data)
self.data= data
self.refreshSpecList()
self.refreshDataSelection()
def setDataSource(self,data=None):
_logger.debug("setDataSource(self, data) called")
_logger.debug("spec data = %s", data)
self.data= data
self.refreshSpecList()
self.refreshDataSelection()
if data is None:
self.arrayList.clear()
else:
self.refreshArrayList(data.sourceName)
def refreshSpecList(self):
speclist= sps.getspeclist()
if self.specCombo.count():
selected= str(self.specCombo.currentText())
else: selected= None
self.specCombo.clear()
if len(speclist):
for spec in speclist:
self.specCombo.addItem(spec)
self.selectSpec(selected or speclist[0])
def selectSpec(self, specname=None):
for idx in range(self.specCombo.count()):
if str(self.specCombo.itemText(idx))==specname:
self.specCombo.setCurrentIndex(idx)
def __getCurrentSpec(self):
if self.specCombo.count():
return str(self.specCombo.currentText())
else: return None
def refreshDataSelection(self, source=None):
spec= self.__getCurrentSpec()
if spec is not None and self.dataSource is not None:
arraylist= self.dataSource.GetDataList(spec)
item= self.arrayList.firstChild()
while item is not None:
name= str(item.text(1))
if name in arraylist: item.setPixmap(0, self.selectPixmap)
else: item.setPixmap(0, self.unselectPixmap)
item= item.nextSibling()
def closeCurrentSpec(self):
spec= self.__getCurrentSpec()
if spec is not None and self.dataSource is not None:
arraylist= self.DataSource.GetDataList(spec)
if len(arraylist):
msg= "%d spectrums are linked to that SPEC source.\n"%(len(arraylist))
msg+= "Do you really want to delete all these spectrums ??"
ans= qt.QMessageBox.information(self, "Remove Spec Shared %s"%spec, msg, \
qt.QMessageBox.No, qt.QMessageBox.Yes)
if ans.qt.QMessageBox.Yes:
self.dataSource.RemoveData(spec)
def refreshArrayList(self,qstring):
self.arrayList.clear()
#spec= self.__getCurrentSpec()
self.currentSpec = str(qstring)
spec = self.currentSpec
if spec is not None:
arraylist= {}
for array in sps.getarraylist(spec):
if array not in self.HiddenArrays:
info= sps.getarrayinfo(spec, array)
rows= info[0]
cols= info[1]
type= info[2]
flag= info[3]
_logger.debug(" array = %s", array)
_logger.debug(" flag = %s", flag)
_logger.debug(" type = %s", type)
if type!=sps.STRING:
if (flag & sps.TAG_ARRAY) == sps.TAG_ARRAY:
arraylist[array]= (rows, cols)
if len(arraylist.keys()):
arrayorder= list(arraylist.keys())
arrayorder.sort()
arrayorder.reverse()
for name in arrayorder:
item = (qt.QTreeWidgetItem(self.arrayList,
["", name, str(arraylist[name][0]), str(arraylist[name][1])]))
self.refreshDataSelection()
self.__getParamWidget("empty")
def __arraySelection(self):
"""
Method called when selecting an array in the view
"""
item= self.arrayList.selectedItems()
if len(item):
item = item[0]
self.currentArray= str(item.text(1))
else:
#click on empty space
return
#self.data.SetSource(self.currentSpec)
#self.data.LoadSource(self.currentArray)
info= self.data.getKeyInfo(self.currentArray)
wid= None
atype = None
if 0 and ((info['flag'] & sps.TAG_FRAMES) == sps.TAG_FRAMES) and\
((info['flag'] & sps.TAG_IMAGE) == sps.TAG_IMAGE):
atype = "frames_image"
elif ((info['flag'] & sps.TAG_FRAMES) == sps.TAG_FRAMES) and\
((info['flag'] & sps.TAG_MCA) == sps.TAG_MCA):
atype = "frames_mca"
elif (info['flag'] & sps.TAG_IMAGE) == sps.TAG_IMAGE:
atype = "image"
elif (info['flag'] & sps.TAG_MCA) == sps.TAG_MCA:
atype = "mca"
elif (info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN:
atype = "scan"
elif (info['rows'] > 100) and (info['cols'] > 100):
atype = "image"
if atype is not None:
wid= self.__getParamWidget(atype)
wid.setInfo(info)
if hasattr(wid, "setDataSource"):
wid.setDataSource(self.data)
else:
for (array, atype) in self.TypeArrays.items():
if self.currentArray[0:len(array)]==array:
wid= self.__getParamWidget(atype)
wid.setInfo(info)
if hasattr(wid, "setDataSource"):
wid.setDataSource(self.data)
break
if wid is None:
arrayType = "ARRAY"
wid= self.__getParamWidget("array")
wid.setDataSize(info["rows"], info["cols"])
else:
arrayType = atype.upper()
#emit a selection to inform about the change
ddict = {}
ddict['SourceName'] = self.data.sourceName
ddict['SourceType'] = self.data.sourceType
ddict['event'] = "SelectionTypeChanged"
if arrayType in ["IMAGE"]:
ddict['SelectionType'] = self.data.sourceName +" "+self.currentArray
elif arrayType in ["MCA", "XIA"]:
ddict['SelectionType'] = "MCA"
elif arrayType in ["ARRAY"]:
ddict['SelectionType'] = "MCA"
else:
ddict['SelectionType'] = arrayType
self.sigOtherSignals.emit(ddict)
def __getParamWidget(self, widtype):
wid= self.paramWidget.currentWidget()
if self.paramWidget.indexOf(wid) != self.paramIndex[widtype]:
self.paramWidget.setCurrentIndex(self.paramIndex[widtype])
wid = self.paramWidget.currentWidget()
return wid
def __replaceClicked(self):
_logger.debug("replace clicked")
selkeys= self.__getSelectedKeys()
if len(selkeys):
#self.eh.event(self.repEvent, selkeys)
_logger.debug("Replace event")
sel = {}
sel['SourceType'] = SOURCE_TYPE
sellistsignal = []
for selection in selkeys:
selsignal = {}
selsignal['SourceType'] = self.data.sourceType
selsignal['SourceName'] = self.data.sourceName
selsignal['selection'] = None
selsignal['Key'] = selection['Key']
if 'SourceName' not in sel:
sel['SourceName'] = selection['SourceName']
arrayname = selection['Key']
if 'Key' not in sel:
sel['Key'] = selection['Key']
if arrayname not in sel:
sel[arrayname] = {'rows':[],'cols':[]}
if selection['plot'] == 'cols':
selsignal["selection"] = {"cols":{}}
selsignal["selection"]["cols"] = {}
selsignal["selection"]["cols"]["x"] = [selection['x']]
selsignal["selection"]["cols"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".c.%d" % int(selection['y'])
sel[arrayname]['cols'].append({'x':selection['x'],'y':selection['y']})
elif selection['plot'] == 'rows':
sel[arrayname]['rows'].append({'x':selection['x'],'y':selection['y']})
selsignal["selection"] = {"rows":{}}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".r.%d" % int(selection['y'])
elif selection['plot'] == 'XIA':
sel[arrayname]['rows'].append({'x':selection['x'],
'y':selection['y']})
#selsignal["Key"] += ".r.%d" % int(selection['y'])
selsignal["selection"] = {"rows":{}, "XIA":True}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
" #%02d" % int(selection['y'])
elif selection['plot'] == 'scan':
if SCAN_MODE:
#sel[arrayname]['cols'].append({'x':selection['selection']['x'][0],
# 'y':selection['selection']['y'][0]})
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = True
#print "cheeting"
#selsignal['scanselection'] = False
else:
#do it as a col
sel[arrayname]['cols'].append({'x':selection['selection']['x'],
'y':selection['selection']['y']})
selsignal["selection"] = {'cols':{}}
selsignal["selection"]["cols"]["x"] = selection['selection']['x']
selsignal["selection"]["cols"]["y"] = selection['selection']['y']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = True
#print "cheeting"
#selsignal['scanselection'] = False
elif selection['plot'] == 'image':
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = False
selsignal['imageselection'] = True
sellistsignal.append(selsignal)
self.setSelected([sel],reset=1)
self.sigReplaceSelection.emit(sellistsignal)
def currentSelectionList(self):
return self._addCliked(emit = False)
def __addClicked(self):
return self._addClicked()
def _addClicked(self, emit=True):
_logger.debug("select clicked")
selkeys= self.__getSelectedKeys()
_logger.debug("selected keys = %s", selkeys )
if len(selkeys):
#self.eh.event(self.addEvent, selkeys)
_logger.debug("Select event")
sel = {}
sel['SourceType'] = SOURCE_TYPE
sellistsignal = []
for selection in selkeys:
selsignal = {}
selsignal['SourceType'] = self.data.sourceType
selsignal['SourceName'] = self.data.sourceName
selsignal['selection'] = None
selsignal['Key'] = selection['Key']
if 'SourceName' not in sel:
sel['SourceName'] = selection['SourceName']
arrayname = selection['Key']
if 'Key' not in sel:
sel['Key'] = selection['Key']
if arrayname not in sel:
sel[arrayname] = {'rows':[],'cols':[]}
if selection['plot'] == 'XIA':
sel[arrayname]['rows'].append({'x':selection['x'],
'y':selection['y']})
#selsignal["Key"] += ".r.%d" % int(selection['y'])
selsignal["selection"] = {"rows":{}, "XIA":True}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
" #%02d" % int(selection['y'])
elif selection['plot'] == 'cols':
sel[arrayname]['cols'].append({'x':selection['x'],
'y':selection['y']})
#selsignal["Key"] += ".c.%d" % int(selection['y'])
selsignal["selection"] = {"cols":{}}
selsignal["selection"]["cols"] = {}
selsignal["selection"]["cols"]["x"] = [selection['x']]
selsignal["selection"]["cols"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".c.%d" % int(selection['y'])
elif selection['plot'] == 'rows':
sel[arrayname]['rows'].append({'x':selection['x'],
'y':selection['y']})
#selsignal["Key"] += ".r.%d" % int(selection['y'])
selsignal["selection"] = {"rows":{}}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".r.%d" % int(selection['y'])
elif selection['plot'] == 'scan':
if SCAN_MODE:
#sel[arrayname]['cols'].append({'x':selection['selection']['x'][0],
# 'y':selection['selection']['y'][0]})
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = True
#print "cheeting"
#selsignal['scanselection'] = False
else:
#do it as a col
sel[arrayname]['cols'].append({'x':selection['selection']['x'],
'y':selection['selection']['y']})
selsignal["selection"] = {'cols':{}}
selsignal["selection"]["cols"]["x"] = selection['selection']['x']
selsignal["selection"]["cols"]["y"] = selection['selection']['y']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = True
#print "cheeting"
#selsignal['scanselection'] = False
elif selection['plot'] == 'image':
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = False
selsignal['imageselection'] = True
sellistsignal.append(selsignal)
if self.selection is None:
self.setSelected([sel],reset=1)
else:
self.setSelected([sel],reset=0)
if emit:
self.sigAddSelection.emit(sellistsignal)
else:
return sellistsignal
def __getSelectedKeys(self):
selkeys= []
parwid= self.paramWidget.currentWidget()
if self.currentArray is not None:
for sel in parwid.getSelection():
sel["SourceName"]= self.currentSpec
sel['SourceType'] = SOURCE_TYPE
sel["Key"]= self.currentArray
selkeys.append(sel)
return selkeys
def __removeClicked(self):
_logger.debug("remove clicked")
selkeys= self.__getSelectedKeys()
if len(selkeys):
#self.eh.event(self.delEvent, selkeys)
_logger.debug("Remove Event")
_logger.debug("self.selection before = %s", self.selection)
returnedselection=[]
sellistsignal = []
for selection in selkeys:
selsignal = {}
selsignal['SourceType'] = self.data.sourceType
selsignal['SourceName'] = self.data.sourceName
selsignal['selection'] = None
selsignal['Key'] = selection['Key']
sel = {}
sel['SourceName'] = selection['SourceName']
sel['SourceType'] = SOURCE_TYPE
sel['Key'] = selection['Key']
arrayname = selection['Key']
sel[arrayname] = {'rows':[],'cols':[]}
if selection['plot'] == 'cols':
sel[arrayname]['cols'].append({'x':selection['x'],'y':selection['y']})
selsignal["selection"] = {"cols":{}}
selsignal["selection"]["cols"] = {}
selsignal["selection"]["cols"]["x"] = [selection['x']]
selsignal["selection"]["cols"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".c.%d" % int(selection['y'])
elif selection['plot'] == 'rows':
sel[arrayname]['rows'].append({'x':selection['x'],'y':selection['y']})
selsignal["selection"] = {"rows":{}}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
".r.%d" % int(selection['y'])
elif selection['plot'] == 'XIA':
sel[arrayname]['rows'].append({'x':selection['x'],
'y':selection['y']})
#selsignal["Key"] += ".r.%d" % int(selection['y'])
selsignal["selection"] = {"rows":{}, "XIA":True}
selsignal["selection"]["rows"] = {}
selsignal["selection"]["rows"]["x"] = [selection['x']]
selsignal["selection"]["rows"]["y"] = [selection['y']]
if type(self.data.sourceName) == type(''):
sname = [self.data.sourceName]
else:
sname = self.data.sourceName
selsignal["legend"] = sname[0] +\
" "+selsignal['Key']+\
" #%02d" % int(selection['y'])
elif selection['plot'] == 'scan':
#sel[arrayname]['cols'].append({'x':selection['selection']['x'][0],
# 'y':selection['selection']['y'][0]})
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = True
elif selection['plot'] == 'image':
selsignal["selection"] = selection['selection']
selsignal['legend'] = self.data.sourceName + " " + \
selsignal['Key']
selsignal['scanselection'] = False
selsignal['imageselection'] = True
sellistsignal.append(selsignal)
returnedselection.append(sel)
if self.selection is not None:
_logger.debug("step 1")
if sel['SourceName'] in self.selection:
_logger.debug("step 2")
if arrayname in self.selection[sel['SourceName']]:
_logger.debug("step 3")
if 'rows' in self.selection[sel['SourceName']][arrayname]:
_logger.debug("step 4")
for couple in sel[arrayname]['rows']:
if couple in self.selection[sel['SourceName']][arrayname]['rows']:
index= self.selection[sel['SourceName']][arrayname]['rows'].index(couple)
del self.selection[sel['SourceName']][arrayname]['rows'][index]
for couple in sel[arrayname]['cols']:
if couple in self.selection[sel['SourceName']][arrayname]['cols']:
index= self.selection[sel['SourceName']][arrayname]['cols'].index(couple)
del self.selection[sel['SourceName']][arrayname]['cols'][index]
seln = {}
seln['SourceName'] = sel['SourceName']
seln['SourceType'] = SOURCE_TYPE
seln['Key'] = sel['Key']
seln[seln['Key']] = self.selection[seln['SourceName']][seln['Key']]
self.setSelected([seln],reset=0)
self.sigRemoveSelection.emit(sellistsignal)
def removeSelection(self,selection):
if type(selection) != type([]):
selection=[selection]
for sel in selection:
arrayname = sel['Key']
if self.selection is not None:
_logger.debug("step 1")
if sel['SourceName'] in self.selection:
_logger.debug("step 2")
if arrayname in self.selection[sel['SourceName']]:
_logger.debug("step 3")
if 'rows' in self.selection[sel['SourceName']][arrayname]:
_logger.debug("step 4")
for couple in sel[arrayname]['rows']:
if couple in self.selection[sel['SourceName']][arrayname]['rows']:
index= self.selection[sel['SourceName']][arrayname]['rows'].index(couple)
del self.selection[sel['SourceName']][arrayname]['rows'][index]
for couple in sel[arrayname]['cols']:
if couple in self.selection[sel['SourceName']][arrayname]['cols']:
index= self.selection[sel['SourceName']][arrayname]['cols'].index(couple)
del self.selection[sel['SourceName']][arrayname]['cols'][index]
seln = {}
seln['SourceName'] = sel['SourceName']
seln['SourceType'] = SOURCE_TYPE
seln['Key'] = sel['Key']
seln[seln['Key']] = self.selection[seln['SourceName']][seln['Key']]
self.setSelected([seln],reset=0)
self.sigRemoveSelection.emit((selection))
def setSelected(self,sellist,reset=1):
_logger.debug("setSelected(self,sellist,reset=1) called")