2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
5 from sface.config import config
6 from sface.screens.sfascreen import SfaScreen
8 from sfa.util.version import version_core
11 'slice' : "local SFA version : %s" % version_core()['code_tag'],
12 'registry': "usual port for registry: 12345",
13 'slicemgr': ["usual port for slice manager: 12347","usual port for aggregate: 12346"],
16 class ConfigWidget(QWidget):
17 def __init__(self, parent):
18 QWidget.__init__(self, parent)
20 glayout = QGridLayout()
22 for (field,msg) in config.field_labels():
23 # edit : text or checkbox
24 default=config.field_default(field)
25 if static_labels.has_key(field):
26 labels=static_labels[field]
27 if not isinstance(labels,list): labels = [ labels, ]
29 glayout.addWidget(QLabel(label),row,1)
31 if isinstance(default,bool):
33 if config.is_true(config.get(field)):
34 edit.setCheckState(Qt.Checked)
36 edit=QLineEdit(config.get(field) or "", self)
37 edit.setAttribute(Qt.WA_MacShowFocusRect, 0)
38 setattr(self,field,edit)
40 glayout.addWidget(QLabel(msg+":",self), row, 0)
41 glayout.addWidget(edit, row, 1)
45 hlayout = QHBoxLayout()
47 for (action,label) in [('apply','Apply'),
48 ('save','Apply && Save')]:
49 button=QPushButton(label, self)
50 button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
51 hlayout.addWidget(button, 0, Qt.AlignRight)
52 hlayout.addSpacing(10)
53 self.connect(button, SIGNAL('clicked()'), getattr(self,action))
55 layout = QVBoxLayout()
56 layout.addLayout(glayout)
57 layout.addLayout(hlayout)
59 self.setLayout(layout)
63 for field in config.fields():
64 widget=getattr(self,field)
65 if isinstance(widget,QCheckBox):
66 if widget.checkState() == Qt.Checked:
67 config.set(field, True)
69 config.set(field, False)
71 config.set(field, str(widget.text()))
73 self.parent().setStatus("<font color='green'>Settings loaded for current session</font>", timeout=5000)
74 config.display("after apply")
76 self.parent().signalAll('configurationChanged')
82 self.parent().setStatus("<font color='green'>Configuration saved in %s !</font>"%config.filename(), timeout=5000)
84 class ConfigScreen(SfaScreen):
85 def __init__(self, parent):
86 SfaScreen.__init__(self, parent)
88 widget = ConfigWidget(self)
89 self.init(widget, "Configure", "Configure the OneLab SFA crawler")