This file is indexed.

/usr/share/pyshared/PyMca/SpecFileCntTable.py is in pymca 4.5.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
#/*##########################################################################
# Copyright (C) 2004-2011 European Synchrotron Radiation Facility
#
# This file is part of the PyMCA X-ray Fluorescence Toolkit developed at
# the ESRF by the Beamline Instrumentation Software Support (BLISS) group.
#
# This toolkit is free software; you can redistribute it and/or modify it 
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) 
# any later version.
#
# PyMCA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# PyMCA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# PyMCA follows the dual licensing model of Trolltech's Qt and Riverbank's PyQt
# and cannot be used as a free plugin for a non-free program. 
#
# Please contact the ESRF industrial unit (industry@esrf.fr) if this license 
# is a problem for you.
#############################################################################*/
import sys
import PyMcaQt as qt
QTVERSION = qt.qVersion()
DEBUG = 0

if 'Object3D' in sys.modules:
    OBJECT3D = True
else:
    OBJECT3D = False

if QTVERSION < '4.0.0':
    if QTVERSION < '3.0.0':
        import Myqttable as qttable
    else:
        import qttable
    
    class SpecFileCntTable(qt.QWidget):
        def __init__(self, parent=None, name=None, fl=0):
            qt.QWidget.__init__(self, parent, name, fl)

            self.mainLayout= qt.QVBoxLayout(self)

            self.table= qttable.QTable(self)
            self.table.setSelectionMode(qttable.QTable.Multi)
            if qt.qVersion() > '3.0.0':
                self.table.setFocusStyle(qttable.QTable.FollowStyle)
                #self.table.setFocusStyle(qttable.QTable.SpreadSheet)
                #self.table.setReadOnly(1)
                self.table.setColumnReadOnly(0,1)
                self.table.setColumnReadOnly(2,1)
            self.table.verticalHeader().setResizeEnabled(0, -1)
            self.table.horizontalHeader().setResizeEnabled(0, -1)
            self.cnt=0
            self.cntlist=[]

            # --- selection in case of a single MCA by scan
            self.firstCnt= qttable.QTableSelection()
            self.firstCnt.init(0, 0)
            self.firstCnt.expandTo(0, 0)

            self.mainLayout.addWidget(self.table)

            #do not use double click
            #self.connect(self.table, qt.SIGNAL("doubleClicked(int,int,int,const qt.QPoint&)"), self.__doubleClicked)
            self.connect(self.table,qt.SIGNAL("clicked(int,int,int,const QPoint&)"),
                                    self.__Clicked)
            self.connect(self.table,qt.SIGNAL("selectionChanged()"),
                                     self.__selectionChanged)
            self.reset()

        #
        # data management
        #
        def setData(self, specfiledata):
            self.data= specfiledata
            self.reset()

        def setDataSource(self, specfiledata):
            self.data= specfiledata
            self.reset()

        def setScan(self, scankey):
            if type(scankey)==type([]): 
                if len(scankey): scankey= scankey[0]
                else: scankey=None
            if scankey is None:
                self.reset()
            else:
                self.info= self.data.GetSourceInfo(scankey)
                self.refresh()

        def markCntSelected(self, cntdict):
            if DEBUG:
                print("markCntSelected(self, cntdict)")
                print("cntdict = ", cntdict)
                print("self.cntlist = ",self.cntlist)
            if (cntdict != {}):
                for cnt in self.cntlist:
                    row =self.cntlist.index(cnt)
                    if row in cntdict["x"]:
                        self.table.xcheck[row].setChecked(1)
                    else:
                        self.table.xcheck[row].setChecked(0)
                    if row in cntdict["y"]:
                        self.table.ycheck[row].setChecked(1)
                    else:
                        self.table.ycheck[row].setChecked(0)
                    if row in cntdict["m"]:
                        self.table.mcheck[row].setChecked(1)
                    else:
                        self.table.mcheck[row].setChecked(0)
                
        def selectCntList(self, cntlist, numbers = True):
            if DEBUG:
                print("selectCntList(self, cntlist)")
                print("cntlist = ",cntlist)
            if not numbers:
                for cntname in cntlist:
                    self.selectCntName(cntname)

        def selectCntName(self, cntname):
            (row, col)= self.__getRowCol(cntname)
            selection= qttable.QTableSelection()
            selection.init(row, col)
            selection.expandTo(row, col)
            self.table.addSelection(selection)
            #self.__selectionChanged()

        def selectFirstCnt(self):
            self.table.addSelection(self.firstCnt)
            #self.__selectionChanged()

        def refresh(self):
            #self.cntlist= self.info["AllLabels"] or []
            self.cntlist= self.info["LabelNames"] or []
            pts= self.info["Lines"] or 0

            if self.cntlist==[]: 
                self.reset()
            else:
                # --- try to compute number of counters
                self.cnt=len(self.cntlist)
                self.table.setNumCols(4)
                self.table.setNumRows(self.cnt)
                Hheader= self.table.horizontalHeader()
                Hheader.setLabel(0, "Label", -1)
                Hheader.setLabel(1, "X", -1)
                self.table.adjustColumn(1)
                Hheader.setLabel(2, "Y", -1)
                self.table.adjustColumn(2)
                Hheader.setLabel(3, "M", -1)
                self.table.adjustColumn(3)
                #for idx in range(4):
                #    Hheader.setLabel(idx, "mca.%d"%(idx+1), -1)
                self.table.xcheck=[]
                self.table.ycheck=[]
                self.table.mcheck=[]
                for row in range(self.cnt):
                    for col in range(4):
                        if col==1:
                            #self.table.setText(row, col, "")
                            self.table.xcheck.append(qttable.QCheckTableItem(self.table,qt.QString("")))
                            self.table.setItem(row,col,self.table.xcheck[row])
                        elif col == 2:
                            #self.table.setText(row, col, "")
                            self.table.ycheck.append(qttable.QCheckTableItem(self.table,qt.QString("")))
                            self.table.setItem(row,col,self.table.ycheck[row])
                        elif col == 3:
                            self.table.mcheck.append(qttable.QCheckTableItem(self.table,qt.QString("")))
                            self.table.setItem(row,col,self.table.mcheck[row])
                        else:
                            self.table.setText(row, col, self.cntlist[row])
                self.table.adjustColumn(0)

                #if mca==1:
                #    self.selectFirstMca()

        def clear(self):
            self.table.clearSelection(1)

        def reset(self):
            self.table.clearSelection(1)
            self.table.setNumCols(1)
            self.table.setNumRows(0)
            self.table.horizontalHeader().setLabel(0, "NO Counters for the selected scan", -1)
            self.table.adjustColumn(0)
            self.cnt= 0
            self.pts= 0

        def getSelection(self, numbers=True):
            if self.cnt==0:    return []
            selection= []
            Xcnt=[]
            Ycnt=[]
            Mcnt=[]
            for row in range(self.cnt):
                #if self.table.isSelected(row, 1):
                if self.table.xcheck[row].isChecked():
                    #Xnt
                    if numbers:
                        Xcnt.append(row)
                    else:
                        Xcnt.append(self.cntlist[row])
                if self.table.ycheck[row].isChecked():
                    #Ycnt
                    if numbers:
                        Ycnt.append(row)
                    else:
                        Ycnt.append(self.cntlist[row])
                #if self.table.isSelected(row, 3):
                if self.table.mcheck[row].isChecked():
                    #Mcnt
                    if numbers:
                        Mcnt.append(row)
                    else:
                        Mcnt.append(self.cntlist[row])

            for cnt in Ycnt:
                selection.append({"Key":"%s"%(self.info["Key"]),
                                  "scan":"%s"%(self.info["Key"]),
                                  "x":Xcnt,
                                  "y":cnt,
                                  "m":Mcnt,
                                  "cntlist":self.cntlist*1})
            return selection

        def getCounterSelection(self, numbers=True):
            ddict = {}
            ddict['cntlist'] = 1 * self.cntlist
            ddict['x']       = []
            ddict['y']       = []
            ddict['m'] = []
            for row in range(self.cnt):
                if self.table.xcheck[row].isChecked():
                    #Xnt
                    if numbers:
                        ddict['x'].append(row)
                    else:
                        ddict['x'].append(self.cntlist[row])
                if self.table.ycheck[row].isChecked():
                    #Ycnt
                    if numbers:
                        ddict['y'].append(row)
                    else:
                        ddict['y'].append(self.cntlist[row])
                #if self.table.isSelected(row, 3):
                if self.table.mcheck[row].isChecked():
                    #Mcnt
                    if numbers:
                        ddict['m'].append(row)
                    else:
                        ddict['m'].append(self.cntlist[row])
                
            return ddict

            
        #
        # signal / slot handling
        #
        def __selectionChanged(self):
            if self.cnt==0: return
            else:
                for row in range(self.cnt):
                    if self.table.isSelected(row, 2):
                        self.table.ycheck[row].setChecked(1)
                    else:
                        self.table.ycheck[row].setChecked(0)
                self.emit(qt.PYSIGNAL("cntSelection"), (self.getSelection,))

        def __doubleClicked(self, *args):
            self.emit(qt.PYSIGNAL("cntDoubleClicked"), (["%s.%d"%(self.info["Key"], self.__getCntNo(args[0], args[1]))],))


        def __Clicked(self, *args):
            row=args[0]
            col=args[1]
            if col == 0:
                pass
            elif col==1:
                #xclick
                maxclicked=1
                for i in range(self.cnt):
                    if i != row:
                        self.table.xcheck[i].setChecked(0)                
            elif col==2:
                #yclick
                pass
            elif col==3:
                #mclixk
                for i in range(self.cnt):
                    if i != row:
                        self.table.mcheck[i].setChecked(0) 
        #
        # (mcano) <--> (row,col) operations
        #
        def __getCntNo(self, row, col):
            return (row*self.cnt+col+1)
            
        def __getRowCol(self, mcano):
            mcano= mcano-1
            row= int(mcano/self.cnt)
            col= mcano-(row*self.cnt)
            return (row, col)

