Screen updating.

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 3:28 pm

Hi all,

I am creating a "quick" utility which uses the following handler :

Code: Select all

On InitaliseLists pListName
   ## Handler that controls reads the data stored in the file system
   
   
   if pListName is "ListOfImages" then
      put "Building List of Images" into field "status"
      wait 0.5 second
      lock screen
      ## first the image files
      put field "PathToImages" into tPath_ImageLibrary
      put getAllFiles (tPath_ImageLibrary) into tFileList
      put the number of lines in tFileList into tCount
      -- put tFileList into field "FileList"
      put ConvertToArray (tFileList) into tImagesA
      put SortArray(tImagesA,"FileName") into sImageFilesA
      put "" into tImagesA
      put "List of " & tCount & " images created!" into field "status"
      unlock screen
      wait 10 seconds with messages
      Beep
      put "" into field "status"
   else
      put "Building List of PrintJobs" into field "status"
      wait 0.5 second
      put GetListPrintJobs() into tPrintJobs
      put tPrintJobs into field "SavedPrintJobs"
      put "List of PrintJobs completed" into field "status"
      wait 10 seconds with messages
      put "" into field "status"
   end if
end InitaliseLists
The card has a field named "Status" and my plan was to update the user on what is happening by updating it with status messages. Looking at the first clause of the "if" statement
put "Building List of Images" into field "status"
this initial write to the field is visible to the user, moving down the code the line
put "List of " & tCount & " images created!" into field "status"
is not displayed to the user. However, it is visible if the final write to the field
put "" into field "status"
is commented out.

I thought the
wait
commands would allow time for the screen to update but it does not. I'm about to experiment with using the send command but wonder why my code fails?
best wishes
Skids

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 3:49 pm

Just wanted to confirm that the
send "message" in n seconds
works. I added a simple handler :

Code: Select all

On UpdateStatus pText
   Put pText into field "status"
end UpdateStatus
and modified the initialise handler to :

Code: Select all

On InitaliseLists pListName
   ## Handler that controls reads the data stored in the file system
   if pListName is "ListOfImages" then
      UpdateStatus "Building List of Images"
      wait 0.1 second
      lock screen
      ## first the image files
      put field "PathToImages" into tPath_ImageLibrary
      put getAllFiles (tPath_ImageLibrary) into tFileList
      put the number of lines in tFileList into tCount
      -- put tFileList into field "FileList"
      put ConvertToArray (tFileList) into tImagesA
      put SortArray(tImagesA,"FileName") into sImageFilesA
      put "" into tImagesA
    
      UpdateStatus ("List of " & tCount & " images created!")
      unlock screen
      send "UpdateStatus" to me in 10 seconds
   else
      put "Building List of PrintJobs" into field "status"
      wait 0.5 second
      put GetListPrintJobs() into tPrintJobs
      put tPrintJobs into field "SavedPrintJobs"
      put "List of PrintJobs completed" into field "status"
      send "UpdateStatus" to me in 10 seconds
   end if
   
end InitaliseLists
The dictionary implies that wait with messages is like the send command in that it is non-blocking. However, it does seem to block screen updating for some reason.
best wishes
Skids

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9397
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Screen updating.

Post by richmond62 » Sun Mar 31, 2024 4:44 pm

wait with messages forces a screen update.

https://livecode.fandom.com/wiki/TextChanged

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 4:56 pm

wait with messages forces a screen update.
Well if true then its not screen updating that is the root of the problem. Here is the code of my open stack handler:

Code: Select all

On OpenStack
   ReadAppPrefsData  -- calls local handler to read and set up the application
   put empty into field "debug"
   put empty into field "FileList"
   put empty into field "SavedPrintJobs"
   put empty into field "ImageCount" of card id 1002 of me
   
   InitaliseLists "ListOfImages" 
   wait with messages
   --send "updateStatus" to me in 5 seconds
   InitaliseLists "PrintJobs"
end OpenStack
Looking at the lower portion of the handler the handler "InitaliseLists" (yes I know I missed th "i" out) is called twice. It seems as if the second call starts before the first has completed as the first never displays the total number of items added to the list. Odd.
best wishes
Skids

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9397
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Screen updating.

Post by richmond62 » Sun Mar 31, 2024 5:01 pm

I wonder if, in that case, you should wait, but not with messages as I feel the second call of the function is one of the messages that might get in the way of the first call.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9397
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Screen updating.

Post by richmond62 » Sun Mar 31, 2024 5:09 pm

This, from the Dictionary:
If the wait..with messages form is used, LiveCode continues normal processing during the wait. The current handler is frozen, but the user can start other handlers and perform other actions
makes me wonder if your:

Code: Select all

InitaliseLists "ListOfImages" 
   wait with messages
   --send "updateStatus" to me in 5 seconds
   InitaliseLists "PrintJobs"
aren't in the same handler; because if they are that with messages won't make a blind bit of difference.

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 5:32 pm

because if they are that with messages won't make a blind bit of difference.
That about sums it up! I've given up and added a second field.

However, while experimenting I would guess that the Livecode engine is reading ahead and/or starting the second handler before the delays in the first have expired.

I may try splitting the initialise handler into two and see if that changes how the timing works.
best wishes
Skids

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 6:07 pm

Splitting the handler into two handlers that can be called without sending any parameters works. The first is called normally and the second is called using a
send message in n seconds command
. I suspect that the value of n is important if the first call is processing hundred of thousands of files.

While my code is now working I am mystified as to what happens under the engine's hood.
best wishes
Skids

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9397
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Screen updating.

Post by richmond62 » Sun Mar 31, 2024 6:46 pm

what happens under the engine's hood
Magic. 8)

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Screen updating.

Post by Simon Knight » Sun Mar 31, 2024 7:19 pm

Magic
:D
best wishes
Skids

Post Reply

Return to “Talking LiveCode”