2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
5 from sface.config import config
6 from sface.screens.sfascreen import SfaScreen
9 'registry': "usual port for registry: 12345",
10 'slicemgr': ["usual port for slice manager: 12347","usual port for aggregate: 12346"],
13 class ConfigWidget(QWidget):
14 def __init__(self, parent):
15 QWidget.__init__(self, parent)
17 glayout = QGridLayout()
19 for (field,msg) in config.field_labels():
20 # edit : text or checkbox
21 default=config.field_default(field)
22 if static_labels.has_key(field):
23 labels=static_labels[field]
24 if not isinstance(labels,list): labels = [ labels, ]
26 glayout.addWidget(QLabel(label),row,1)
28 if isinstance(default,bool):
30 if config.is_true(config.get(field)):
31 edit.setCheckState(Qt.Checked)
33 edit=QLineEdit(config.get(field) or "", self)
34 edit.setAttribute(Qt.WA_MacShowFocusRect, 0)
35 setattr(self,field,edit)
37 glayout.addWidget(QLabel(msg+":",self), row, 0)
38 glayout.addWidget(edit, row, 1)
42 hlayout = QHBoxLayout()
44 for (action,label) in [('apply','Apply'),
45 ('save','Apply && Save')]:
46 button=QPushButton(label, self)
47 button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
48 hlayout.addWidget(button, 0, Qt.AlignRight)
49 hlayout.addSpacing(10)
50 self.connect(button, SIGNAL('clicked()'), getattr(self,action))
52 layout = QVBoxLayout()
53 layout.addLayout(glayout)
54 layout.addLayout(hlayout)
56 self.setLayout(layout)
60 for field in config.fields():
61 widget=getattr(self,field)
62 if isinstance(widget,QCheckBox):
63 if widget.checkState() == Qt.Checked:
64 config.set(field, True)
66 config.set(field, False)
68 config.set(field, str(widget.text()))
70 self.parent().setStatus("<font color='green'>Settings loaded for current session</font>", timeout=5000)
71 config.display("after apply")
73 self.parent().signalAll('configurationChanged')
79 self.parent().setStatus("<font color='green'>Configuration saved in %s !</font>"%config.filename(), timeout=5000)
81 class ConfigScreen(SfaScreen):
82 def __init__(self, parent):
83 SfaScreen.__init__(self, parent)
85 widget = ConfigWidget(self)
86 self.init(widget, "Configure", "Configure the OneLab SFA crawler")