def __selectPreset(self): preset = self.ui.presetComboBox.currentText() try: self.__loadPresetIntoUi(preset) except Exception: # fallback: if the currently selected preset has no values in the configuration file: # store the default values from the gui self.__savePresetFromUi(preset) config.set("EAGenerator", "preset", preset) config.flush()
def __savePreset(self, alert, nameField): preset = nameField.text() presetsList = config.get("EAGenerator", "presets") presets = [name.strip() for name in presetsList.split(",")] if preset not in presets: # append preset's name to the comma separated list presetsList += "," + preset config.set("EAGenerator", "presets", presetsList) config.flush() # reflect changes in ui self.ui.presetComboBox.addItem(preset) self.ui.presetComboBox.setCurrentIndex( self.ui.presetComboBox.count() - 1) self.__savePresetFromUi(preset) alert.close()
def __removePreset(self): preset = self.ui.presetComboBox.currentText() section = "EAGenerator_Preset:" + preset presets = [ name.strip() for name in config.get("EAGenerator", "presets").split(",") ] if preset in presets and len(presets) > 1: delIndex = presets.index(preset) del presets[delIndex] config.set("EAGenerator", "presets", ",".join(presets)) # either select previous preset or the first one newIndex = max(0, delIndex - 1) config.set("EAGenerator", "preset", presets[newIndex]) config.removeSection(section) config.flush() # reflect changes in ui self.ui.presetComboBox.removeItem( self.ui.presetComboBox.currentIndex()) self.ui.presetComboBox.setCurrentIndex(newIndex)
def __savePresetFromUi(self, preset): section = "EAGenerator_Preset:" + preset config.set(section, "colorMutationRate", self.ui.colorMutationRateSpinBox.value()) config.set(section, "colorsRangeFromR", self.ui.colorsFromRSpinBox.value()) config.set(section, "colorsRangeToR", self.ui.colorsToRSpinBox.value()) config.set(section, "colorsRangeFromG", self.ui.colorsFromGSpinBox.value()) config.set(section, "colorsRangeToG", self.ui.colorsToGSpinBox.value()) config.set(section, "colorsRangeFromB", self.ui.colorsFromBSpinBox.value()) config.set(section, "colorsRangeToB", self.ui.colorsToBSpinBox.value()) config.set(section, "contrastRangeFrom", self.ui.contrastFromSpinBox.value()) config.set(section, "contrastRangeTo", self.ui.contrastToSpinBox.value()) config.set(section, "shapeMutationRate", self.ui.shapeMutationRateSpinBox.value()) config.set(section, "shapePolygonPointCount", self.ui.shapePolygonPointCountSpinBox.value()) config.set(section, "initialPopulationSize", self.ui.initialPopulationSizeSpinBox.value()) config.set(section, "targetConfidence", self.ui.targetConfidenceSpinBox.value()) config.set(section, "targetPopulationSize", self.ui.targetPopulationSizeSpinBox.value()) config.flush()
def save(self): config.set('API', 'url', self.lineEditUrl.text()) config.set('API', 'key', self.lineEditKey.text()) config.flush() self.close()