Dividers in UI menus/lists

Posted on
Mon Sep 23, 2019 3:24 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Dividers in UI menus/lists

Is it possible to have a divider in a dynamic list. For example:
    Input 1
    Input 2
    ---------
    Output 1
    Output 2
I can catch the entry in the Callback handler, but since the handler does not receive the full list, I am unsure of what to return. Returning False fails with
    TypeError: Expecting an object of type list; got an object of type bool instead
and if I return nothing I get
    TypeError: Expecting an object of type list; got an object of type NoneType instead

Again, if this were a regular static menu I could just trap the problem in the validation callback.

Thanks for any ideas.

Posted on
Tue Sep 24, 2019 7:11 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Dividers in UI menus/lists

I'm not sure I understand your question, but the dynamic callback list function (documented here) has to return the complete list/menu you want to use. So an example would be:

Code: Select all
def myListGenerator(self, filter="", valuesDict=None, typeId="", targetId=0)
   myArray = [(“option1”, ”First Option”),(“option2”,”Second Option”)]
   return myArray

I'm not sure it will work but try this to see if it will add a separator:

Code: Select all
   myArray = [(“option1”, ”First Option”),(“_Separator”,”_Separator”),(“option2”,”Second Option”)]

Image

Posted on
Tue Sep 24, 2019 7:43 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dividers in UI menus/lists

Sorry, I meant to reply to this earlier. You totally can. Here's the method I use in the Matplotlib plugin for adding a CSV source:

Code: Select all
    def csv_source(self, type_id="", values_dict=None, dev_id=0, target_id=0):
        """
        Construct a list of devices and variables for the CSV engine

        Constructs a list of devices and variables for the user to select within the
        CSV engine configuration dialog box. Devices and variables are listed in
        alphabetical order with devices first and then variables. Category labels
        are also included for  visual clarity.

        -----

        :param unicode type_id:
        :param class 'indigo.Dict' values_dict:
        :param int dev_id:
        :param int target_id:
        """

        list_ = list()

        if values_dict.get('addSourceFilter', 'A') == "D":
            [list_.append(t) for t in [(u"-1", u"%%disabled:Devices%%"), (u"-2", u"%%separator%%")]]
            [list_.append((dev.id, u"{0}".format(dev.name))) for dev in indigo.devices.iter()]

        elif values_dict.get('addSourceFilter', 'A') == "V":
            [list_.append(t) for t in [(u"-3", u"%%separator%%"), (u"-4", u"%%disabled:Variables%%"), (u"-5", u"%%separator%%")]]
            [list_.append((var.id, u"{0}".format(var.name))) for var in indigo.variables.iter()]

        else:
            [list_.append(t) for t in [(u"-1", u"%%disabled:Devices%%"), (u"-2", u"%%separator%%")]]
            [list_.append((dev.id, u"{0}".format(dev.name))) for dev in indigo.devices.iter()]

            [list_.append(t) for t in [(u"-3", u"%%separator%%"), (u"-4", u"%%disabled:Variables%%"), (u"-5", u"%%separator%%")]]
            [list_.append((var.id, u"{0}".format(var.name))) for var in indigo.variables.iter()]

        return list_


Screen Shot 2019-09-24 at 8.40.58 PM.png
Screen Shot 2019-09-24 at 8.40.58 PM.png (130.5 KiB) Viewed 1795 times

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

[My Plugins] - [My Forums]

Posted on
Tue Sep 24, 2019 7:50 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Dividers in UI menus/lists

Listen to Dave. He is right that the UI Name should be "%%separator%%" and not "_Separator".

Image

Posted on
Wed Sep 25, 2019 2:20 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Dividers in UI menus/lists

matt (support) wrote:
I'm not sure I understand your question,...

And I probably didn't explain it very well. Here is the UI field definition from Devices.xml, the code that creates the list and and the Callback handler
Code: Select all
<Field id="deviceSelect" type="menu" >
        <Label>Select Device:</Label>
        <List class='self' method='getDevices' />
        <CallbackMethod>getDevicesExit</CallbackMethod>
