QSettings is a cross-platform abstraction that can be used for saving preferences, so hopefully that obviates the use of #IFDEFs
I also found that it has really good performance. So good, in fact, that I just installed an event listener and called save()
upon every single event.
The form's class contains an event filter like this:
def __init__(self, *args, **kwargs):
# ....
self.installEventFilter(self)
# ....
def eventFilter(self, obj, event):
self.save()
return False
And my save()
method looks like this:
self.app.settings.setValue(self.state_key, self.header.saveState())
self.app.settings.setValue(self.geometry_key, self.header.saveGeometry())
self.app.settings.setValue("connect_timeout_spinBox_value", self.connect_timeout_spinBox.value())
self.app.settings.setValue("reveal_downloads_checkbox_checked", self.reveal_downloads_checkbox.checkState())
So, yes, you have to do some leg-work yourself to get your prefs saved immediately - but I didn't find it too arduous.
And although it (still) feels a bit ham-fisted to spray out save()s on every event, QSettings
fine performance made this operation undetectable to the user.
Writing a small class which enumerates every widget on a form and saves/restores each of its properties in QSettings
would also be neat. This might be appropriate if you have some some tens/hundreds of preferences. I'll post back here when I've done it.