/usr/share/pyshared/PyMca/MatrixEditor.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 | #/*##########################################################################
# Copyright (C) 2004-2010 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.
#############################################################################*/
__revision__ = "$Revision: 1.10 $"
from MaterialEditor import qt
import MaterialEditor
import MatrixImage
QTVERSION = qt.qVersion()
class MatrixEditor(qt.QWidget):
def __init__(self, parent=None, name="Matrix Editor",current=None,
table=True,orientation="vertical",thickness=True,
density=True, size=None):
if QTVERSION < '4.0.0':
qt.QWidget.__init__(self, parent, name)
self.setCaption(name)
else:
qt.QWidget.__init__(self, parent)
self.setWindowTitle(name)
self._current={'Density': 1.0,
'Thickness': 1.0,
'AlphaIn': 45.0,
'AlphaOut': 45.0,
'AlphaScatteringFlag':False,
'AlphaScattering': 90,
'Material': "Water"}
if current is not None: self._current.update(current)
self.build(table,orientation, thickness, density, size)
self._update()
def build(self, table,orientation, thickness, density, size=None):
if size is None: size="medium"
layout = qt.QHBoxLayout(self)
if table:
#the material definition
matBox = qt.QWidget(self)
layout.addWidget(matBox)
matBoxLayout = qt.QVBoxLayout(matBox)
self.materialEditor = MaterialEditor.MaterialEditor(matBox,
comments=False, height=7)
matBoxLayout.addWidget(self.materialEditor)
matBoxLayout.addWidget(VerticalSpacer(matBox))
else:
self.materialEditor = None
#the matrix definition
sampleBox = qt.QWidget(self)
layout.addWidget(sampleBox)
if orientation == "vertical":
sampleBoxLayout = qt.QVBoxLayout(sampleBox)
else:
sampleBoxLayout = qt.QHBoxLayout(sampleBox)
#the image
if orientation == "vertical":
labelHBox = qt.QWidget(sampleBox)
sampleBoxLayout.addWidget(labelHBox)
labelHBoxLayout = qt.QHBoxLayout(labelHBox)
labelHBoxLayout.addWidget(HorizontalSpacer(labelHBox))
label = MatrixImage.MatrixImage(labelHBox,size=size)
labelHBoxLayout.addWidget(label)
labelHBoxLayout.addWidget(HorizontalSpacer(labelHBox))
else:
labelHBox = qt.QWidget(sampleBox)
sampleBoxLayout.addWidget(labelHBox)
labelHBoxLayout = qt.QVBoxLayout(labelHBox)
labelHBoxLayout.setMargin(0)
labelHBoxLayout.setSpacing(4)
label = MatrixImage.MatrixImage(labelHBox,size=size)
labelHBoxLayout.addWidget(label)
if orientation != "vertical":
labelHBoxLayout.addWidget(VerticalSpacer(labelHBox))
self.imageLabel = label
#the input fields container
self.__gridSampleBox = qt.QWidget(sampleBox)
grid = self.__gridSampleBox
sampleBoxLayout.addWidget(grid)
if QTVERSION < '4.0.0':
gridLayout=qt.QGridLayout(grid,6,2,11,4)
else:
gridLayout = qt.QGridLayout(grid)
gridLayout.setMargin(11)
gridLayout.setSpacing(4)
#the angles
angle1Label = qt.QLabel(grid)
angle1Label.setText("Incoming Angle (deg.):")
self.__angle1Line = MyQLineEdit(grid)
self.__angle1Line.setReadOnly(False)
angle2Label = qt.QLabel(grid)
angle2Label.setText("Outgoing Angle (deg.):")
self.__angle2Line = MyQLineEdit(grid)
self.__angle2Line.setReadOnly(False)
self.__angle3Label = qt.QCheckBox(grid)
self.__angle3Label.setText("Scattering Angle (deg.):")
self.__angle3Line = MyQLineEdit(grid)
self.__angle3Line.setReadOnly(False)
self.__angle3Line.setDisabled(True)
if QTVERSION < '4.0.0':
angle1Label.setAlignment(qt.QLabel.WordBreak | \
qt.QLabel.AlignVCenter)
angle2Label.setAlignment(qt.QLabel.WordBreak | \
qt.QLabel.AlignVCenter)
else:
angle1Label.setAlignment(qt.Qt.AlignVCenter)
angle2Label.setAlignment(qt.Qt.AlignVCenter)
self.__angle3Label.setChecked(0)
gridLayout.addWidget(angle1Label, 0, 0)
gridLayout.addWidget(self.__angle1Line, 0, 1)
gridLayout.addWidget(angle2Label, 1, 0)
gridLayout.addWidget(self.__angle2Line, 1, 1)
gridLayout.addWidget(self.__angle3Label, 2, 0)
gridLayout.addWidget(self.__angle3Line, 2, 1)
rowoffset = 3
#thickness and density
if density:
densityLabel = qt.QLabel(grid)
densityLabel.setText("Sample Density (g/cm3):")
if QTVERSION < '4.0.0':
densityLabel.setAlignment(qt.QLabel.WordBreak | \
qt.QLabel.AlignVCenter)
else:
densityLabel.setAlignment(qt.Qt.AlignVCenter)
self.__densityLine = MyQLineEdit(grid)
self.__densityLine.setReadOnly(False)
gridLayout.addWidget(densityLabel, rowoffset, 0)
gridLayout.addWidget(self.__densityLine, rowoffset, 1)
rowoffset = rowoffset + 1
else:
self.__densityLine = None
if thickness:
thicknessLabel = qt.QLabel(grid)
thicknessLabel.setText("Sample Thickness (cm):")
if QTVERSION < '4.0.0':
thicknessLabel.setAlignment(qt.QLabel.WordBreak | \
qt.QLabel.AlignVCenter)
else:
thicknessLabel.setAlignment(qt.Qt.AlignVCenter)
self.__thicknessLine = MyQLineEdit(grid)
self.__thicknessLine.setReadOnly(False)
gridLayout.addWidget(thicknessLabel, rowoffset, 0)
gridLayout.addWidget(self.__thicknessLine, rowoffset, 1)
rowoffset = rowoffset + 1
else:
self.__thicknessLine = None
gridLayout.addWidget(VerticalSpacer(grid), rowoffset, 0)
gridLayout.addWidget(VerticalSpacer(grid), rowoffset, 1)
if QTVERSION < '4.0.0':
self.connect(self.__angle1Line,qt.PYSIGNAL('MyQLineEditSignal'),
self.__angle1Slot)
self.connect(self.__angle2Line, qt.PYSIGNAL('MyQLineEditSignal'),
self.__angle2Slot)
self.connect(self.__angle3Line, qt.PYSIGNAL('MyQLineEditSignal'),
self.__angle3Slot)
if self.__densityLine is not None:
self.connect(self.__densityLine, qt.PYSIGNAL('MyQLineEditSignal'),
self.__densitySlot)
if self.__thicknessLine is not None:
self.connect(self.__thicknessLine,qt.PYSIGNAL('MyQLineEditSignal'),
self.__thicknessSlot)
else:
self.connect(self.__angle1Line,qt.SIGNAL('MyQLineEditSignal'),
self.__angle1Slot)
self.connect(self.__angle2Line, qt.SIGNAL('MyQLineEditSignal'),
self.__angle2Slot)
self.connect(self.__angle3Line, qt.SIGNAL('MyQLineEditSignal'),
self.__angle3Slot)
if self.__densityLine is not None:
self.connect(self.__densityLine, qt.SIGNAL('MyQLineEditSignal'),
self.__densitySlot)
if self.__thicknessLine is not None:
self.connect(self.__thicknessLine,qt.SIGNAL('MyQLineEditSignal'),
self.__thicknessSlot)
self.connect(self.__angle3Label, qt.SIGNAL('clicked()'),
self.__angle3LabelSlot)
if orientation == "vertical":
sampleBoxLayout.addWidget(VerticalSpacer(sampleBox))
def setParameters(self, param):
for key in param.keys():
self._current[key] = param[key]
self._update()
def getParameters(self, param = None):
if param is None:
return copy(self._current)
elif param in self._current.keys():
return self._current[param]
else:
raise KeyError("%s" % param)
return
def _update(self):
if self.materialEditor is not None:
self.materialEditor.materialGUI.setCurrent(self._current['Material'])
self.__angle1Line.setText("%.5g" % self._current['AlphaIn'])
self.__updateImage()
self.__angle2Line.setText("%.5g" % self._current['AlphaOut'])
if self._current['AlphaScatteringFlag']:
self.__angle3Label.setChecked(1)
self.__angle3Line.setEnabled(True)
self.__angle3Line.setText("%.5g" % self._current['AlphaScattering'])
else:
self.__angle3Label.setChecked(False)
self.__angle3LabelSlot()
if self.__densityLine is not None:
self.__densityLine.setText("%.5g" % self._current['Density'])
if self.__thicknessLine is not None:
self.__thicknessLine.setText("%.5g" % self._current['Thickness'])
def __angle1Slot(self, ddict):
if (ddict['value'] < -90.) or (ddict['value'] > 90.):
msg=qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Incident beam angle has to be in the range [-90, 90]")
if QTVERSION < '4.0.0':
msg.exec_loop()
else:
msg.setWindowTitle("Angle Error")
msg.exec_()
self.__angle1Line.setFocus()
return
doit = False
if self._current['AlphaIn'] > 0:
if ddict['value'] < 0:
doit = True
elif self._current['AlphaIn'] < 0:
if ddict['value'] > 0:
doit = True
self._current['AlphaIn'] = ddict['value']
if doit:
self.__updateImage()
self.__updateScattering()
def __updateImage(self):
if self._current['AlphaIn'] < 0:
self.imageLabel.setPixmap("image2trans")
else:
self.imageLabel.setPixmap("image2")
def __angle2Slot(self, ddict):
if (ddict['value'] <= 0.0) or (ddict['value'] > 180.):
msg=qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Fluorescent beam angle has to be in the range ]0, 180[")
if QTVERSION < '4.0.0':
msg.exec_loop()
else:
msg.setWindowTitle("Angle Error")
msg.exec_()
self.__angle2Line.setFocus()
return
self._current['AlphaOut'] = ddict['value']
self.__updateScattering()
def __angle3Slot(self, ddict):
self._current['AlphaScattering'] = ddict['value']
def __angle3LabelSlot(self):
if self.__angle3Label.isChecked():
self._current['AlphaScatteringFlag'] = 1
self.__angle3Line.setEnabled(True)
else:
self._current['AlphaScatteringFlag'] = 0
self.__angle3Line.setEnabled(False)
self.__updateScattering()
def __updateScattering(self):
if not self.__angle3Label.isChecked():
self._current['AlphaScattering'] = self._current['AlphaIn'] +\
self._current['AlphaOut']
self.__angle3Line.setText("%.5g" % self._current['AlphaScattering'])
def __thicknessSlot(self, ddict):
self._current['Thickness'] = ddict['value']
def __densitySlot(self, ddict):
self._current['Density'] = ddict['value']
class MyQLineEdit(qt.QLineEdit):
def __init__(self,parent=None,name=None):
qt.QLineEdit.__init__(self,parent)
if QTVERSION < '4.0.0':
self.connect(self, qt.SIGNAL("returnPressed()"), self.__mySlot)
else:
self.connect(self, qt.SIGNAL("editingFinished()"), self.__mySlot)
if QTVERSION < '4.0.0':
def focusInEvent(self,event):
if QTVERSION < '3.0.0':
pass
else:
if QTVERSION < '4.0.0':
self.backgroundcolor = self.paletteBackgroundColor()
self.setPaletteBackgroundColor(qt.QColor('yellow'))
def focusOutEvent(self,event):
if QTVERSION < '3.0.0':
pass
else:
self.setPaletteBackgroundColor(qt.QColor('white'))
self.__mySlot()
def setPaletteBackgroundColor(self, color):
if QTVERSION < '3.0.0':
pass
elif QTVERSION < '4.0.0':
qt.QLineEdit.setPaletteBackgroundColor(self, color)
else:
pass
def __mySlot(self):
qstring = self.text()
text = str(qstring)
try:
if len(text):
value = float(str(qstring))
ddict={}
ddict['event'] = 'returnPressed'
ddict['value'] = value
ddict['text'] = text
ddict['qstring'] = qstring
if QTVERSION < '4.0.0':
self.emit(qt.PYSIGNAL('MyQLineEditSignal'),(ddict,))
else:
self.emit(qt.SIGNAL('MyQLineEditSignal'), ddict)
except:
msg=qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("Invalid Float")
if QTVERSION < '4.0.0':
msg.exec_loop()
else:
msg.exec_()
self.setFocus()
class HorizontalSpacer(qt.QWidget):
def __init__(self, *args):
qt.QWidget.__init__(self, *args)
self.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed))
class VerticalSpacer(qt.QWidget):
def __init__(self, *args):
qt.QWidget.__init__(self, *args)
self.setSizePolicy(qt.QSizePolicy(qt.QSizePolicy.Fixed,qt.QSizePolicy.Expanding))
if __name__ == "__main__":
app = qt.QApplication([])
qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"),app,qt.SLOT("quit()"))
#demo = MatrixEditor(table=False, orientation="horizontal")
demo = MatrixEditor(table=True, orientation="vertical")
if QTVERSION < '4.0.0':
app.setMainWidget(demo)
demo.show()
app.exec_loop()
else:
demo.show()
app.exec_()
|