Device selection order

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Tue Jan 15, 2013 1:24 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Device selection order

Is there a way to control the order a plugin's devices appear in the device selection popup menu? If the only way is via the ASCII sort sequence, what are the rules on device naming?

Posted on
Tue Jan 15, 2013 7:50 am
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: Device selection order

They are sorted by name only. Devices should be able to have arbitrary string names as long as they have legal character encodings.

You might want to use folders though instead for organization. Plugins can create folders and move devices they create/own into those folders:

Code: Select all
newFolder = indigo.devices.folder.create("myPluginFolderName")
indigo.device.moveToFolder(dev1, value=newFolder)
indigo.device.moveToFolder(dev2, value=newFolder)
indigo.device.moveToFolder(dev3, value=newFolder)
indigo.device.moveToFolder(dev4, value=newFolder)

Image

Posted on
Tue Jan 15, 2013 11:00 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

Matt: Sorry if I wasn't clear. I was referring to the popup list of Device types that is presented in the Device ConfigUI. The list drawn from the id parameter in the Device tags in Devices.xml.

I would like to control the order the types are presented.

Posted on
Tue Jan 15, 2013 11:15 am
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: Device selection order

Are you referring to the device type shown in the main Device dialog (before the plugin config UI dialog is shown)?

I don't recall how that works -- is it currently sorting alpha numerically versus the order of definition in the XML file?

Image

Posted on
Tue Jan 15, 2013 11:27 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

Yes. To be more accurate, it is the model. As in...
ss.png
ss.png (58.63 KiB) Viewed 3499 times
It appears to be an alpha sort on the Device's id parameter. It also appears that the character set is restricted. Starting the id with characters like • to force a sort order throws errors.

Posted on
Tue Jan 15, 2013 3:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 18256
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Device selection order

It's alphabetical by type name (not id). I inserted a bullet and it worked fine - what was the error it threw?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2013 3:47 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

Sorry, I was unclear. The error is thrown when the device is queried.

So, this...
Code: Select all
<Device id="ifKit" type="custom" >
      <Name>•Phidgets Interface Kit</Name>


results in this...
Code: Select all
>>> print indigo.devices[1267280394]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2022' in position 1788: ordinal not in range(128)

Posted on
Tue Jan 15, 2013 4:13 pm
jay (support) offline
Site Admin
User avatar
Posts: 18256
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Device selection order

That's because the python "print" statement tries to use str() on the value - which won't work because the bullet is a unicode character.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2013 4:16 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

So, I can use characters like •, ≥, etc. to "force" a sort order, but, I wouldn't be able to print them out easily (like for testing, etc.).

Sounds like it isn't worth it, and would certainly confuse others don the road.

Thanks.

Posted on
Tue Jan 15, 2013 4:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18256
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Device selection order

Yep - using odd characters to force sort order is rarely a good idea.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2013 4:40 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

Agreed. So, could you throw this into the circular file of someday features... a Device model tag <Sort> if it existed, the contents would be used to create the sort, following the same rules used for <Name>. If it did not exist, then Sort would = Name.

So, I could code:
Code: Select all
<Device id="ifKit" type="custom" >
      <Name>Phidgets Interface Kit</Name>
                <Sort>1</Sort>
                ...

Posted on
Tue Jan 15, 2013 5:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 18256
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Device selection order

Ok - after some investigation (because this sounded familiar), I've found that unlike the events and actions, we are sorting the device types based on the device type name (as identified above). Not sure why we did that exactly (probably had some reason), but we can't remember why.

It seems like the better idea is to allow the device types to be sorted by the order they are declared in the XML just like we do events and actions. So we'll make that change in the next release unless someone has a problem with it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2013 5:16 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Device selection order

Great. No objection here,

Thanks.

Posted on
Wed Jan 16, 2013 1:32 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Device selection order

jay (support) wrote:
It seems like the better idea is to allow the device types to be sorted by the order they are declared in the XML just like we do events and actions. So we'll make that change in the next release unless someone has a problem with it.

I object!! :twisted:

/me trolling


(I don't actually object).

Posted on
Fri Jan 25, 2013 3:34 am
matt (support) offline
Site Admin
User avatar
Posts: 21427
Joined: Jan 27, 2003
Location: Texas

Re: Device selection order

The next beta of Indigo 6 is available which maintains the order defined in the XML.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests