Skip to main content
Known Participant
August 29, 2009
Question

LrProgressScope from a menu item

  • August 29, 2009
  • 1 reply
  • 3209 views

Hi,

I've been trying to use the LrProgressScope feature in a function that is called from a menu item, but it's being elusive. It looks as though it's trying to do it's job but nothing is updated.

The outline of the code is this:

LrTasks.startAsyncTask( function()

    LrFunctionContext.callWithContext( "showCustomDialog", function( context )

            Prog = LrProgressScope( {title = 'Checking for local updates', functionContext = context, } )
            Prog:setCancelable(true)

            local cat = LrApplication.activeCatalog()
            cat:withWriteAccessDo('Do Something', function()

                for i,p in ipairs(cat.allPhotos) do

                    if Prog:isCanceled() then
                        break
                    end

                    -- Do stuff, and then

                    Prog:setPortionComplete(ProcCount, PhotoCount)
                    Prog:setCaption(LrPathUtils.leafName(p.path))

                    LrTasks.yield()

                end

            end )
            Prog:done()

        end
    end )
end )

I've tried with every possible combination of:

- Create the LrProgressScope inside or outside of the callWithContext function

- Call the entire thing inline or as an LrTask

- Use LrTasks.yield() or not

... and in every case, the progress bar only appears when the entire function returns, showing 100% complete. Interestingly, if I replace the LrTasks.yield() with LrTasks.sleep(0.1), I get an error "attempt to yield across metamethod/c-call boundary".

Am I missing the point somewhere? I'd assumed that I may need to have the function running as an LrTask to allow the main thread to update the display, but even this (not illustrated above) doesn't work. Obviously it does from an Export module, but this is being called from a menu.

Help!

Cheers,

Jim

This topic has been closed for replies.

1 reply

escouten
Adobe Employee
Adobe Employee
August 31, 2009

Jim, the documentation for LrCatalog:withWriteAccessDo says: "Do not call LrTasks.yield() or any similar call that will cause your task to wait during this call." It's a bug that we're not reporting an error on the LrTasks.yield() call in this case.

If you need to do a task that will take a longer time, then you should call LrCatalog:withProlongedWriteAccessDo instead.

jimkeirAuthor
Known Participant
August 31, 2009

Hi,

Got that. The yield() was only in there as an attempt to get the main thread to update the ProgressScope.

I've tried "withProlongedWriteAccess" and I'm afraid I have the same problem; the progress scope doesn't appear. I know it's being used, because a) none of the update calls fail, and b) if I put in a LrDialogs.message() at the end of the callback function for withProlonged..., the progress scope appears in front of the dialog.

Incidentally, if I do this then neither dialog will accept input to their "Cancel" or "Ok" buttons. You have to click the 'Close' icon in the top right of the newly-appeared progress bar.

The progress dialog isn't essential, but it would be nice. Still looks like it has a problem when it's called from a menu.

(Windows 7 x64)

Cheers,

Jim

escouten
Adobe Employee
Adobe Employee
September 1, 2009

withProlongedWriteAccessDo provides you with its own progress scope. Did that not work for you?