Loading a LONG list with images
Tom Glod
tom at makeshyft.com
Mon Feb 21 18:47:22 EST 2022
This is how i did it ..... I hope this helps.
First to use the "numberofrecords" way of setting the datagrid data.
This is key, that way you only ever trigger loading of visible rows.
This is the code from my dg column.
global PixabayResults
if PixabayResults["cache"]["DL:" & PixabayResults["data"][the dgindex
of me]["previewURL"]] is empty then
send "GetImageTrigger " & the dgindex of me & comma & quote &
PixabayResults["data"][the dgindex of me]["previewURL"] & quote & comma &
random(25500) to card "Search Pixabay"
put image id 1410033 of card "Resources" into image 1 of me --
14110033 image id is the placeholder.
set the visible of image 1 of me to true
set the MyIndex of me to empty
//set the visible of group "Image Tools" of me to false
else
put PixabayResults["cache"]["DL:" & PixabayResults["data"][the
dgindex of me]["previewURL"]] into image 1 of me
set the visible of image 1 of me to true
set the MyIndex of me to the dgIndex of me
delete global PixabayResults["downloaded"][the dgIndex of me] --
delete the flag to update this row because its a visible row with newly
downloaded file
//set the visible of group "Image Tools" of me to false
end if
on GetImageTrigger ThisIndex,ThisURL,ThisRandom
send "GetAndCachePreviewImage " & ThisIndex & comma & quote & ThisURL &
quote & comma & random(25500) to card "Search Pixabay" in 0 milliseconds
end GetImageTrigger
on GetAndCachePreviewImage ThisIndex,ThisURL,ThisRandomNumber
Task_Scheduler_Add "Download File To Variable","DL:" &
ThisURL,ThisURL,"" -- this schedules TSNET request to download image then
waits for the image to download
wait until AppStarterStackTaskScheduler["finished"]["DL:" & ThisURL] is
not empty with messages -- wait with messages until its finished
if AppStarterStackTaskScheduler["finished"]["DL:" & ThisURL] is "error"
then
throw "Thumbnail Download Failed:" & ThisURL
else
put AppStarterStackTaskScheduler["data"]["DL:" & ThisURL]["data"]
into PixabayResults["cache"]["DL:" & ThisURL]
put 1 into PixabayResults["downloaded"][ThisIndex]
delete variable AppStarterStackTaskScheduler["data"]["DL:" &
ThisURL]["data"]
end if
end GetAndCachePreviewImage
On Mon, Feb 21, 2022 at 6:20 PM Tom Glod <tom at makeshyft.com> wrote:
> Dan can you check this video and the pixabay search example?
> https://youtu.be/jN2bQbhQ0L8?t=216
> Is this what you have in mind?
> These images are loaded as the row comes into view.
>
> On Mon, Feb 21, 2022 at 6:07 PM Dan Friedman via use-livecode <
> use-livecode at lists.runrev.com> wrote:
>
>> Richard,
>>
>> Probably not over a couple thousand. The images are square -- they need
>> to be resized to the DG template image size, but not scaled (H vs W).
>>
>> -Dan
>>
>>
>> On 2/21/22, 12:14 PM, "use-livecode on behalf of Richard Gaskin via
>> use-livecode" <use-livecode-bounces at lists.runrev.com on behalf of
>> use-livecode at lists.runrev.com> wrote:
>>
>> How many images?
>>
>> I once made a solution for 3,000 images, but it may not scale well
>> above
>> 8,000 or so depending on memory and connection speed.
>>
>> --
>> Richard Gaskin
>> Fourth World Systems
>>
>>
>>
>>
>> Dan Friedman wrote:
>>
>> > Does anyone have any answers to the issue of loading a long list
>> with
>> > images so that it loads images "as needed" like a webpage does.
>> >
>> > I have a DataGrid with several hundred rows. Each row has a
>> specific
>> > image that is to be displayed with that row (like a list of songs).
>> > The image is loaded from the web. Is there a method to load the
>> > DataGrid and only load the images for the rows that are shown?
>> And,
>> > when you scroll the grid, the images for the newly shown rows are
>> then
>> > loaded. The loading need to happen somehow without halting the
>> > scrolling or making it stutter.
>> >
>> > I hope that makes sense!
>> > -Dan
>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
More information about the use-livecode
mailing list