List trouble

Posted on
Tue Sep 03, 2013 8:06 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

List trouble

I'm working on my first plugin, and I'm having trouble. Following the examples, I was able to create a dynamic list, add to it, and remove from it. However, I have found that if the values contain spaces, then they become separate values when iterating over the list of selected options.

This debug log output shows that my RowsData, which is used to create my list, contains three entries. RowsList, however, is supposed to be the entry that I have selected from my List. As you can see, instead of it being a list of one item, it's a list of 4.

Code: Select all
    RowsData : a s df g,z x c v,q w e rt yu i (string)
    RowsList : (list)
          Item : z (string)
          Item : x (string)
          Item : c (string)
          Item : v (string)

I believe my List is defined correctly, as I do get the following additional debug output:

Code: Select all
RowsDataString: a s df g,z x c v,q w e rt yu i
RowsDataList: [u'a s df g', u'z x c v', u'q w e rt yu i']
Row: a s df g
Row: z x c v
Row: q w e rt yu i
returnList: [('a s df g', u'a s df g'), ('z x c v', u'z x c v'), ('q w e rt yu i', u'q w e rt yu i')]


I'm attempting to delete one of the Rows in the list, but since it's not giving me 'z x v c' as a single key, it won't find it in the List.

If my keys do not contain spaces, then everything works fine.

What am I doing wrong? And is this an Indigo-specific thing that I'm doing wrong, or is it a Python thing?

Posted on
Tue Sep 03, 2013 8:38 pm
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: List trouble

Post Update: ignore the text below. Dynamic lists don't use an indigo.Dict key for the list key. The key for a dynamic list can be any string, including those with spaces.

It isn't documented well yet, but the first tuple value (which is the key), needs to follow the rules discussed here for indigo.Dict objects. Internally dynamic lists use the indigo.Dict object, so the key must follow the rules outlined on that post. In this case the problem is the spaces. The second value of the tuple (the value) can be any arbitrary string since it is what is shown in the UI. So it can contain spaces, unicode characters, etc.

Image

Posted on
Tue Sep 03, 2013 9:10 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

Ok. So I'm not a complete idiot then. :)

Reviewing the post you referenced, you say:

    keys cannot start with a number or punctuation character.

Does that mean that if the key were a string, that the string can not start with a number? Can the key be just a number? To get around my problem, I created a counter that counts up from zero, and used that as my key. Then, I looped through my selected keys, and used them as an index into my List (like an array index). Seems to be working for me so far.

Posted on
Tue Sep 03, 2013 9:21 pm
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: List trouble

I might be mistaken but I think that is correct -- it cannot start with a number (as odd as that may seem).

Hmmm... I just realized in your post you are saying it works with a number. In that case a number is okay. :-)

I'll look at this in more detail tomorrow. Maybe my assumption that this is related to the indigo.Dict() differences is incorrect.

Image

Posted on
Tue Sep 03, 2013 10:19 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

I'm pretty sure I'm using an integer, however it is entirely possible that Indigo is converting it to a string before using it as the key.

It would be a very good idea for you to update the Indigo 6 Plug-In guide to include the information that you referred me to about the requirements for the keys. I'm making progress now, but I lost a lot of time trying to figure out what the heck I was doing wrong.

Posted on
Wed Sep 04, 2013 8:24 am
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: List trouble

I looked into this some more. The dynamic lists should be able to handle your original keys. The keys used in the list aren't really used as keys in indigo.Dicts(), so the restrictions I mentioned don't apply (using integers is also fine).

I tried defining a dynamic list function that just returned:

Code: Select all
  return [('a s df g', u'a s df g'), ('z x c v', u'z x c v'), ('q w e rt yu i', u'q w e rt yu i')]


And it seems to work fine. It sounds like the problem you are having is when you are iterating over it at some point. To troubleshoot that I'll need to see some sample code that illustrates the problem.

Image

Posted on
Wed Sep 04, 2013 7:48 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

I have since changed things, but I'll try to show you what it used to be.

In my Devices.xml, I have:

