Action creation
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
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
Action creation
When the action configUI is run are there any callbacks into plugin.py? Specifically, a user may display information on an LCD text display having between 1 and 4 lines. I would like to dynamically change the ConfigUI to take input for all available lines rather than have the action take input for just one line (user defined 1 to 4) -- thus, requiring 4 actions for a 4 line display.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Action creation
You can change what's displayed in a running dialog via a response to a button press. You can pass back a modified values dict which can end up hiding/showing controls. Not sure if that's the answer you're looking for - if not, can you describe more what it is you're trying to do?
Re: Action creation
Thanks. What I really wanted was what the Button Press gives, but without the button press. I.e. before the window displays, there is a call to some function. But, the button press should do the trick.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Action creation
Oh, that's different. You can implement this method (the default implementation is shown for example purposes):
If the devId is non-zero (which it would be for a new device), then you can modify the valuesDict as necessary to manipulate the UI via visible and/or hidden bindings.
Alternately, you could implement this method (again, the default implementation is shown):
To modify the XML itself. I wouldn't recommend that approach, but you could do it if you really wanted to... 
Code: Select all
def getDeviceConfigUiValues(self, pluginProps, typeId, devId)
valuesDict = pluginProps
errorMsgDict = indigo.Dict()
return (valuesDict, errorMsgDict)Alternately, you could implement this method (again, the default implementation is shown):
Code: Select all
def getDeviceConfigUiXml(self, typeId, devId):
if typeId in self.devicesTypeDict:
return self.devicesTypeDict[typeId][u"ConfigUIRawXml"]
return NoneRe: Action creation
I am not sure we are on the same page.
I am talking about creating a plugin defined action (Trigger-> Action, or Action Group)
After selecting the Type: and Device: and clicking the Edit Action Settings... button I would like the contents of the configuration window to vary based on data stored in the device properties or in the plugin. Specifically, I would like to display a varying number of textfields.
I tried getDeviceConfigUiValues, but it doesn't seem to get called (and the Device context didn't seem right anyway).
I guess I could define as many textfields as I might ever need (4) and hide 1 to 3 of them based on some value returned to the Action dialog in a hidden field. If there was a way to return that field to the action Config.
I am talking about creating a plugin defined action (Trigger-> Action, or Action Group)
After selecting the Type: and Device: and clicking the Edit Action Settings... button I would like the contents of the configuration window to vary based on data stored in the device properties or in the plugin. Specifically, I would like to display a varying number of textfields.
I tried getDeviceConfigUiValues, but it doesn't seem to get called (and the Device context didn't seem right anyway).
I guess I could define as many textfields as I might ever need (4) and hide 1 to 3 of them based on some value returned to the Action dialog in a hidden field. If there was a way to return that field to the action Config.
Re: Action creation
It looks like getActionConfigUiXml will work. I can either return all the XML or just set a value in a hidden field to usa as a visibleBindingValue.
Re: Action creation
Yes!
getActionConfigUiXml worked perfectly. I structured the Action.xml so the appropriate display was controlled by a value in a hidden textfield. Then, all I needed to do was use re substitution to change the defaultValue received in self.actionsTypeDict[typeId][u"ConfigUIRawXml"] and return the edited xml.
Thanks for the pointers.
getActionConfigUiXml worked perfectly. I structured the Action.xml so the appropriate display was controlled by a value in a hidden textfield. Then, all I needed to do was use re substitution to change the defaultValue received in self.actionsTypeDict[typeId][u"ConfigUIRawXml"] and return the edited xml.
Thanks for the pointers.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Action creation
Are you sure getDeviceConfigUiValues isn't getting called every time? That would be the easier place to set that value.
And, for a new device, it doesn't really matter since you don't yet know what kind of device it is (so you'd just show the default amount), right?
You really should think about the DeviceFactory - it's made exactly for what you're trying to do I think.
And, for a new device, it doesn't really matter since you don't yet know what kind of device it is (so you'd just show the default amount), right?
You really should think about the DeviceFactory - it's made exactly for what you're trying to do I think.
Re: Action creation
This is an action group creation dialog, not a device config. So, the device always exists, otherwise it could not have appeared tin the device selection pulldown.
I did look at getActionConfigUiValues(self, pluginProps, typeId, devId):
which returns valuesDict and errorMsgDict. But, pluginProps is empty so there is nothing to edit. Essentially this function seems like a noop, at least in the context of creating a new action group.
I did look at getActionConfigUiValues(self, pluginProps, typeId, devId):
which returns valuesDict and errorMsgDict. But, pluginProps is empty so there is nothing to edit. Essentially this function seems like a noop, at least in the context of creating a new action group.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Action creation
Just add the value to pluginProps (well, the copy you make by doing valuesDict = pluginProps) that will hide/show whatever you want. Anything in the pluginProps that corresponds to a field will have that value passed to the <Field>. It's empty on a new action because it's the first time the dialog runs for that action.
I think...
I think the name "pluginProps" is a bit misleading from plugin_base.py - I'm pretty sure it's the props for the action.
I think...
I think the name "pluginProps" is a bit misleading from plugin_base.py - I'm pretty sure it's the props for the action.
Re: Action creation
Well, I think you were right
getActionConfigUiValues works.
With this field definition from actions.xml:
I set valuesDict to: valuesDict['displayLinesNum'] = '4'
and got what I wanted. This is certainly easier than doing the re substitution... though, I had already coded that, I'm switching to getActionConfigUiValues. Easier to code = easier to maintain.
Thanks.
getActionConfigUiValues works.
With this field definition from actions.xml:
Code: Select all
<Field id='displayLinesNum' type='textfield' hidden='true' defaultValue='1'>
<Label/>
</Field>and got what I wanted. This is certainly easier than doing the re substitution... though, I had already coded that, I'm switching to getActionConfigUiValues. Easier to code = easier to maintain.
Thanks.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Action creation
Totally agree - maintainability is an important design goal. Glad it worked.berkinet wrote:Easier to code = easier to maintain.