Skip to main content
Known Participant
August 5, 2013
Question

Calling LrTasks.execute from within a plug in manager control

  • August 5, 2013
  • 1 reply
  • 1356 views

I'm working on a Lightroom post-processing-filter plug in which has most of the functionality inside an executable that resides inside the plug in folder.

The executable is responsible for doing the actual photo processing but is also responsible for obtaining and verifying that there is a valid license. This means that I need to let the user eneter an activation code, pass that to the executable which will talk to our server and get a license.

I would like to handle that activation part from the plug-in manager dialog so I've added a top section (see following code) with a text field and a button and I've added code to call the executable when the button is pressed, but the executalbe is never called.

Is what I'm trying to do impossible? Any workarounds?

Thanks in advance!

Eyal

function PluginManager.sectionsForTopOfDialog( f, p )

          p.my_result = 0

return {

          -- section for the top of the dialog

          {

                    bind_to_object = p,

                    title = "MyPlug",

                    f:row {

                              spacing = f:control_spacing(),

                              f:static_text {

                                        title = LrView.bind( "my_result")

                              },

                              f:push_button {

                                        width = 150,

                                        title = 'Run Exe',

                                        enabled = true,

                                        action = function()

                                                  command = '"' .. LrPathUtils.child(LrPathUtils.child( _PLUGIN.path, "mac" ), "MyTool" ) .. '" ' .. '-action check"'

                                                  quotedCommand = command  

                                                  p.my_result = LrTasks.execute( quotedCommand )

                                        end,

                                        },

                              },

          },

}

end

This topic has been closed for replies.

1 reply

areohbee
Legend
August 5, 2013

local buttonGuard

action = function( button )

     LrFunctionContext.postAsyncTaskWithContext( button.title, function( context )

          LrDialogs.attachErrorDialogToFunctionContext( context )

          if buttonGuard == nil then

               buttonGuard = LrRecursionGuard( button.title )

          elseif buttonGuard.active then

               LrDialogs.message( "cool yer jets..." )

               return

          end

          buttonGuard:performWithGuard( function()

               -- execute your commands and whatever...

          end )

     end )

end,

Note:

* action runs asynchronously, which you probably need to execute your command.

* action function will display an error message instead of silently croaking, if there is an error thrown.

* action won't run repeatedly if user keeps clicking on the button, and will give him/her a gentle scolding if so doing .

For more error handling possibilities, use a cleanup handler for the function context, instead of attaching the default error dialog.

Rob

BigRedlerAuthor
Known Participant
August 5, 2013

Thanks Rob,

I'm afraid it didn't work for me. The code inside postAsyncTaskWithContext is not executed, as far as I could see. I didn't see any diagnostic messages.

local LrView = import "LrView"

local LrHttp = import "LrHttp"

local bind = import "LrBinding"

local app = import 'LrApplication'

local LrPathUtils = import 'LrPathUtils'

local LrTasks = import "LrTasks"

local LrDialogs = import 'LrDialogs'

local LrRecursionGuard = import 'LrRecursionGuard'

PluginManager = {}

function PluginManager.sectionsForTopOfDialog( f, p )

          p.my_result = 0

          local buttonGuard

return {

          -- section for the top of the dialog

          {

                    bind_to_object = p,

                    title = "MyPlug",

                    f:row {

                              spacing = f:control_spacing(),

                              f:static_text {

                                        title = LrView.bind( "my_result")

                              },

                              f:push_button {

                                        width = 150,

                                        title = 'Do Something',

                                        enabled = true,

                                        action = function(button)

                                                  LrFunctionContext.postAsyncTaskWithContext(button.title,function(context)

                                                            p.my_result = 3

                                                  end)

                                        end,

                                        },

                              },

          },

}

end

areohbee
Legend
August 5, 2013

You didn't import LrFunctionContext - could that be it?

PS - the code snippet I posted had not been tested as typed in. I use something similar but the wrapping code comes with an object which is part of an object oriented framework (elare plugin framework).

PPS - Consider using John Ellis' debugging toolkit.

Rob