Code: Select all
         <Field id="myRowsList" type="list" rows="10">
            <Label>Data:</Label>
            <List class="self" method="myRowsData" dynamicReload="true"/>
         </Field>
         <Field id="removeMyRow" type="button">
            <Label/>
            <Title>Remove Selected Row</Title>
            <CallbackMethod>removeMyRow</CallbackMethod>
         </Field>
         <Field id="myRowsData" type="textfield" hidden="yes">
            <Label/>
         </Field>


And in plugin.py, I have:

Code: Select all
   def myRowsData(self, filter="", valuesDict=None, typeId="", targetId=0):
      self.debugLog("myRowsData called with filter: %s  typeId: %s  targetId: %s" % (filter, typeId, str(targetId)))
      returnList = list()
      # valuesDict may be empty or None if it's a brand new device
      if valuesDict and "myRowsData" in valuesDict:
         # Get the list of rows
         myRowsDataString = valuesDict["myRowsData"]
      self.debugLog("myRowsDataString: " + myRowsDataString)
      myRowsDataList = myRowsDataString.split(",")
      self.debugLog("myRowsDataList: %s" % myRowsDataList)
      rowNum = 0
      for myRow in myRowsDataList:
         self.debugLog("myRow: " + myRow)
         returnList.append((myRow,myRow))
         rowNum += 1
      self.debugLog("returnList: %s" % returnList)
      return returnList

   def removeMyRow(self, valuesDict=None, typeId="", targetId=0):
      self.debugLog("removeMyRow called with typeId: %s  targetId: %s" % (typeId, str(targetId)))
      self.debugLog("valuesDict = " + str(valuesDict))


There's more to removeMyRow(), but the output of valuesDict should show you that the row that has been selected (myRowsList) has the option split on spaces as separate entries in a list.