else:
    class SpecFileCntTable(qt.QTableWidget):
        def __init__(self, parent=None):
            qt.QTableWidget.__init__(self, parent)
            self.cntList      = []
            self.mcaList      = []
            self.xSelection   = []
            self.ySelection   = []
            self.monSelection = []
            self.__is3DEnabled = False
            labels = ['Counter', 'X    ', 'Y    ', 'Mon']
            self.setColumnCount(len(labels))
            for i in range(len(labels)):
                item = self.horizontalHeaderItem(i)
                if item is None:
                    item = qt.QTableWidgetItem(labels[i],
                                               qt.QTableWidgetItem.Type)
                item.setText(labels[i])
                self.setHorizontalHeaderItem(i,item)
            """
            #the cell is not the same as the check box
            #but I wonder about the checkboxes being destroyed
            qt.QObject.connect(self,
                         qt.SIGNAL("cellClicked(int, int)"),
                         self._mySlot)
            """

        def build(self, cntlist, nmca=None):
            if not OBJECT3D:
                nmca = 0
            nmca = 0
            if nmca is None:
                nmca = 0 
            self.cntList = cntlist
            self.mcaList = []
            n = len(cntlist)
            self.setRowCount(n)
            if n > 0:
                self.setRowCount(n + nmca)
                rheight = self.horizontalHeader().sizeHint().height()
                for i in range(n):
                    self.setRowHeight(i, rheight)
                    self.__addLine(i, cntlist[i])
                    for j in range(1, 4, 1):
                        widget = self.cellWidget(i, j)
                        widget.setEnabled(True)
                for j in range(nmca):
                    row = n+j
                    self.setRowHeight(n+j, rheight)
                    mca = "Mca %d" % (j+1)
                    self.mcaList.append(mca)
                    self.__addLine(n+j, self.mcaList[j])
                    #the x checkbox
                    widget = self.cellWidget(row, 1)
                    widget.setChecked(False)
                    widget.setEnabled(False)
                    #the y checkbox
                    widget = self.cellWidget(row, 2)
                    widget.setChecked(False)
                    widget.setEnabled(True)
                    #the Monitor checkbox
                    widget = self.cellWidget(row, 3)
                    widget.setChecked(False)
                    widget.setEnabled(False)
            else:
                self.setRowCount(0)

            self.resizeColumnToContents(1)
            self.resizeColumnToContents(2)
            self.resizeColumnToContents(3)
            
        def __addLine(self, i, cntlabel):
            #the counter name
            item = self.item(i, 0)
            if item is None:
                item = qt.QTableWidgetItem(cntlabel,
                                           qt.QTableWidgetItem.Type)
                item.setTextAlignment(qt.Qt.AlignHCenter | qt.Qt.AlignVCenter)
                self.setItem(i, 0, item)
            else:
                item.setText(cntlabel)
            #item is just enabled (not selectable)
            item.setFlags(qt.Qt.ItemIsEnabled)

            #the checkboxes
            for j in range(1, 4, 1):
                widget = self.cellWidget(i, j)
                if widget is None:
                    widget = CheckBoxItem(self, i, j)
                    self.setCellWidget(i, j, widget)
                    qt.QObject.connect(widget,
                                       qt.SIGNAL('CheckBoxItemSignal'),
                                       self._mySlot)
                else:
                    pass

        def set3DEnabled(self, value):
            if value:
                self.__is3DEnabled = True
                if len(self.xSelection) > 3:
                    self.xSelection = self.xSelection[-3:]
            else:
                self.__is3DEnabled = False
                if len(self.xSelection) > 1:
                    self.xSelection = [1 * self.xSelection[0]]                    
            self._update()

        def _mySlot(self, ddict):
            row = ddict["row"]
            col = ddict["col"]
            if col == 1:
                if ddict["state"]:
                    if row not in self.xSelection:
                        self.xSelection.append(row)
                else:
                    if row in self.xSelection:
                        del self.xSelection[self.xSelection.index(row)]
                if (not OBJECT3D) or (not self.__is3DEnabled):
                    if len(self.xSelection) > 2:
                        #that is to support mesh plots
                        self.xSelection = self.xSelection[-2:]
                    if len(self.xSelection) > 1:
                        self.xSelection = self.xSelection[-1:]
                elif len(self.xSelection) > 3:
                    self.xSelection = self.xSelection[-3:]

            if col == 2:
                if ddict["state"]:
                    if row not in self.ySelection:
                        self.ySelection.append(row)
                else:
                    if row in self.ySelection:
                        del self.ySelection[self.ySelection.index(row)]
            if col == 3:
                if ddict["state"]:
                    if row not in self.monSelection:
                        self.monSelection.append(row)
                else:
                    if row in self.monSelection:
                        del self.monSelection[self.monSelection.index(row)]
                if len(self.monSelection) > 1:
                    self.monSelection = self.monSelection[-1:]
            self._update()

        def _update(self):
            for i in range(self.rowCount()):
                j = 1
                widget = self.cellWidget(i, j)
                if i in self.xSelection:
                    if not widget.isChecked():
                        widget.setChecked(True)
                else:
                    if widget.isChecked():
                        widget.setChecked(False)
                j = 2
                widget = self.cellWidget(i, j)
                if i in self.ySelection:
                    if not widget.isChecked():
                        widget.setChecked(True)
                else:
                    if widget.isChecked():
                        widget.setChecked(False)
                j = 3
                widget = self.cellWidget(i, j)
                if i in self.monSelection:
                    if not widget.isChecked():
                        widget.setChecked(True)
                else:
                    if widget.isChecked():
                        widget.setChecked(False)
            ddict = {}
            ddict["event"] = "updated"
            self.emit(qt.SIGNAL('SpecCntTableSignal'), ddict)        
            

        def getCounterSelection(self):
            ddict = {}
            ddict['cntlist'] = self.cntList * 1
            ddict['mcalist'] = self.mcaList * 1
            ddict['x']       = self.xSelection * 1
            ddict['y']       = self.ySelection * 1
            ddict['m'] = self.monSelection * 1        
            return ddict

        def setCounterSelection(self, ddict):
            keys = ddict.keys()
            if 'cntlist' in keys: cntlist = ddict['cntlist']
            else: cntlist = self.cntList * 1

            if 'x' in keys: x = ddict['x']
            else: x = []

            if 'y' in keys: y = ddict['y']
            else: y = []

            if 'm' in keys: monitor = ddict['m']
            else: monitor = []

            self.xSelection = []
            for item in x:
                if item < len(cntlist):
                    counter = cntlist[item]
                    if 0:
                        if counter in self.cntList:
                            self.xSelection.append(self.cntList.index(counter))
                    else:
                        self.xSelection.append(item)

            self.ySelection = []
            for item in y:
                if item < len(cntlist):
                    counter = cntlist[item]
                    if counter in self.cntList:
                        self.ySelection.append(self.cntList.index(counter))
            self.monSelection = []
            for item in monitor:
                if item < len(cntlist):
                    counter = cntlist[item]
                    if counter in self.cntList:
                        self.monSelection.append(self.cntList.index(counter))
            self._update()
        

class CheckBoxItem(qt.QCheckBox):
    def __init__(self, parent, row, col):
        qt.QCheckBox.__init__(self, parent)
        self.__row = row
        self.__col = col
        qt.QObject.connect(self, qt.SIGNAL("clicked(bool)"), self._mySignal)

    def _mySignal(self, value):
        ddict = {}
        ddict["event"] = "clicked"
        ddict["state"] = value
        ddict["row"] = self.__row * 1
        ddict["col"] = self.__col * 1
        self.emit(qt.SIGNAL('CheckBoxItemSignal'), ddict)

def main():
    app = qt.QApplication([])
    tab = SpecFileCntTable()
    tab.build(["Cnt1", "Cnt2", "Cnt3"])
    tab.setCounterSelection({'x':[1, 2], 'y':[4], 'cntlist':["dummy", "Cnt0", "Cnt1", "Cnt2", "Cnt3"]})
    tab.show()
    app.exec_()

if __name__ == "__main__":
    main()