diff options
Diffstat (limited to 'module/gui/SettingsWidget.py')
-rw-r--r-- | module/gui/SettingsWidget.py | 105 |
1 files changed, 94 insertions, 11 deletions
diff --git a/module/gui/SettingsWidget.py b/module/gui/SettingsWidget.py index 6197cee6c..ddfb45994 100644 --- a/module/gui/SettingsWidget.py +++ b/module/gui/SettingsWidget.py @@ -32,38 +32,120 @@ class SettingsWidget(QWidget): def setConnector(self, connector): self.connector = connector - + def loadConfig(self): + if self.sections and self.psections: + self.data = self.connector.proxy.get_config() + self.pdata = self.connector.proxy.get_plugin_config() + + self.reloadSection(self.sections, self.data) + self.reloadSection(self.psections, self.pdata) + + return + if self.layout(): delete(self.layout()) + for s in self.sections.values()+self.psections.values(): delete(s) + self.sections = {} self.setLayout(QVBoxLayout()) self.clearConfig() layout = self.layout() layout.setSizeConstraint(QLayout.SetMinAndMaxSize) - + + general = QTabWidget() + self.general = general + + plugins = QTabWidget() + self.plugins = plugins + + tab = QTabWidget() + self.tab = tab + tab.addTab(general, _("General")) + tab.addTab(plugins, _("Plugins")) + + layout.addWidget(tab) + self.data = self.connector.proxy.get_config() self.pdata = self.connector.proxy.get_plugin_config() for k, section in self.data.items(): - s = Section(section, self) + s = Section(section, general) self.sections[k] = s - layout.addWidget(s) + for k, section in self.pdata.items(): - s = Section(section, self, "plugin") + s = Section(section, plugins, "plugin") self.psections[k] = s - layout.addWidget(s) - + rel = QPushButton(_("Reload")) - layout.addWidget(rel) save = QPushButton(_("Save")) - #layout.addWidget(save) + + layout.addWidget(save) + + cont = QHBoxLayout() + cont.addWidget(rel) + cont.addWidget(save) + + layout.addLayout(cont) + + self.connect(save, SIGNAL("clicked()"), self.saveConfig) self.connect(rel, SIGNAL("clicked()"), self.loadConfig) - + def clearConfig(self): self.sections = {} + def reloadSection(self, sections, pdata): + + for k, section in pdata.iteritems(): + if sections.has_key(k): + widget = sections[k] + for option,data in section.iteritems(): + if widget.inputs.has_key(option): + i = widget.inputs[option] + + if data["type"] == "int": + i.setValue(int(data["value"])) + elif not data["type"].find(";") == -1: + i.setCurrentIndex(i.findText(data["value"])) + elif data["type"] == "bool": + if data["value"]: + i.setCurrentIndex(0) + else: + i.setCurrentIndex(1) + else: + i.setText(data["value"]) + + + def saveConfig(self): + self.data = self.connector.proxy.get_config() + self.pdata = self.connector.proxy.get_plugin_config() + + self.saveSection(self.sections, self.data) + self.saveSection(self.psections, self.pdata, "plugin") + + + def saveSection(self, sections, pdata, sec="core"): + for k, section in pdata.iteritems(): + if sections.has_key(k): + widget = sections[k] + for option,data in section.iteritems(): + if widget.inputs.has_key(option): + i = widget.inputs[option] + + if data["type"] == "int": + if i.value() != data["value"]: + self.connector.proxy.set_conf_val(k, option, i.value(), sec) + elif not data["type"].find(";") == -1: + if i.currentText() != data["value"]: + self.connector.proxy.set_conf_val(k, option, i.currentText(), sec) + elif data["type"] == "bool": + if (data["value"] ^ (not i.currentIndex())): + self.connector.proxy.set_conf_val(k, option, not i.currentIndex(), sec) + else: + if i.text() != data["value"]: + self.connector.proxy.set_conf_val(k, option, str(i.text()), sec) + class Section(QGroupBox): def __init__(self, data, parent, ctype="core"): self.data = data @@ -73,9 +155,10 @@ class Section(QGroupBox): self.ctype = ctype layout = QGridLayout(self) self.setLayout(layout) + parent.addTab(self, data["desc"]) row = 0 - for k, option in self.data.items(): + for k, option in self.data.iteritems(): if k == "desc": continue l = QLabel(option["desc"], self) |