This file is indexed.

/usr/share/pyshared/PyMca/QSourceSelector.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
#/*##########################################################################
# 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()
import PyMca_Icons as icons
import os
import spswrap as sps
import PyMcaDirs

DEBUG = 0

class QSourceSelector(qt.QWidget):
    def __init__(self, parent=None, filetypelist=None):
        qt.QWidget.__init__(self, parent)
        self.mainLayout= qt.QVBoxLayout(self)
        self.mainLayout.setMargin(0)
        self.mainLayout.setSpacing(0)
        if filetypelist is None:
            self.fileTypeList = ["Spec Files (*mca)",
                                "Spec Files (*dat)",
                                "Spec Files (*spec)",
                                "SPE Files (*SPE)",
                                "EDF Files (*edf)",
                                "EDF Files (*ccd)",
                                "CSV Files (*csv)",
                                "All Files (*)"]
        else:
            self.fileTypeList = filetypelist
        self.lastFileFilter = self.fileTypeList[0]

        # --- file combo/open/close
        self.lastInputDir = PyMcaDirs.inputDir
        self.fileWidget= qt.QWidget(self)
        fileWidgetLayout= qt.QHBoxLayout(self.fileWidget)
        fileWidgetLayout.setMargin(0)
        fileWidgetLayout.setSpacing(0)
        self.fileCombo  = qt.QComboBox(self.fileWidget)
        self.fileCombo.setEditable(0)
        self.mapCombo= {}
        openButton= qt.QToolButton(self.fileWidget)
        if QTVERSION < '4.0.0':
            self.openIcon= qt.QIconSet(qt.QPixmap(icons.fileopen))
            self.closeIcon= qt.QIconSet(qt.QPixmap(icons.fileclose))
            self.specIcon= qt.QIconSet(qt.QPixmap(icons.spec))
            self.reloadIcon = qt.QIconSet(qt.QPixmap(icons.reload))
            openButton.setIconSet(self.openIcon)
            openButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
            closeButton= qt.QToolButton(self.fileWidget)
            closeButton.setIconSet(self.closeIcon)
            specButton= qt.QToolButton(self.fileWidget)
            specButton.setIconSet(self.specIcon)
            refreshButton= qt.QToolButton(self.fileWidget)
            refreshButton.setIconSet(self.reloadIcon)
        else:
            self.openIcon   = qt.QIcon(qt.QPixmap(icons.fileopen))
            self.closeIcon  = qt.QIcon(qt.QPixmap(icons.fileclose))
            self.reloadIcon = qt.QIcon(qt.QPixmap(icons.reload))
            self.specIcon   = qt.QIcon(qt.QPixmap(icons.spec))

            openButton.setIcon(self.openIcon)
            openButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
            openButton.setToolTip("Open new file data source")

            closeButton= qt.QToolButton(self.fileWidget)
            closeButton.setIcon(self.closeIcon)
            closeButton.setToolTip("Close current data source")

            refreshButton= qt.QToolButton(self.fileWidget)
            refreshButton.setIcon(self.reloadIcon)
            refreshButton.setToolTip("Refresh data source")

            specButton= qt.QToolButton(self.fileWidget)
            specButton.setIcon(self.specIcon)
            specButton.setToolTip("Open new shared memory source")

        closeButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
        specButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))
        refreshButton.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed, qt.QSizePolicy.Minimum))

        self.connect(openButton, qt.SIGNAL("clicked()"), self._openFileSlot)
        self.connect(closeButton, qt.SIGNAL("clicked()"), self.closeFile)
        self.connect(refreshButton, qt.SIGNAL("clicked()"),
                         self._reload)
            
        self.connect(specButton, qt.SIGNAL("clicked()"), self.openSpec)
        self.connect(self.fileCombo, qt.SIGNAL("activated(const QString &)"),
                                                     self._fileSelection)

        fileWidgetLayout.addWidget(self.fileCombo)
        fileWidgetLayout.addWidget(openButton)            
        fileWidgetLayout.addWidget(closeButton)
        fileWidgetLayout.addWidget(specButton)
        if sys.platform == "win32":specButton.hide()
        fileWidgetLayout.addWidget(refreshButton)
        self.specButton = specButton
        self.mainLayout.addWidget(self.fileWidget)

    def _reload(self):
        if DEBUG:
            print("_reload called")
        qstring = self.fileCombo.currentText()
        if not len(qstring): return

        key = str(qstring)
        ddict = {}
        ddict["event"] = "SourceReloaded"
        ddict["combokey"] = key
        ddict["sourcelist"] = self.mapCombo[key] * 1
        if QTVERSION < '4.0.0':
            self.emit(qt.PYSIGNAL("SourceSelectorSignal"), (ddict,))    
        else:
            self.emit(qt.SIGNAL("SourceSelectorSignal"), ddict)

    def _openFileSlot(self):
        self.openFile(None, None)
    
    def openSource(self, sourcename, specsession=None):
        if specsession is None:
            if sourcename in sps.getspeclist():
                specsession=True 
            else:
                specsession=False
        self.openFile(sourcename, specsession=specsession)

    def openFile(self, filename=None,justloaded=None, specsession = False):
        if DEBUG:
            print("openfile = ",filename)
        staticDialog = False
        if not specsession:
            if justloaded is None: justloaded = True
            if filename is None:
                if self.lastInputDir is not None:
                    if not os.path.exists(self.lastInputDir):
                        self.lastInputDir = None
                wdir = self.lastInputDir
                if wdir is None:wdir = os.getcwd()
                if QTVERSION < '4.0.0':
                    filetypes = ""
                    for filetype in self.fileTypeList:
                        filetypes += filetype+"\n"
                    if sys.platform == 'win32':
                        filelist = qt.QFileDialog.getOpenFileNames(
                                    filetypes,
                                    wdir,
                                    self,
                                    "openFile",
                                    "Open a new EdfFile")
                    else:
                        filedialog = qt.QFileDialog(self,
                                                    "Open new EdfFile(s)",
                                                    1)
                        if self.lastInputDir is not None:
                            filedialog.setDir(self.lastInputDir)
                        filedialog.setMode(filedialog.ExistingFiles)
                        filedialog.setFilters(filetypes)           
                        if filedialog.exec_loop() == qt.QDialog.Accepted:
                            filelist= filedialog.selectedFiles()
                        else:
                            return              
                else:
                    #if sys.platform == 'win32':
                    #if (QTVERSION < '4.3.0') and (sys.platform != 'darwin'):
                    if (sys.version < '3.0') and PyMcaDirs.nativeFileDialogs:
                        filetypes = ""
                        for filetype in self.fileTypeList:
                            filetypes += filetype+"\n"
                        if sys.version < '3.0':
                            filelist = qt.QFileDialog.getOpenFileNames(self,
                                    "Open a new source file",
                                    wdir,
                                    filetypes,
                                    self.lastFileFilter)
                        else:
                            filelist, self.lastFileFilter =\
                                    qt.QFileDialog.getOpenFileNamesAndFilter(\
                                    self,
                                    "Open a new source file",
                                    wdir,
                                    filetypes,
                                    self.lastFileFilter)
                        staticDialog = True
                    else:
                        fdialog = qt.QFileDialog(self)
                        fdialog.setModal(True)
                        fdialog.setWindowTitle("Open a new source file")
                        if hasattr(qt, "QStringList"):
                            strlist = qt.QStringList()
                        else:
                            strlist = []
                        for filetype in self.fileTypeList:
                            strlist.append(filetype)
                        fdialog.setFilters(strlist)
                        fdialog.selectFilter(self.lastFileFilter)
                        fdialog.setFileMode(fdialog.ExistingFiles)
                        fdialog.setDirectory(wdir)
                        ret = fdialog.exec_()
                        if ret == qt.QDialog.Accepted:
                            filelist = fdialog.selectedFiles()
                            self.lastFileFilter = str(fdialog.selectedFilter())
                            fdialog.close()
                            del fdialog                        
                        else:
                            fdialog.close()
                            del fdialog
                            return            
                #filelist.sort()
                filename=[]
                for f in filelist:
                    filename.append(str(f))
                if not len(filename):
                    return
                if len(filename):
                    self.lastInputDir  = os.path.dirname(filename[0])
                    PyMcaDirs.inputDir = os.path.dirname(filename[0])
                    if staticDialog:
                        if len(filename[0]) > 3:
                            #figure out the selected filter
                            extension = filename[0][-3:]
                            self.lastFileFilter = self.fileTypeList[-1]
                            for fileFilter in self.fileTypeList:
                                if extension == fileFilter[-4:-1]:
                                    self.lastFileFilter = fileFilter
                                    break
                justloaded = True
            if justloaded:
                if type(filename) != type([]):
                    filename = [filename]
            if not os.path.exists(filename[0]):
                if '%' not in filename[0]:
                    raise IOError("File %s does not exist" % filename[0])

            #check if it is a stack
            if len(filename) > 1:
                key = "STACK from %s to %s" % (filename[0], filename[-1])
            else:
                key = os.path.basename(filename[0])
        else:
            key = filename
            if key not in sps.getspeclist():
                qt.QMessageBox.critical(self,
                                    "SPS Error", 
                                    "No shared memory source named %s" % key)
                return
        ddict = {}
        ddict["event"] = "NewSourceSelected"
        if key in self.mapCombo.keys():
            if self.mapCombo[key] == filename:
                #Reloaded event
                ddict["event"] = "SourceReloaded"
            else:
                i = 0
                while key in self.mapCombo.keys():
                    key += "_%d" % i
        ddict["combokey"]   = key
        ddict["sourcelist"] = filename
        self.mapCombo[key] = filename
        if ddict["event"] =="NewSourceSelected":
            nitems = self.fileCombo.count()
            if QTVERSION < '4.0.0':
                self.fileCombo.insertItem(key)
                self.fileCombo.setCurrentItem(nitems)
            else:
                self.fileCombo.insertItem(nitems, key)
                self.fileCombo.setCurrentIndex(nitems)
        else:
            if hasattr(qt, "QString"):
                nitem = self.fileCombo.findText(qt.QString(key))
            else:
                nitem = self.fileCombo.findText(key)
            self.fileCombo.setCurrentIndex(nitem)
        if QTVERSION < '4.0.0':
            self.emit(qt.PYSIGNAL("SourceSelectorSignal"), (ddict,))        
        else:
            self.emit(qt.SIGNAL("SourceSelectorSignal"), ddict)

    def closeFile(self):
        if DEBUG:
            print("closeFile called")
        #get current combobox key
        qstring = self.fileCombo.currentText()
        if not len(qstring): return
        key = str(qstring)
        ddict = {}
        ddict["event"] = "SourceClosed"
        ddict["combokey"] = key
        ddict["sourcelist"] = self.mapCombo[key] * 1
        if hasattr(qt, "QString"):
            nitem = self.fileCombo.findText(qt.QString(key))
        else:
            nitem = self.fileCombo.findText(key)
        self.fileCombo.removeItem(nitem)
        del self.mapCombo[key]
        if QTVERSION < '4.0.0':
            self.emit(qt.PYSIGNAL("SourceSelectorSignal"), (ddict,))    
        else:
            self.emit(qt.SIGNAL("SourceSelectorSignal"), ddict)

    def openSpec(self):
        speclist = sps.getspeclist()
        if not len(speclist):
            qt.QMessageBox.information(self,
                    "No SPEC Shared Memory Found", 
                    "No shared memory source available")
            return
        if QTVERSION < '4.0.0':
            print("should I keep Qt3 version?")
            return
        menu = qt.QMenu()
        for spec in speclist:
            if hasattr(qt, "QString"):
                menu.addAction(qt.QString(spec), 
                        lambda i=spec:self.openFile(i, specsession=True))
            else:
                menu.addAction(spec, 
                        lambda i=spec:self.openFile(i, specsession=True))
        menu.exec_(self.cursor().pos())

    def _fileSelection(self, qstring):
        if DEBUG:
            print("file selected ", qstring)
        key = str(qstring)
        ddict = {}
        ddict["event"] = "SourceSelected"
        ddict["combokey"] = key
        ddict["sourcelist"] = self.mapCombo[key]
        if QTVERSION < '4.0.0':
            self.emit(qt.PYSIGNAL("SourceSelectorSignal"), (ddict,))    
        else:
            self.emit(qt.SIGNAL("SourceSelectorSignal"), ddict)

def test():
    a = qt.QApplication(sys.argv)
    #new access
    import QDataSource
    w= QSourceSelector()
    def mySlot(ddict):
        print(ddict)
        if ddict["event"] == "NewSourceSelected":
            d = QDataSource.QDataSource(ddict["sourcelist"][0])
            w.specfileWidget.setDataSource(d)
            if QTVERSION < '4.0.0':
                a.connect(w, qt.PYSIGNAL("SourceSelectorSignal"),
                      mySlot)
            else:
                a.connect(w, qt.SIGNAL("SourceSelectorSignal"),
                       mySlot)

        
    qt.QObject.connect(a, qt.SIGNAL("lastWindowClosed()"),
              a, qt.SLOT("quit()"))

    if QTVERSION < '4.0.0':
        w.show()
        a.exec_loop()
    else:
        w.show()
        a.exec_()


if __name__=="__main__":
    test()