/usr/lib/python2.7/dist-packages/PyMca/PyMcaPostBatch.py is in pymca 4.7.1+dfsg-2.
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 | #!/usr/bin/env python
#/*##########################################################################
# Copyright (C) 2004-2012 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# PyMca follows the dual licensing model of 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.
#############################################################################*/
__author__ = "V.A. Sole - ESRF Software Group"
import sys
import os
from PyMca import PyMcaDirs
from PyMca import RGBCorrelator
from PyMca import PyMcaQt as qt
if hasattr(qt, "QString"):
QString = qt.QString
QStringList = qt.QStringList
else:
QString = qt.safe_str
QStringList = list
QTVERSION = qt.qVersion()
class PyMcaPostBatch(RGBCorrelator.RGBCorrelator):
def addBatchDatFile(self, filename, ignoresigma=None):
#test if filename is an EDF ...
#this is a more complete test
#but it would rewire to import too many things
#import QDataSource
#sourceType = QDataSource.getSourceType(filename)
#if sourceType.upper().startswith("EDFFILE"):
# return self.addFileList([filename])
f = open(filename, 'rb')
twoBytes = f.read(2)
f.close()
if sys.version < '3.0':
twoChar = twoBytes
else:
try:
twoChar = twoBytes.decode('utf-8')
except:
twoChar = "__dummy__"
if twoChar in ["II", "MM", "\n{"] or\
twoChar[0] in ["{"] or\
filename.lower().endswith('cbf')or\
(filename.lower().endswith('spe') and twoChar[0] not in ['$']):
#very likely wrapped as EDF
return self.addFileList([filename])
text = qt.safe_str(self.windowTitle())
text += ": " + qt.safe_str(os.path.basename(filename))
self.setWindowTitle(text)
if len(filename) > 4:
if filename[-4:] == ".csv":
csv = True
else:
csv = False
self.controller.addBatchDatFile(filename, ignoresigma, csv=csv)
def addFileList(self, filelist):
"""
Expected to work just with EDF files
"""
text = qt.safe_str(self.windowTitle())
if len(filelist) == 1:
text += ": " + qt.safe_str(os.path.basename(filelist[0]))
else:
text += ": from " + qt.safe_str(os.path.basename(filelist[0])) + \
" to " + qt.safe_str(os.path.basename(filelist[-1]))
self.setWindowTitle(text)
self.controller.addFileList(filelist)
def _getStackOfFiles(self):
wdir = PyMcaDirs.inputDir
fileTypeList = ["Batch Result Files (*dat)",
"EDF Files (*edf)",
"EDF Files (*ccd)",
"TIFF Files (*tif *tiff *TIF *TIFF)",
"Image Files (* jpg *jpeg *tif *tiff *png)",
"All Files (*)"]
message = "Open ONE Batch result file or SEVERAL EDF files"
#if (QTVERSION < '4.3.0') and (sys.platform != 'darwin'):
if PyMcaDirs.nativeFileDialogs:
filetypes = ""
for filetype in fileTypeList:
filetypes += filetype+"\n"
filelist = qt.QFileDialog.getOpenFileNames(self,
message,
wdir,
filetypes)
if not len(filelist):return []
else:
fdialog = qt.QFileDialog(self)
fdialog.setModal(True)
fdialog.setWindowTitle(message)
strlist = QStringList()
for filetype in fileTypeList:
strlist.append(filetype.replace("(","").replace(")",""))
fdialog.setFilters(strlist)
fdialog.setFileMode(fdialog.ExistingFiles)
fdialog.setDirectory(wdir)
ret = fdialog.exec_()
if ret == qt.QDialog.Accepted:
filelist = fdialog.selectedFiles()
fdialog.close()
del fdialog
else:
fdialog.close()
del fdialog
return []
filelist = [qt.safe_str(x) for x in filelist]
if not len(filelist):
return []
PyMcaDirs.inputDir = os.path.dirname(filelist[0])
filelist.sort()
return filelist
def test():
app = qt.QApplication([])
qt.QObject.connect(app,
qt.SIGNAL("lastWindowClosed()"),
app,
qt.SLOT('quit()'))
import getopt
options=''
longoptions=["nativefiledialogs=","transpose=", "fileindex="]
opts, args = getopt.getopt(
sys.argv[1:],
options,
longoptions)
transpose=False
for opt,arg in opts:
if opt in '--nativefiledialogs':
if int(arg):
PyMcaDirs.nativeFileDialogs=True
else:
PyMcaDirs.nativeFileDialogs=False
elif opt in '--transpose':
if int(arg):
transpose=True
elif opt in '--fileindex':
if int(arg):
transpose=True
filelist=args
w = PyMcaPostBatch()
w.layout().setMargin(11)
if not len(filelist):
filelist = w._getStackOfFiles()
if not len(filelist):
print("Usage:")
print("python PyMcaPostBatch.py PyMCA_BATCH_RESULT_DOT_DAT_FILE")
sys.exit(app.quit())
if len(filelist) == 1:
if filelist[0].lower().endswith("dat"):
try:
w.addBatchDatFile(filelist[0])
except ValueError:
w.addFileList(filelist)
else:
w.addFileList(filelist)
else:
w.addFileList(filelist)
if transpose:
w.transposeImages()
w.show()
app.exec_()
if __name__ == "__main__":
test()
|