I am curious to know if I've done something wrong, but as it turns out, it's a bad idea to use myRow as both the key and the value (because myRow doesn't have to be unique, which would mess up the list). I changed it to append(rowNum,myRow), which is working just fine.

Posted on
Wed Sep 04, 2013 8:22 pm
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: List trouble

I'm afraid I don't follow where in the code is it messing up since the debugLog() line don't match the logging shown in your original post. Glancing at the code I don't see anything wrong, but it isn't clear to me where the problem is occurring (where in the logging does it show the bad data: beginning of myRowsData(), further into myRowsData(), or in removeMyRow())? Basically, I'm lost as to where the problem is occurring and under what circumstances (does removeMyRow() have anything to do with the problem?).

Image

Posted on
Wed Sep 04, 2013 8:36 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

I will put together a plugin and attach it this week. Thanks.

Posted on
Fri Sep 06, 2013 9:17 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

Code: Select all
  Enabling plugin "Example Device - Custom 1.0.1"
  Starting plugin "Example Device - Custom 1.0.1" (pid 40246)
  Started plugin "Example Device - Custom 1.0.1"
  Example Device - Custom Debug   startup called
  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString:
  Example Device - Custom Debug   testRowsDataList: ['']
  Example Device - Custom Debug   testRow:
  Example Device - Custom Debug   returnList: [('', '')]
  Example Device - Custom Error   Found dynamic list element () with no value - skipping that item
  Example Device - Custom Debug   addTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   adding testRow: a s d f to
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : a s d f (string)
     testRowsData : a s d f (string)
     testRowsList : (list)
  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f
  Example Device - Custom Debug   testRowsDataList: [u'a s d f']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f')]
  Example Device - Custom Debug   addTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   adding testRow: qwer to a s d f
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : qwer (string)
     testRowsData : a s d f,qwer (string)
     testRowsList : (list)
  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f,qwer
  Example Device - Custom Debug   testRowsDataList: [u'a s d f', u'qwer']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   testRow: qwer
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f'), (u'qwer', u'qwer')]
  Example Device - Custom Debug   addTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   adding testRow: z x c v to a s d f,qwer
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : z x c v (string)
     testRowsData : a s d f,qwer,z x c v (string)
     testRowsList : (list)
  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f,qwer,z x c v
  Example Device - Custom Debug   testRowsDataList: [u'a s d f', u'qwer', u'z x c v']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   testRow: qwer
  Example Device - Custom Debug   testRow: z x c v
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f'), (u'qwer', u'qwer'), (u'z x c v', u'z x c v')]
  Example Device - Custom Debug   removeTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : z x c v (string)
     testRowsData : a s d f,qwer,z x c v (string)
     testRowsList : (list)
          Item : a (string)
          Item : s (string)
          Item : d (string)
          Item : f (string)
  Example Device - Custom Debug   testRows: [u'a s d f', u'qwer', u'z x c v']
  Example Device - Custom Debug   selectedRows: testRowsList : (list)
     Item : a (string)
     Item : s (string)
     Item : d (string)
     Item : f (string)
  Example Device - Custom Debug   remove row: f
  Example Device - Custom Error   Error in plugin execution UiAction:

Traceback (most recent call last):
  File "plugin.py", line 324, in removeTestRow
<type 'exceptions.ValueError'>: list.remove(x): x not in list

  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f,qwer,z x c v
  Example Device - Custom Debug   testRowsDataList: [u'a s d f', u'qwer', u'z x c v']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   testRow: qwer
  Example Device - Custom Debug   testRow: z x c v
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f'), (u'qwer', u'qwer'), (u'z x c v', u'z x c v')]
  Example Device - Custom Debug   removeTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : z x c v (string)
     testRowsData : a s d f,qwer,z x c v (string)
     testRowsList : (list)
          Item : qwer (string)
  Example Device - Custom Debug   testRows: [u'a s d f', u'qwer', u'z x c v']
  Example Device - Custom Debug   selectedRows: testRowsList : (list)
     Item : qwer (string)
  Example Device - Custom Debug   remove row: qwer
  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f,z x c v
  Example Device - Custom Debug   testRowsDataList: [u'a s d f', u'z x c v']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   testRow: z x c v
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f'), (u'z x c v', u'z x c v')]
  Example Device - Custom Debug   removeTestRow called with typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   valuesDict = UiValuesDict : (dict)
     addTestRow :  (string)
     removeTestRow :  (string)
     testLabel :  (string)
     testRow : z x c v (string)
     testRowsData : a s d f,z x c v (string)
     testRowsList : (list)
          Item : z (string)
          Item : x (string)
          Item : c (string)
          Item : v (string)
  Example Device - Custom Debug   testRows: [u'a s d f', u'z x c v']
  Example Device - Custom Debug   selectedRows: testRowsList : (list)
     Item : z (string)
     Item : x (string)
     Item : c (string)
     Item : v (string)
  Example Device - Custom Debug   remove row: v
  Example Device - Custom Error   Error in plugin execution UiAction:

Traceback (most recent call last):
  File "plugin.py", line 324, in removeTestRow
<type 'exceptions.ValueError'>: list.remove(x): x not in list

  Example Device - Custom Debug   testRowsData called with filter:   typeId: testDevice  targetId: 292353820
  Example Device - Custom Debug   testRowsDataString: a s d f,z x c v
  Example Device - Custom Debug   testRowsDataList: [u'a s d f', u'z x c v']
  Example Device - Custom Debug   testRow: a s d f
  Example Device - Custom Debug   testRow: z x c v
  Example Device - Custom Debug   returnList: [(u'a s d f', u'a s d f'), (u'z x c v', u'z x c v')]
  Example Device - Custom Debug   validateDeviceConfigUi: typeId: testDevice  devId: 292353820
Attachments
Example.indigoPlugin.txt
This is actually a .zip file. Rename it to .zip and then expand it.
(10.37 KiB) Downloaded 148 times

Posted on
Sat Sep 07, 2013 1:33 pm
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: List trouble

Thanks, the example helped me track down the problem.

It occurs when Indigo is trying to translate the selection in the list for the plugin. I've fixed the problem so spaces will be allowed (as long as the first character is alphanumeric), and I added better error reporting for when an illegal ID string is used. These changes will be in 6.0.2 (not yet available).

Image

Posted on
Sat Sep 07, 2013 3:34 pm
dgarozzo offline
Posts: 132
Joined: Jan 08, 2009

Re: List trouble

Awesome. Glad I could help make Indigo more solid. Love the app, and your support. Thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests