/usr/share/pyshared/PyMca/SimpleFitBatchGUI.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 | #!/usr/bin/env python
###########################################################################
# 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 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., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, 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.
#############################################################################
import sys
import os
import PyMcaQt as qt
from PyMca_Icons import IconDict
import PyMcaDirs
import PyMcaFileDialogs
PyMcaDirs.nativeFileDialogs = False
QTVERSION = qt.qVersion()
HDF5SUPPORT = True
import QDataSource
class SimpleFitBatchParameters(qt.QWidget):
def __init__(self, parent=None, file_browser=True):
qt.QWidget.__init__(self, parent)
self.setWindowTitle("PyMca Simple Fit Batch GUI")
self.setWindowIcon(qt.QIcon(qt.QPixmap(IconDict['gioconda16'])))
self.mainLayout = qt.QGridLayout(self)
self.mainLayout.setMargin(2)
self.mainLayout.setSpacing(2)
self._inputDir = None
self._outputDir = None
self._lastInputFileFilter = None
self._fileList = []
self._build(file_browser)
def _build(self, file_browser):
row = 0
if file_browser:
self._listLabel = qt.QLabel(self)
self._listLabel.setText("Input File list:")
self._listView = qt.QTextEdit(self)
self._listView.setMaximumHeight(30*self._listLabel.sizeHint().height())
self._listButton = qt.QPushButton(self)
self._listButton.setText('Browse')
self._listButton.setAutoDefault(False)
self.connect(self._listButton,qt.SIGNAL('clicked()'),self.browseList)
self.mainLayout.addWidget(self._listLabel, 0, 0, qt.Qt.AlignTop|qt.Qt.AlignLeft)
self.mainLayout.addWidget(self._listView, 0, 1)
self.mainLayout.addWidget(self._listButton, 0, 2, qt.Qt.AlignTop|qt.Qt.AlignRight)
row += 1
#options
labels = ['Fit Configuration File:', 'Output Directory:']
row0 = 0
for label in labels:
l = qt.QLabel(self)
l.setText(label)
line = qt.QLineEdit(self)
b = qt.QPushButton(self)
b.setText('Browse')
self.mainLayout.addWidget(l, row+row0, 0)
self.mainLayout.addWidget(line, row+row0, 1)
self.mainLayout.addWidget(b, row+row0, 2)
if row0 == 0:
self._fitConfigurationLine = line
self._fitConfigurationButton = b
else:
self._outputDirectoryLine = line
self._outputDirectoryButton = b
row0 += 1
row += row0
self.connect(self._outputDirectoryButton,
qt.SIGNAL('clicked()'),
self.browseOutputDirectory)
self.connect(self._fitConfigurationButton,
qt.SIGNAL('clicked()'),
self.browseFitConfiguration)
def browseList(self):
if self._inputDir is None:
self._inputDir = PyMcaDirs.inputDir
elif os.path.exists(self._inputDir):
PyMcaDirs.inputDir = self._inputDir
filetypes = ["Mca Files (*.mca)",
"Edf Files (*.edf)"]
if HDF5SUPPORT:
filetypes.append("HDF5 Files(*.nxs *.h5 *.hdf)")
filetypes.append("SPEC Files (*.spec)")
filetypes.append("SPEC Files (*.dat)")
filetypes.append("All files (*)")
message = "Open a set of files"
mode = "OPEN"
getfilter = True
currentfilter = self._lastInputFileFilter
fileList, fileFilter = PyMcaFileDialogs.getFileList(self,
filetypelist=filetypes,
message=message,
mode=mode,
getfilter=getfilter,
single=False,
currentfilter=currentfilter)
if not len(fileList):
return
else:
self._lastInputFileFilter = fileFilter
self._inputDir = os.path.dirname(fileList[0])
if (QTVERSION < '4.2.0') or (not len(self._fileList)):
self.setFileList(fileList)
self.raise_()
return
msg = qt.QMessageBox()
msg.setWindowTitle("Append or replace")
msg.setIcon(qt.QMessageBox.Information)
msg.setText("Do you want to delete current file list?")
msg.setStandardButtons(qt.QMessageBox.Yes|qt.QMessageBox.No)
answer=msg.exec_()
if answer == qt.QMessageBox.Yes:
append = False
else:
append = True
self.setFileList(fileList, append=append)
self.raise_()
def browseFitConfiguration(self):
if self._inputDir is None:
self._inputDir = PyMcaDirs.inputDir
elif os.path.exists(self._inputDir):
PyMcaDirs.inputDir = self._inputDir
filetypes = ["Configuration Files (*.cfg)"]
if self._inputDir is None:
self._inputDir = PyMcaDirs.inputDir
elif os.path.exists(self._inputDir):
PyMcaDirs.inputDir = self._inputDir
message = "Select a Simple Fit Configuration File"
mode = "OPEN"
getfilter = False
currentfilter = None #self._lastInputFileFilter
fileList = PyMcaFileDialogs.getFileList(self,
filetypelist=filetypes,
message=message,
mode=mode,
getfilter=getfilter,
single=True,
currentfilter=currentfilter)
if not len(fileList):
return
self._inputDir = os.path.dirname(fileList[0])
self.setFitConfigurationFile(fileList[0])
self.raise_()
def browseOutputDirectory(self):
if self._outputDir is None:
self._outputDir = PyMcaDirs.outputDir
elif os.path.exists(self._outputDir):
PyMcaDirs.inputDir = self._outputDir
message = "Select a Simple Fit Configuration File"
mode = "OPEN"
fileList = PyMcaFileDialogs.getExistingDirectory(self,
message=message,
mode=mode)
if not len(fileList):
return
if type(fileList) != type([]):
fileList = [fileList]
self._outputDir = os.path.dirname(fileList[0])
self.setOutputDirectory(fileList[0])
self.raise_()
def setFileList(self, filelist, append=False):
if filelist is None:
filelist = []
if not append:
self._fileList = []
self._listView.clear()
text = ""
for ffile in self._fileList:
text += ffile + "\n"
for ffile in filelist:
if ffile not in self._fileList:
self._fileList.append(ffile)
text += ffile + "\n"
self._listView.insertPlainText(text)
sourceType = QDataSource.getSourceType(self._fileList[0])
dataSourceClass = QDataSource.source_types[sourceType]
dataSourceWidget = QDataSource.source_widgets[sourceType]
self._dataSource = dataSourceClass(self._fileList[0])
self._dataWidget = dataSourceWidget()
self._dataWidget.setDataSource(self._dataSource)
self.connect(self._dataWidget,
qt.SIGNAL('addSelection'), self.printSelection)
self._dataWidget.show()
def setFitConfigurationFile(self, fname):
self._fitConfigurationLine.setText(fname)
def setOutputDirectory(self, fname):
self._outputDirectoryLine.setText(fname)
def printSelection(self, ddict):
print("Received = ", ddict)
def getParameters(self):
ddict = {}
ddict['selection'] = {}
ddict['selection']['x'] = None
ddict['selection']['y'] = None
ddict['selection']['m'] = None
ddict['filelist'] = self._fileList
ddict['outputdir'] = str(self._outputDirectoryLine.text())
ddict['fitconfiguration'] = str(self._fitConfigurationLine.text())
return ddict
class SimpleFitBatchGUI(qt.QWidget):
def __init__(self, parent=None, stack=False, actions=True):
qt.QWidget.__init__(self, parent)
if stack in [None, False]:
file_browser = False
else:
file_browser = True
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setMargin(2)
self.mainLayout.setSpacing(2)
self.parametersWidget = SimpleFitBatchParameters(self)
self.getParameters = self.parametersWidget.getParameters
self.mainLayout.addWidget(self.parametersWidget)
if actions:
self.actionsBox = qt.QWidget(self)
self.actionsBox.mainLayout = qt.QHBoxLayout(self.actionsBox)
self.actionsBox.mainLayout.setMargin(2)
self.actionsBox.mainLayout.setSpacing(2)
self.closeButton = qt.QPushButton(self.actionsBox)
self.closeButton.setText("Close")
self.startButton = qt.QPushButton(self.actionsBox)
self.startButton.setText("Start")
self.actionsBox.mainLayout.addWidget(qt.HorizontalSpacer(self.actionsBox))
self.actionsBox.mainLayout.addWidget(self.closeButton)
self.actionsBox.mainLayout.addWidget(qt.HorizontalSpacer(self.actionsBox))
self.actionsBox.mainLayout.addWidget(self.startButton)
self.actionsBox.mainLayout.addWidget(qt.HorizontalSpacer(self.actionsBox))
self.mainLayout.addWidget(self.actionsBox)
self.connect(self.closeButton,
qt.SIGNAL('clicked()'),
self.close)
if __name__ == "__main__":
app = qt.QApplication([])
w = SimpleFitBatchGUI()
w.show()
app.exec_()
|