def __contains__(self, key): groupings = self._get_groups(key) key = groupings.pop() settings = QSettings(parent=self.parent) for g in groupings: settings.beginGroup(g) r = settings.contains(key) for g in groupings: settings.endGroup() return r
def _on_reset(self): """ Callback for reset button. Prompts user for confirmation, then proceeds to reset settings to default values if confirmed, before updating controls and applying any changes (emits change signal if any changes). """ mb = QMessageBox( QMessageBox.Warning, tr("Reset all settings"), tr("This will reset all settings to their default " + "values. Are you sure you want to continue?"), QMessageBox.Yes | QMessageBox.No) mb.setDefaultButton(QMessageBox.No) dr = mb.exec_() if dr == QMessageBox.Yes: # This clears all settings, and recreates only those values # initialized with set_default this session. Settings.restore_from_defaults() # Now we update controls: s = QSettings(self.ui) keys = list( self._initial_values.keys()) # Use copy, as we may modify for k in keys: # Check if setting is still present if s.contains(k): # Present, update to new value (triggers _on_change) v = s.value(k) w = self._lut[k] if isinstance(w, QLineEdit): w.setText(v) elif isinstance(w, QCheckBox): w.setChecked(v.lower() == "true") elif isinstance(w, (QSpinBox, QDoubleSpinBox)): w.setValue(v) else: # Setting was removed, remove editor w = self._lut[k] layout = w.parent().layout() label = layout.labelForField(w) layout.removeWidget(w) w.close() if label is not None: layout.removeWidget(label) label.close() del self._lut[k] del self._initial_values[k] self._changes[k] = None # Check whether all editors for tab was removed if layout.count() == 0: wrap = w.parent() self.tabs.removeTab(self.tabs.indexOf(wrap)) # Finally apply changes (update _initial_values, and emit signal) self.apply_changes()
def _on_reset(self): """ Callback for reset button. Prompts user for confirmation, then proceeds to reset settings to default values if confirmed, before updating controls and applying any changes (emits change signal if any changes). """ mb = QMessageBox(QMessageBox.Warning, tr("Reset all settings"), tr("This will reset all settings to their default " + "values. Are you sure you want to continue?"), QMessageBox.Yes | QMessageBox.No) mb.setDefaultButton(QMessageBox.No) dr = mb.exec_() if dr == QMessageBox.Yes: # This clears all settings, and recreates only those values # initialized with set_default this session. Settings.restore_from_defaults() # Now we update controls: s = QSettings(self.ui) keys = list(self._initial_values.keys()) # Use copy, as we may modify for k in keys: # Check if setting is still present if s.contains(k): # Present, update to new value (triggers _on_change) v = s.value(k) w = self._lut[k] if isinstance(w, QLineEdit): w.setText(v) elif isinstance(w, QCheckBox): w.setChecked(v.lower() == "true") elif isinstance(w, (QSpinBox, QDoubleSpinBox)): w.setValue(v) else: # Setting was removed, remove editor w = self._lut[k] layout = w.parent().layout() label = layout.labelForField(w) layout.removeWidget(w) w.close() if label is not None: layout.removeWidget(label) label.close() del self._lut[k] del self._initial_values[k] self._changes[k] = None # Check whether all editors for tab was removed if layout.count() == 0: wrap = w.parent() self.tabs.removeTab(self.tabs.indexOf(wrap)) # Finally apply changes (update _initial_values, and emit signal) self.apply_changes()