Skip to main content
Participant
August 3, 2013
Question

Dynamically updating UI (binding, maybe?)

  • August 3, 2013
  • 1 reply
  • 1014 views

So I am writing an export plugin for lightroom. I need to update the export UI dynamically after getting a result from Lrhttp.post. The code is underlined below. Basically, how can I display to the user that their login is successful by dynamically updating the export UI after they click the submit button (I want the last row to display whether the login was a success or not)? I could not find a UI refresh function in the LR API.

I tried looking at Lr.Binding to try to bind resultlogin but that did not work as intended. Any suggestions? Thanks!

ExportDialogSections = {}

function ExportDialogSections.sectionsForTopOfDialog(f, propertyTable)

           return {

                    {

                              title = "...",

                              --

                              f:row {

                                        spacing = f:control_spacing(),

                                        f:static_text {

                                                  title =  "Username",

                                                  width = share 'labelWidth',

                                                  alignment = 'right',

                                        },

                                        f:edit_field {

                                                  value = bind 'Username',

                                                  width_in_chars = 40

                                        },

                              },

                              --

                              f:row {

                                        spacing = f:control_spacing(),

                                        f:static_text {

                                                  title = "Password",

                                                  width = share 'labelWidth',

                                                  alignment = 'right',

                                        },

                                        f:password_field {

                                                  value = bind 'Password',

                                                  width_in_chars = 40

                                        },

                              },

                              --

                              f:push_button{

                                        title="Submit",

                                        action = function( button )

                                                  import "LrTasks".startAsyncTask( function()

                                                            resultlogin = LrHttp.post(...)

                                                  end )

                                                  if resultlogin == "success" then

                                                            --send username to exporttask and display username is valid

                                                            sendUsername(...)

                                                  else

                                                            sendUsername(...)

                                                  end

                                        end,

                              },

                              f:row {

                                        spacing = f:control_spacing(),

                                        f:static_text {

                                                  title = resultlogin,

                                                  width = share 'labelWidth',

                                                  alignment = 'right',

                                        },

                              },

                    --

                    }

          }

end

return ExportDialogSections

This topic has been closed for replies.

1 reply

areohbee
Legend
August 3, 2013

You have to assign resultLogin as a member of a (observable) property table, then bind to that member by name, for example:

f:static_text {
    title = LrView.bind( 'resultlogin' ),
    width = share 'labelWidth',
    alignment = 'right',
},

In the case of export dialog box, the export settings themselves are a usable property table. In other cases, you may need to create one yourself - see LrFunctionContext, in which case the only trick is to make sure that the property table is specified as bind_to_object.

There are examples galore in my plugin's source code:

http://www.robcole.com/Rob/ProductsAndServices

Rob

allahmaneAuthor
Participant
August 3, 2013

Thanks for the quick, helpful reply!

Sorry if this is fairly obvious, but how exactly do I assign resultLogin as a member of a property table?

areohbee
Legend
August 3, 2013

There are zillions of examples in the plugins here, all of which include source code:

http://www.robcole.com/Rob/ProductsAndServices

That said, here is some code:

local props = LrBinding.makePropertyTable( functionContext )

local resultLogin = ... -- get login result.

props['resultLogin'] = resultLogin

Or you can use the export settings which are set up for your export.

Again, I recommend downloading an export plugin (e.g. TreeSyncPublisher) from the above link for exact code with all the trimmings...

Rob