7 Replies Latest reply on Feb 21, 2010 8:19 PM by JW Stephenson

    LrProgressScope from a menu item

    jimkeir

      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

        • 1. Re: LrProgressScope from a menu item
          escouten Adobe Employee

          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.

          • 2. Re: LrProgressScope from a menu item
            jimkeir Level 1

            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

            • 3. Re: LrProgressScope from a menu item
              escouten Adobe Employee

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

              • 4. Re: LrProgressScope from a menu item
                jimkeir Level 1

                Hi,

                 

                No, I'm afraid not. As I said, it has the exact same problem. The progress dialog doesn't appear at all unless I put in an LrDialog.message at the end of the long update, and even then it only appears at that point - i.e. completed - and also locks the screen.

                 

                Cheers,

                Jim

                • 5. Re: LrProgressScope from a menu item
                  escouten Adobe Employee

                  Did you use yield in the prolonged access? Otherwise the UI wouldn't get a chance to update.

                  • 6. Re: LrProgressScope from a menu item
                    jimkeir Level 1

                    Hi,


                    Thanks for the suggestion. Unfortunately, I'd already tried both with and without LrTasks.yield()  - same result, no GUI. Here's the relevant code:

                     

                    local DoSyncUpdate = function(context, Prog)

                        local cat = LrApplication.activeCatalog()

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

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

                     

                            -- Do stuff here

                     

                            LrTasks.yield()
                             p:setPropertyForPlugin( _PLUGIN, 'NeedsSync', NeedsSync)

                        end
                        LrDialogs.message('Sync status updated.','Check the "Alamy - Sync Needed" Smart Collection.','info')
                    end

                     

                    LrApplication.activeCatalog():withProlongedWriteAccessDo( {
                        title = 'Update Sync Status',
                        caption = 'Checking Sync Status',
                        pluginName = 'Alamy Uploader',
                        func = DoSyncUpdate,
                        } )

                     

                    There's no GUI activity beyond a busy cursor until the LrDialogs.message, at which point both the message *and* the progress dialog appear.

                     

                    I repeat, because I think it's significant, that this is being called from a menu item and not from an export module.

                     

                    Cheers,

                    Jim

                    • 7. Re: LrProgressScope from a menu item
                      JW Stephenson Level 4

                      Jim,

                       

                      I have noticed as well that the progressScope inside a menu item sets up but the progressScope:setPortionComplete() function does absolutely nothing.  All works as expected in an export module sdk.  Any luck with a workaround?

                       

                      Jeff