</Field>
Code: Select all
def getDevices:
    for key in self.deviceArray:
        menuText = self.deviceArray[key]['serverName']
        menuEntry = (key, menuText)
        returnMenu.append(menuEntry)

    menuEntry = (u'--', u'-------------')
    returnMenu.append(menuEntry)
    menuEntry = (u'DIGITALINPUT', u'Digital Input')
    returnMenu.append(menuEntry)
    menuEntry = (u'DIGITALOUTPUT', u'Digital Output')
    returnMenu.append(menuEntry)
   
    return returnMenu
Code: Select all
def getDevicesExit(self, valuesDict, typeId, devId):
    key = valuesDict['deviceSelect']

    if key == '--':
        errorsDict = indigo.Dict()
        errorsDict['phidgetSelect'] = "Invalid Selection"
        errorsDict["showAlertText"] = "Invalid Selection"
        return errorsDict
    elif key == ...
This creates the menu list as desired, showing the dynamic entries and then the separator and the static entries at the bottom. What I want to do is trap the case where the user selects the separator (value = "--"). Since getDevicesExit is called when there is a menu change, I thought I could trap it there and return an error indication. However, it appears that Indigo is only expecting a single dict in the return from the callback method. The code above produces no visible error message, but it does reset the menu to the original state (- Select an Item-). I suspect it does that because errorsDict is essentially an empty dict - I.e. no entries matching any fields in the UI.

So, the question is, is there a way to display an error in the case noted above? Or, should I just be content with resetting the menu and letting the user figure out what happened?

Posted on
Wed Sep 25, 2019 5:36 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dividers in UI menus/lists

If you take a look at the example code above from the Matplotlib plugin, the separator (and an attending label entry) are sent in a disabled state. This makes it so the user is unable to select the separator or the label text, so there's nothing to trap. I believe you can set each elements' value to anything you want; so long as it's valid XML.

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

[My Plugins] - [My Forums]

Posted on
Wed Sep 25, 2019 7:49 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Dividers in UI menus/lists

DaveL17 wrote:
If you take a look at the example code above from the Matplotlib plugin, ....

Sorry. I left a window open on Matt's first post, and then responded later -- missing your post., Thanks, I think that is exactly what I wanted.

Posted on
Wed Sep 25, 2019 8:24 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dividers in UI menus/lists

No problem! If I had a nickel for every time I did that, I’d be a rich man.


Sent from my iPhone using Tapatalk Pro

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

[My Plugins] - [My Forums]

Posted on
Wed Sep 25, 2019 10:44 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Dividers in UI menus/lists

Just curious... Is this (%%separator%% and %%disabled:foo%%) documented somewhere?

Posted on
Wed Sep 25, 2019 11:15 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Dividers in UI menus/lists

Yes, but it needs to be documented somewhere besides just here. :roll:

Image

Posted on
Wed Sep 25, 2019 1:30 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Dividers in UI menus/lists

matt (support) wrote:

I have observed multiple list entries can contain the same value and I also noticed you and Dave both use negative numeric values in some cases, like the separator. Is that just style (my guess), or is there some semantics to that?

From the "documentation"
Code: Select all
<Field type="menu" id="exampleMenu">
   <Label>Poll device:</Label>
   <List>
      <Option value="0">Only When Activity Detected</Option>
      <Option value="-1">%%separator%%</Option>
      <Option value="60">Every Hour</Option>
      <Option value="30">Every 30 Minutes</Option>
      <Option value="10">Every 10 Minutes</Option>
      <Option value="5">Every 5 Minutes</Option>
      <Option value="1">%%disabled:Every Minute%%</Option>
   </List>
</Field>

Posted on
Wed Sep 25, 2019 6:11 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Dividers in UI menus/lists

berkinet wrote:
...Is that just style (my guess), or is there some semantics to that?

I'm fairly certain that the value can be anything, so long as it's XML compliant. I chose to follow Matt & Jay's lead.

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

[My Plugins] - [My Forums]

Posted on
Sat Sep 28, 2019 12:03 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Dividers in UI menus/lists

Yeah, that is just a notational style we use: negative values for disabled/title/separator type items.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests