pythonguis / pyqtconfig

A PyQt config manager. Keep Qt widgets in sync with an config dictionary and/or QSettings object.
Other
133 stars 33 forks source link

Feature Request: Save values of QSettingsManager manually #13

Closed stlehmann closed 9 years ago

stlehmann commented 9 years ago

I often have the usecase of using a QDialog with OK and Cancel button to change certain settings. The changes made should only be stored if Ok was hit by the user. Otherwise they should be dismissed. Is there already a way to realise this feature? Otherwise it would be a great plus in usability.

mfitzp commented 9 years ago

Currently when I want to do this I create a temporary settings instance for the config window and copy in the global settings to it with set_many.. A dictionary (e.g. that could also be used for set_defaults) is used to filter the values to make sure it only adds settings that should be set on the window.

defaults = {
   'a': 5,
   'b': 10,
}

dialog.config.set_defaults(defaults)
dialog.config.set_many({k:global_settings(k) for k in defaults.keys()}

Then assuming OK is pressed I then copy these back to the global settings instance (using global_settings.set_many(dialog.config.as_dict) )

So it's already possible, but it would probably be nice to have a simpler interface for doing this. The most elegant way would be some kind of .hold() and .commit() or .discard() API but that would have to account for things being updated from elsewhere (you only want to lock the options in the dialog).

Is the method above workable for you?

On 21 July 2015 at 14:11, Stefan Lehmann notifications@github.com wrote:

I often have the usecase of using a QDialog with OK and Cancel button to change certain settings. The changes made should only be stored if Ok was hit by the user. Otherwise they should be dismissed. Is there already a way to realise this feature? Otherwise it would be a great plus in usability.

— Reply to this email directly or view it on GitHub https://github.com/mfitzp/pyqtconfig/issues/13.

stlehmann commented 9 years ago

I didn' t know the set_many() function so your approach seems a workable way for me.