[ANSWERED]validatePrefsConfigUi() Question

Posted on
Mon Jan 26, 2015 8:56 am
DaveL17 offline
User avatar
Posts: 6786
Joined: Aug 20, 2013
Location: Chicago, IL, USA

[ANSWERED]validatePrefsConfigUi() Question

It seems like changes to config prefs are being written out after validatePrefsConfigUi is called, which leaves me with some behavior that I'm struggling with.

In validatePrefsConfigUi(), I test for
Code: Select all
len(THING) == 0
and get THING through
Code: Select all
self.pluginPrefs.get('THING', None)
for the test.

If a user opens the plugin config dialog and deletes THING, they can save out no problem (doesn't fail the len() test.) But next time the go in and repopulate THING, it fails the len() test even though THING is no longer empty.

Is this behavior because I'm getting the value of THING from pluginPrefs.get()? Can I pull the value from the dialog field itself?

Thanks,
Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Jan 26, 2015 9:28 am
autolog offline
Posts: 3991
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: validatePrefsConfigUi() Question

Try something like:
Code: Select all
        if "THING" in valuesDict:
           self.thing = valuesDict["THING"]
        else:
            self.thing = "<YOUR DEFAULT>"  # Normally equal to value you set in the pluginConf.xml

      # self.thing now contains preference value for THING


I think your code
Code: Select all
self.pluginPrefs.get('THING', None)
would normally be executed outside of the validatePrefsConfigUi when something wants the value.

Hopefully I am correct in this :)

Posted on
Mon Jan 26, 2015 10:38 am
DaveL17 offline
User avatar
Posts: 6786
Joined: Aug 20, 2013
Location: Chicago, IL, USA

validatePrefsConfigUi() Question

Looks like that did the trick.

I already pass valuesDict to validatePrefsConfigUi(), so this works a treat:

Code: Select all
THING = valuesDict['THING']


Thank you!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Jan 26, 2015 11:06 am
autolog offline
Posts: 3991
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: validatePrefsConfigUi() Question

Good to hear it is working for you :)

As I understand it, the advantage / benefit of checking if the value exists in valuesDict and setting a default if it doesn't is that it allows you to add to the config in the future without having to insist that an existing user of the plugin has to go into the plugin config to ensure the value is created in order to avoid getting a plugin run-time error :)

Posted on
Mon Jan 26, 2015 12:24 pm
DaveL17 offline
User avatar
Posts: 6786
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: validatePrefsConfigUi() Question

That's my understanding too--which is why I think I was trying to use it whenever possible...

:D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Jan 26, 2015 5:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18261
Joined: Mar 19, 2008
Location: Austin, Texas

Re: validatePrefsConfigUi() Question

Correct - the validate*ConfigUi() methods are called before the values passed in valuesDict from the actual dialog get stored into the self.pluginPrefs dictionary. This gives you the opportunity to validate user input and, as was pointed out, insert prefs into pluginPrefs that you don't necessarily need to collect from the user (though there are other ways to do that as well).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jan 26, 2015 7:16 pm
DaveL17 offline
User avatar
Posts: 6786
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: [ANSWERED]validatePrefsConfigUi() Question

Thanks Jay!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jan 05, 2016 6:35 pm
ben-p offline
Posts: 9
Joined: Jan 05, 2016

Re: validatePrefsConfigUi() Question

Hey,

hopefully it is ok to extend the thread. I still dont get it, is it possible to save any new value to the pluginProps in any of the validate*Ui methods? I tried several ways without luck, like
Code: Select all
def validateDeviceConfigUi(self, valuesDict, typeId, devId):
        errorDict = indigo.Dict()
   ....
        valuesDict["myNewValue"] = "whatever"
   ----
        if len(errorDict):
            return False, valuesDict, errorDict

        return True, valuesDict


Also the replacePluginPropsOnServer do not work...

It would be a pity to go through the way to store it via self.myNewValue as then I have to store it later in deviceStartComm() to the pluginProps..

Any ideas?

Thanks,
Ben

Posted on
Tue Jan 05, 2016 7:40 pm
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: [ANSWERED]validatePrefsConfigUi() Question

Hi Ben,

No, the valuesDict passed into the validate method (and returned by the validate method) isn't quite the same as pluginProps in that (adding new elems) regard. A future version of Indigo will probably improve that though.

In the mean time you'll need to store the data in your plugin and call repalcePluginPropsOnServer later (outside the scope of a validate method).

Image

Posted on
Wed Jan 06, 2016 2:33 am
ben-p offline
Posts: 9
Joined: Jan 05, 2016

Re: [ANSWERED]validatePrefsConfigUi() Question

Ok thanks for clarification...

Ben

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests