5 Replies Latest reply on Jun 25, 2012 5:42 PM by DawMatt

    Dynamic table for popup_menu


      I'm trying to attach some dynamic information to a popup_menu (pulldown) object in the export dialog.


      I'm retrieving the data through an asynchronous task such as:

      SYPNEventResults = '';

      local LrDialogs = import "LrDialogs"

      local LrHttp = import "LrHttp"

      import "LrTasks".startAsyncTask( function()    

          SYPNEventResults, hdrs = LrHttp.get( "http://dev.seeyourphotos.net/cgi-bin/lightroom-event-list.cgi?photographer_id=20060207")

      end )


      This does succcessfully query the server and place a chunk of values in the SYPNEventResults variable like this:

      { title = "Lab Event", value = "Lab Event" },

      { title = "Karsten", value = "Karsten" },


      When I try to use this to populate the contents of the pulldown object (below), what is shown is all of the

      values as one long string rather than a list of events to choose from.  I'm presuming I'm missing a setp to

      bind this somehow differently.

      viewFactory:popup_menu {

              items = {



             value = LrView.bind('eventname2'),

             width_in_chars = 40,



      In summary, I'm trying to popuulate a custom dialog pulldown where the user selects from an event list retrieved from the server where that value can in turn be used in other parts of the dialog/ftp upload.


      I'm new to Lightroom, so please take that into account in your answer.


      Thanks in advance for any help.

        • 1. Re: Dynamic table for popup_menu
          areohbee Level 6

          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?


          • 2. Re: Dynamic table for popup_menu



            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 = {},  





            • 3. Re: Dynamic table for popup_menu
              EdMcCullough66 Level 1

              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
                areohbee Level 6

                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.




                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.



                • 5. Re: Dynamic table for popup_menu
                  DawMatt Level 3

                  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.