Orange Forum • View topic - Widget dev: settings location

Widget dev: settings location

A place to ask questions about methods in Orange and how they are used and other general support.

Widget dev: settings location

Postby axanthos » Fri Mar 28, 2014 14:55

Hi Aleš,

Sometimes, when I update a widget of Orange Textable, I have to make changes in the code that modify settings (name and/or values). This can lead to undesired effects when a user upgrades to a new version of Textable, because of conflicts between settings that have been automatically saved by Orange Canvas and the new versions of the widgets.

The widget development tutorial used to indicate that the call to OWWidget's __init__ in a widget's own __init__ contained a parameter influencing where this widget's settings would be saved. Quoting docs/extend-widgets/rst/basics.rst in v2.6:

Code: Select all
        def __init__(self, parent=None, signalManager=None):
            OWWidget.__init__(self, parent, signalManager, 'SampleDataA')
... passing the name 'SampleData' which will,
essentially, be used for nothing else than a stem of a file for saving
the parameters of the widgets...

I was thinking of using this to avoid the above mentioned issues, by changing this "stem" to a new value with each new version of a widget (e.g. "TextableConvert_0_12"), but I doesn't seem to have any effect. Has there been a change in the method's signature? Or is there another solution to my problem?

Thank you and best greetings!

Re: Widget dev: settings location

Postby Ales » Mon Mar 31, 2014 11:58

axanthos wrote:Has there been a change in the method's signature? Or is there another solution to my problem?
I changed where settings are stored about a year ago, and also removed that segment from the documentation. The previous way was broken, and would not help you in this case.

The cleanest way I see of adding versioning, is to override the getSettings and setSettings methods of OWWidget:
Code: Select all
def getSettings(self, *args, **kwargs):
    settings = OWWidget.getSettings(self, *args, **kwargs)
    settings["settingsDataVersion"] = (0, 12)
    return settings

def setSettings(self, settings):
    if settings.get("settingsDataVersion", None) == (0, 12):
        settings = settings.copy()
        del settings["settingsDataVersion"]
        OWWidget.setSettings(self, settings)

Note that this would only apply to the plain settings (listed in 'settingsList'). Context dependent settings already have a 'contextDataVersion' (a parameter to the ContextHandler class).

Re: Widget dev: settings location

Postby axanthos » Mon Mar 31, 2014 13:25

Thank you very much for these precise instructions. I'll use them in the add-on's next update.

Return to Questions & Support