Skip to main content
Known Participant
April 10, 2012
Question

collections becomes visible after 5 - 10 seconds. Message until it appears.

  • April 10, 2012
  • 3 replies
  • 2467 views

Hi,

I have a plug-in that creates serveral collections and adds photos to a 1000 - 2000 photos to these.

Also in the loop the message is shown of the progress. After the loop has finished the processing is also finished.

This all works fine.

The code is something like:

After the loop has finished and the created collectiona are populated  the collections becomes visible after 5 to 10 seconds. There is a delay. On slower systems this can be longer.

The problem is that the user sees and thinks that nothing happens and tries again.

What I want is to show a message which automatically disappears when the collections gets visible. No pushing buttons, only the message that he should we for the collection to become visible.

Other solutions are also welcome.

A little example would help alot.

        xxxxCollection = catalog:createCollection(  ...  )

                           for i, photo in ipairs(cat_photos) do

           


message = 'processed: ' .. i
           


progressScope:setCaption(message)
           



                                                           .. processing

                        
-- adding photo to collection.
           


xxxxCollection:addPhotos{ photo }
           



           

     progressScope:setPortionComplete( i, nCountSelected )
       

end
       

progressScope:done()
   
end)


end)


end



This topic has been closed for replies.

3 replies

dhmc05Author
Known Participant
April 27, 2012

I understand the reason, but how can i show the user that although nothing happens on screen Lightroom is processing the Collections.

I have tried with one parent progressScope which should emcompass all the functions and a child progressScope which should show the iteration over the individual photos.

This is my code, but only the first time the parent progress bar is shown. I'm doing something wrong.

My code is below. I have been trying for hours, but cannot get it right.

Could anyone correct it so that I get 2 bars, the other goes from 1 - 4 and the inner from 1 - photo count.

So that after the collections async have been created the other bar should finish.

local LrTasks = import 'LrTasks'

local catalog = import "LrApplication".activeCatalog()

local LrFunctionContext = import 'LrFunctionContext'

local LrProgressScope = import 'LrProgressScope'

local LrDialogs = import 'LrDialogs'

local myLogger = import 'LrLogger'( 'AddImages' )

--    myLogger:enable( "logfile" )

local message

local messageTitle

local messageOk

local messageCancel

function AddImagesToCollection()

    -- This should be the MAIN progressScope (progressScopeLarge) : this should encompass all

    --    Phase 1: Removing the Collection hierarchy

    --    Phase 2: Initializing

    --    Phase 3: Iterating all the photos

        -- Child progressScope - should show the progress of the individual photos. (progressScope)

    --    Phase 4: Building the Collection tree.

    --            After that all the images have been edited

    --            The problem is that the user is seeing nothing for some time. Thats why I want to show the progress of the main scope.

   

    local progressScopeLarge = LrProgressScope {

        title = 'My plug-in processing ...',

        functionContext = context,

    }

   

    LrTasks.startAsyncTask(function()

        message = "Remove previous CollectionSet"

        progressScopeLarge:setCaption(message)

        progressScopeLarge:setPortionComplete( 1, 4 )

       

        catalog:withWriteAccessDo( "Remove previous CollectionSet", function()

            local collectionSet = catalog:createCollectionSet( "My plug-in Collection", nil, true )

            collectionSet:delete()

        end)

        message = "Initializing ..."

        progressScopeLarge:setCaption(message)

        progressScopeLarge:setPortionComplete( 2, 4 )

       

        local cat_photos = catalog.targetPhotos

        local nCountSelected = #cat_photos

       

        progressScope = LrProgressScope {

            title = 'My plug-in: adding images ...',

            functionContext = context,

        }

       

        catalog:withWriteAccessDo( "Create new CollectionSet", function()

            message = "Iterating all photos"

            progressScopeLarge:setCaption(message)

            progressScopeLarge:setPortionComplete( 3, 4 )

           

            -- loop through each of the photos

            for i, photo in ipairs(cat_photos) do

                message = 'processed: ' .. i

                progressScope:setCaption(message)

               

                << All the processing per image >>

               

                progressScope:setPortionComplete( i, nCountSelected )

            end

            progressScope:done()

        end)

       

    end)

    message = "Building Collection tree"

    progressScopeLarge:setCaption(message)

    progressScopeLarge:setPortionComplete( 4, 4 )

    progressScopeLarge:done()

end

AddImagesToCollection()

johnrellis
Legend
April 27, 2012

Re the progressScopes, it's not obvious what might be going wrong. 

But it's not clear from your code fragment whether you've addressed the underlying issue, which is you'd prefer the collections and photos to appear in the user interface immediately when they're added.  Your code fragment appears to imply that the collection set and collections are all being created within one single catalog:withWriteAccessDo().

I suggest that you restructure your code to create each collection set/collection and add each photo to a collection within separate calls to catalog:withWriteAccessDo:

catalog:withWriteAccessDo

delete collection set

create collection set

for each photo

...

catalog:withWriteAccessDo

create collection

...

catalog:withWriteAccessDo

add photo to collection

Then it's more likely that the changes made to collections and their contents will appear incrementally on the screen as the plugin executes.


dhmc05Author
Known Participant
May 3, 2012

Hi,

I understand that it is normal behaviour that after the loop the collections are created / made visible and that this takes some time. This is no problem for me.

It is not neccesary to have the collections been build and visible during the loop. Also I think this would use a lot of performance.

For me it is enough to show "child progressbar" increase in the loop.

The only thing I want is to give the user a sign of life between the moment the last photo is added to the last collection (the end of the loop) and the moment the collections appear visible on screen for the user.

areohbee
Legend
April 10, 2012

Just to help reinforce one of the points John is making - collections aren't created until after you exit the with-write-access-do function. Likewise, nothing else is really done database-wise until the database transaction is complete - after returning from with...do.

It's worth noting that last edit date will not be the time the change was initiated, but the time it was finally committed.

johnrellis
Legend
April 10, 2012

In general, the LR user interface updates asynchronously from changes made to the catalog, and changes made by plugins can take a while to get reflected in the user interface.  But one thought about your situation:

Is the progressScope:done() inside or outside of the call to catalog:withWriteAccessDo()?  That is, is your structure:

catalog:withWriteAccessDo()

catalog:createCollection()

loop

collection:addPhoto()

progressScope:setPortionComplete()

progressScope:done()

If the call to progressScope:done() is inside the call to catalog:withWriteAccessDo(), then perhaps it is indicating that the operation is finished before all the changes to the catalog actually get committed.  What happens if you move progressScope:done() outside of the call to catalog:withWriteAccessDo()?