from PyQt4.QtCore import * from PyQt4.QtGui import * from sface.config import config from sface.screens.sfascreen import SfaScreen class ConfigWidget(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) layout = QVBoxLayout() for (field,msg) in config.field_labels(): # label layout.addWidget(QLabel(msg,self)) # edit : text or checkbox default=config.field_default(field) if isinstance(default,bool): edit=QCheckBox(msg) if config.is_true(config.get(field)): edit.setCheckState(Qt.Checked) else: edit=QLineEdit(config.get(field), self) edit.setAttribute(Qt.WA_MacShowFocusRect, 0) setattr(self,field,edit) layout.addWidget (edit) hlayout = QHBoxLayout() hlayout.addStretch() for (action,label) in [('apply','Apply'), ('save','Apply && Save')]: button=QPushButton(label, self) button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) hlayout.addWidget(button, 0, Qt.AlignRight) hlayout.addSpacing(10) self.connect(button, SIGNAL('clicked()'), getattr(self,action)) layout.addLayout(hlayout) self.setLayout(layout) def apply(self): for field in config.fields(): widget=getattr(self,field) if isinstance(widget,QCheckBox): if widget.checkState() == Qt.Checked: config.set(field, True) else: config.set(field, False) else: config.set(field, str(widget.text())) self.parent().setStatus("Settings loaded for current session", timeout=5000) config.display("after apply") def save(self): self.apply() config.save_config() self.parent().setStatus("Configuration saved in %s !"%config.filename(), timeout=5000) class ConfigScreen(SfaScreen): def __init__(self, parent): SfaScreen.__init__(self, parent) widget = ConfigWidget(self) self.init(widget, "Configure", "Configure the OneLab Federation GUI")