default value for dynamic lists

Posted on
Sat Sep 14, 2019 1:34 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

default value for dynamic lists

This question was previously asked in 2012. So, now 7 years later I am wondering if the answer might be different, also my use case is a little different.

A plugin offers the user a choice of three log level settings: info, trace, debug. This works fine in a menu (Menu item or plugin config) . However, when the menu opens I would like it to be set to the current level setting (as stored in the plugin preferences or set in plugin.py). The actual menu items are constant. I know I can provide the entire menu via a dynamic list - but I don't see any option to set the default using that approach. So, is there a way to make the default setting for a configUI menu dynamic?

Posted on
Sat Sep 14, 2019 4:14 am
autolog offline
Posts: 3990
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: default value for dynamic lists

From the Plugin Developer Documentation Plugin from @RogueProeliator:

Code: Select all
   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   # This routine returns the initial values for the menu action config dialog, if you
   # need to set them prior to the GUI showing
   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   def getMenuActionConfigUiValues(self, menuId):
      self.debugLogWithLineNum(u'Called getMenuActionConfigUiValues(self, menuId):')
      if self.logMethodParams == True:
         self.debugLogWithLineNum(u'     (' + unicode(menuId) + u')')
      valuesDict = indigo.Dict()
      errorMsgDict = indigo.Dict()
      return (valuesDict, errorMsgDict)
      
It's a useful piece of documentation - see Plugin Developer Documenter Plugin. :)

EDIT: Actually not sure if this is answering your question?

Posted on
Sat Sep 14, 2019 5:31 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: default value for dynamic lists

autolog wrote:
...EDIT: Actually not sure if this is answering your question?

As they say in N.Z. Yeah, Nah. But thanks. The basics of dynamic menus are laid out in the Indigo Plugin Developer's Guide.
Code: Select all
 You may also include custom dynamic lists that are constructed on-the-fly by your plugin. If you defined your list like this:

<Field id="insteonDimmers" type="menu">
   <Label>INSTEON Dimmers:</Label>
   <List class="self" filter="stuff" method="myListGenerator"/>
</Field>
Then your plugin will have the method specified called with the filter. For the above example, you must define a method like this:

def myListGenerator(self, filter="", valuesDict=None, typeId="", targetId=0)
   # From the example above, filter = “stuff”
   # You can pass anything you want in the filter for any purpose
   # Create an array where each entry is a list - the first item is
   # the value attribute and last is the display string that will
   # show up in the control. All parameters are read-only.
   myArray = [(“option1”, ”First Option”),(“option2”,”Second Option”)]
   return myArray
What is missing, at least from the documentation, is the ability to define a defaultValue for the list. I can set defaultValue in the static XML for the Field, but that is useless in this case. Also, at least in my case, the issue is the opposite of the example case: my list is static, only the default value is dynamic.

Posted on
Sat Sep 14, 2019 6:13 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default value for dynamic lists

I think this was actually answered in this thread from 2014: viewtopic.php?f=108&t=12530

If this menu is in the plugin preferences, then you want:
Code: Select all
   def getPrefsConfigUiValues(self):
      prefsConfigUiValues = self.pluginPrefs

# set the default for the preference key here

      return prefsConfigUiValues

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Sep 14, 2019 6:51 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: default value for dynamic lists

FlyingDiver wrote:
I think this was actually answered in this thread from 2014: viewtopic.php?f=108&t=12530

I had seen that topic but didn't get how to apply it to what I am doing. After going over it three more times, I got it. For anyone else in the same situation, here is the part I missed...

To dynamically set the defaultValue for a dynamic list (and possibly any list) you need to create a method with the specific name of getPrefsConfigUiValues
Code: Select all
def getPrefsConfigUiValues(self):
        """ preset the default value for a configUI list """
        prefsConfigUiValues = self.pluginPrefs
        prefsConfigUiValues['field_name'] = some_default_value
        return prefsConfigUiValues
Then, create the actual list statically or dynamicaly as you choose. In other words, the dynamic setting of defaultValue for a dynamic list (menu) is independent of the creation of the list.

BTW, I assume this approach is what Jay referred to as jiggery-pokery

Posted on
Sat Sep 14, 2019 6:55 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default value for dynamic lists

Slight correction.

berkinet wrote:
To dynamically set the defaultValue for a dynamic list (and possibly any list) in the plugin preferences, you need to create a method with the specific name of getPrefsConfigUiValues


This routine is specific to the PluginConfig.xml. There are similar routines for dynamic lists in the other xml files.

Also, you should really check to see if the value already exists before you set it. Your code as written will overwrite an existing selection.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests