-
1. Re: Dynamic table for popup_menu
Rob Cole Jun 25, 2012 9:48 AM (in response to EdMcCullough66)I've never used dynamically changing popup items variable before, and I'm not sure it will work(?)
But, if it's displaying a long string, it does not sound like 'items' is being assigned a proper table yet.
I don't know what you mean by a "chunk" of values. I assume you mean table.
In any case, if SYPNEventResults[1].title is a string, then SYPNEventResults[1].value can be any legal lua type.
Likewise for SYPNEventResults[2], SYPNEventResults[3], ...
If you can index/display the title with this syntax, e.g. LrDialogs.message( SYPNEventResults[1].title ), then the popup should be initialized thusly:
viewFactory:popup_menu {
items = SYPNEventResults,
value = LrView.bind('eventname2'),
width_in_chars = 40,
},
if a function is returning multiple values, then to get it into a table "array", do this:
local tableArray = { myTableArrayFunc( myTableArrayParameters ) }
Does this help?
Rob
-
2. Re: Dynamic table for popup_menu
Blatman888 Jun 25, 2012 11:51 AM (in response to EdMcCullough66)Ed,
I had a similar result when I was doing font selection with a popup in the webengine - from memory the line of tables was produced when part of a string rather than a table. The items parameter is a table of tables but I had made a string of tables.
Maybe try SYPNEventResults = {},
Cheers,
Blane
-
3. Re: Dynamic table for popup_menu
EdMcCullough66 Jun 25, 2012 12:09 PM (in response to Blatman888)I definitely feel like what is being returned is a string of tables rather than a table of tables.
LrDialogs.message( SYPNEventResults[1].title ) returns an error.
Any quick help on how to covert from a string of tables to a table of tables?
Thanks in advance. I'm trying to read up as much as I can but it's a bit like drinking from a fire hydrant at the moment.
-
4. Re: Dynamic table for popup_menu
Rob Cole Jun 25, 2012 12:35 PM (in response to EdMcCullough66)There is no such thing as a string of tables, only string of characters, but I recommend using
* type( variable ) to assertain variable type, and/or
* John Ellis' Debug.lognpp - to dump variables and subvariables ad-infinitum with table syntax trimming... - so you can see exacty what you've got.
http://forums.adobe.com/message/4141424
If the return variable is a string of characters, and no way around that (i.e. server is doing it, not plugin), you may need to parse the string into pieces and assign pieces to table members, to come up with popup 'items' table in proper form.
R
-
5. Re: Dynamic table for popup_menu
Matt Dawson Jun 25, 2012 5:42 PM (in response to EdMcCullough66)Hi Ed,
If you mean by "string of tables" that the LrHttp call results in the text representing a Lua table, then you could use the loadstring function to convert it back into an actual table. Please note that:
- if you don't have control over the URL returning the results and don't fully trust it, this can be a large security hole in your plugin to please give this due consideration
- to use this your URL should really return text like "s = {}", as in the table you are returning should be assigned to a variable, rather than just returning the table content itself
Alternatively if you are in control of the URL you could change the returned values to be in XML or JSON format and use some of the freely available Lua code for working with those formats, and converting them back to a table.
Also I'm assuming that these values only need to be dynamic at the point the UI is being initially created and displayed. If you have events that trigger the popup list's items needing to change after the dialog has been created then you would need to bind your items to an LrObservableTable entry that contained the values being displayed. This can be tricky to operabe because LrObservableTables aren't really designed to monitor the entries within tables they contain.
Matt



