/usr/share/pyshared/PyMca/QScriptOption.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 | #/*##########################################################################
# 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.
#############################################################################*/
import sys
import PyMcaQt as qt
QTVERSION = qt.qVersion()
import CheckField
import EntryField
import TextField
#import RadioField
import TabSheets
TupleType=type(())
def uic_load_pixmap_RadioField(name):
pix = qt.QPixmap()
m = qt.QMimeSourceFactory.defaultFactory().data(name)
if m:
qt.QImageDrag.decode(m,pix)
return pix
class QScriptOption(TabSheets.TabSheets):
def __init__(self,parent = None,name=None,modal=1,fl = 0,
sheets=(),default=None,nohelp=1,nodefaults=1):
TabSheets.TabSheets.__init__(self,parent,name,modal,fl,
nohelp,nodefaults)
if QTVERSION < '4.0.0':
if name is not None:self.setCaption(str(name))
else:
if name is not None:self.setWindowTitle(str(name))
self.sheets={}
self.sheetslist=[]
self.default=default
self.output={}
self.output.update(self.default)
if QTVERSION >= '3.0.0':
ntabs=self.tabWidget.count()
else:
ntabs = 2
#remove anything not having to do with my sheets
for i in range(ntabs):
if QTVERSION < '4.0.0':
if QTVERSION >= '3.0.0':
page=self.tabWidget.page(0)
self.tabWidget.removePage(page)
else:
self.tabWidget.setCurrentPage(i)
self.tabWidget.removePage(self.tabWidget.currentPage())
else:
self.tabWidget.setCurrentIndex(0)
self.tabWidget.removeTab(self.tabWidget.currentIndex())
for sheet in sheets:
name=sheet['notetitle']
a=FieldSheet(fields=sheet['fields'])
self.sheets[name]=a
a.setdefaults(self.default)
self.sheetslist.append(name)
self.tabWidget.addTab(self.sheets[name],str(name))
if QTVERSION < '4.0.0':
self.tabWidget.showPage(self.sheets[name])
else:
if QTVERSION < '4.2.0':
i = self.tabWidget.indexOf(self.sheets[name])
self.tabWidget.setCurrentIndex(i)
else:
self.tabWidget.setCurrentWidget(self.sheets[name])
#perform the binding to the buttons
self.connect(self.buttonOk,qt.SIGNAL("clicked()"),self.myaccept)
self.connect(self.buttonCancel,qt.SIGNAL("clicked()"),self.myreject)
if not nodefaults:
self.connect(self.buttonDefaults,qt.SIGNAL("clicked()"),self.defaults)
if not nohelp:
self.connect(self.buttonHelp,qt.SIGNAL("clicked()"),self.myhelp)
def myaccept(self):
self.output.update(self.default)
for name,sheet in self.sheets.items():
self.output.update(sheet.get())
#avoid pathologicval None cases
for key in list(self.output.keys()):
if self.output[key] is None:
if key in self.default:
self.output[key]=self.default[key]
self.accept()
return
def myreject(self):
self.output={}
self.output.update(self.default)
self.reject()
return
def defaults(self):
self.output={}
self.output.update(self.default)
def myhelp(self):
print("Default - Sets back to the initial parameters")
print("Cancel - Sets back to the initial parameters and quits")
print("OK - Updates the parameters and quits")
class FieldSheet(qt.QWidget):
def __init__(self,parent = None,name=None,fl = 0,fields=()):
if QTVERSION < '4.0.0':
qt.QWidget.__init__(self,parent,name,fl)
else:
qt.QWidget.__init__(self,parent)
layout= qt.QVBoxLayout(self)
layout.setMargin(0)
layout.setSpacing(0)
#self.fields = ([,,,])
self.fields=[]
self.nbfield= 1
for field in fields:
fieldtype=field[0]
if len(field) == 3:
key = field[1]
else:
key = None
parameters=field[-1]
if fieldtype == "TextField":
myTextField = MyTextField(self,keys=key,params=parameters)
self.fields.append(myTextField)
layout.addWidget(myTextField)
if fieldtype == "CheckField":
myCheckField = MyCheckField(self,keys=key,params=parameters)
self.fields.append(myCheckField)
layout.addWidget(myCheckField)
if fieldtype == "EntryField":
myEntryField = MyEntryField(self,keys=key,params=parameters)
self.fields.append(myEntryField)
layout.addWidget(myEntryField)
if fieldtype == "RadioField":
radioField = RadioField(self,keys=key,params=parameters)
self.fields.append(radioField)
layout.addWidget(radioField)
def get(self):
result={}
for field in self.fields:
result.update(field.getvalue())
return result
def setdefaults(self,dict):
for field in self.fields:
field.setdefaults(dict)
return
class MyTextField(TextField.TextField):
def __init__(self,parent = None,name = None,fl = 0,
keys=(), params = ()):
TextField.TextField.__init__(self,parent,name,fl)
self.TextLabel.setText(str(params))
def getvalue(self):
pass
return
def setvalue(self):
pass
return
def setdefaults(self,dict):
pass
return
class MyEntryField(EntryField.EntryField):
def __init__(self,parent = None,name = None,fl = 0,
keys=(), params = ()):
EntryField.EntryField.__init__(self,parent,name,fl)
self.dict={}
if type(keys) == TupleType:
for key in keys:
self.dict[key]=None
else:
self.dict[keys]=None
self.TextLabel.setText(str(params))
self.connect(self.Entry,qt.SIGNAL("textChanged(const QString&)"),self.setvalue)
def getvalue(self):
return self.dict
def setvalue(self,value):
for key in self.dict.keys():
self.dict[key]=str(value)
return
def setdefaults(self, ddict):
for key in list(self.dict.keys()):
if key in ddict:
self.dict[key] = ddict[key]
self.Entry.setText(str(ddict[key]))
return
class MyCheckField(CheckField.CheckField):
def __init__(self,parent = None,name = None,fl = 0,
keys=(), params = ()):
CheckField.CheckField.__init__(self,parent,name,fl)
self.dict={}
if type(keys) == TupleType:
for key in keys:
self.dict[key]=None
else:
self.dict[keys]=None
self.CheckBox.setText(str(params))
self.connect(self.CheckBox,qt.SIGNAL("stateChanged(int)"),self.setvalue)
def getvalue(self):
return self.dict
def setvalue(self,value):
if value:
val=1
else:
val=0
for key in self.dict.keys():
self.dict[key]=val
return
def setdefaults(self, ddict):
for key in self.dict.keys():
if key in ddict:
if int(ddict[key]):
self.CheckBox.setChecked(1)
self.dict[key]=1
else:
self.CheckBox.setChecked(0)
self.dict[key]=0
return
class RadioField(qt.QWidget):
def __init__(self,parent = None,name = None,fl = 0,
keys=(), params = ()):
if QTVERSION < '4.0.0':
qt.QWidget.__init__(self,parent,name,fl)
if name == None:
self.setName("RadioField")
#self.resize(166,607)
self.setSizePolicy(qt.QSizePolicy(1,1,0,0,self.sizePolicy().hasHeightForWidth()))
self.setCaption(str("RadioField"))
RadioFieldLayout = qt.QHBoxLayout(self,11,6,"RadioFieldLayout")
else:
qt.QWidget.__init__(self,parent)
RadioFieldLayout = qt.QHBoxLayout(self)
RadioFieldLayout.setMargin(11)
RadioFieldLayout.setSpacing(6)
self.RadioFieldBox = qt.QButtonGroup(self)
if QTVERSION < '4.0.0':
self.RadioFieldBox.setSizePolicy(qt.QSizePolicy(1,1,0,0,self.RadioFieldBox.sizePolicy().hasHeightForWidth()))
self.RadioFieldBox.setTitle(str(""))
self.RadioFieldBox.setColumnLayout(0,qt.Qt.Vertical)
self.RadioFieldBox.layout().setSpacing(6)
self.RadioFieldBox.layout().setMargin(11)
RadioFieldBoxLayout = qt.QVBoxLayout(self.RadioFieldBox.layout())
RadioFieldBoxLayout.setAlignment(qt.Qt.AlignTop)
Layout1 = qt.QVBoxLayout(None,0,6,"Layout1")
self.dict={}
if type(keys) == TupleType:
for key in keys:
self.dict[key]=1
else:
self.dict[keys]=1
self.RadioButton=[]
i=0
for text in params:
self.RadioButton.append(qt.QRadioButton(self.RadioFieldBox,
"RadioButton"+"%d" % i))
self.RadioButton[-1].setSizePolicy(qt.QSizePolicy(1,1,0,0,
self.RadioButton[-1].sizePolicy().hasHeightForWidth()))
self.RadioButton[-1].setText(str(text))
Layout1.addWidget(self.RadioButton[-1])
i=i+1
RadioFieldBoxLayout.addLayout(Layout1)
RadioFieldLayout.addWidget(self.RadioFieldBox)
self.RadioButton[0].setChecked(1)
self.connect(self.RadioFieldBox,qt.SIGNAL("clicked(int)"),
self.setvalue)
def getvalue(self):
return self.dict
def setvalue(self,value):
if value:
val=1
else:
val=0
for key in self.dict.keys():
self.dict[key]=val
return
def setdefaults(self, ddict):
for key in list(self.dict.keys()):
if key in ddict:
self.dict[key]=ddict[key]
i=int(ddict[key])
self.RadioButton[i].setChecked(1)
return
def test():
a = qt.QApplication(sys.argv)
qt.QObject.connect(a,qt.SIGNAL("lastWindowClosed()"),
a,qt.SLOT("quit()"))
#w = FieldSheet(fields=(["TextField",'Simple Entry'],
# ["EntryField",'entry','MyLabel'],
# ["CheckField",'label','Check Label'],
# ["RadioField",'radio',('Button1','hmmm','3')]))
sheet1={'notetitle':"First Sheet",
'fields':(["TextField",'Simple Entry'],
["EntryField",'entry','MyLabel'],
["CheckField",'label','Check Label'])}
sheet2={'notetitle':"Second Sheet",
'fields':(["TextField",'Simple Radio Buttons'],
["RadioField",'radio',('Button1','hmmm','3')])}
w=QScriptOption(name='QScriptOptions',sheets=(sheet1,sheet2),
default={'radio':1,'entry':'type here','label':1})
if QTVERSION < '4.0.0':
a.setMainWidget(w)
w.show()
a.exec_loop()
else:
w.show()
a.exec_()
print(w.output)
if __name__ == "__main__":
test()
|