I have one list populating with 2,000 items at program startup and the following two sets of ways are partially successful at stopping the 'greying out' or non-responsiveness of the list while loading but the list is still 'grey' for a short while and doesn't look nice.
This
LockWindowUpdate_(GadgetID(#DocList)) ; Lock the list
LockWindowUpdate_(0) ; Unlock the list
or
SendMessage_(GadgetID(#DocList), #WM_SETREDRAW, #False, 0)
SendMessage_(GadgetID(#DocList), #WM_SETREDRAW, #True, 0)
There was an example in the forum to subclass the gadget to stop all redraw messages but I don't know what it was called.
Does anyone know of a better, more effective way than the above?
Proper ListIconGadget locking to prevent greying out?
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Proper ListIconGadget locking to prevent greying out?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Proper ListIconGadget locking to prevent greying out?
Why not simply hide the gadget until you are done populating it?
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Proper ListIconGadget locking to prevent greying out?
I hide the whole form for aesthetics but obviously not long enough. Too long and it would not look right.hazard wrote:Why not simply hide the gadget until you are done populating it?
The subclassing option is better and someone may remember it.
or, might need to do something other than load so many records on start but I like the gadget visible and not greyed out so the subclassing option sounds good. At least there is a visible 'face' to the program while work is being done.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Proper ListIconGadget locking to prevent greying out?
I am not really sure how subclassing to prevent redrawing will cure the 'non-responsiveness' because, even if you disable all painting, your program is still going to have to wait whilst the list is populated.
You could populate the list within some timer or other or...
You could populate the list within some timer or other or...
Code: Select all
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Column", 250)
For i = 0 To 10000
AddGadgetItem(0, -1, "Item " + Str(i))
WindowEvent() : Delay(1)
Next
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Re: Proper ListIconGadget locking to prevent greying out?
A good aproach when adding so much items is to use multithreading. Adding items asynchroniously will update gadget's window and keep the gadget responsive.
Code: Select all
Procedure additems(param)
For i = 0 To 10000
AddGadgetItem(0, -1, "Item " + Str(i))
Next
EndProcedure
If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Column", 250)
CreateThread(@additems(), 0)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Proper ListIconGadget locking to prevent greying out?
I don't know much about threads having not used them in many years but it sounds like a good approach.criobot wrote:A good aproach when adding so much items is to use multithreading. Adding items asynchroniously will update gadget's window and keep the gadget responsive.Code: Select all
Procedure additems(param) For i = 0 To 10000 AddGadgetItem(0, -1, "Item " + Str(i)) Next EndProcedure If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection) AddGadgetColumn(0, 1, "Column", 250) CreateThread(@additems(), 0) Repeat Event = WaitWindowEvent() Until Event = #PB_Event_CloseWindow EndIf
1 question though...I remember that there is a single string buffer in pb so what happens if something else wants to use the gadget when the thread is operating (posting other strings to it from other parts of my program)? Am I opening a whole can of worms here?
When a thread is finished, does it just exit and clean up after itself?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Proper ListIconGadget locking to prevent greying out?
Set the threadsafe compiler switch and the compiler will automatically generate code in which each thread uses it's own string buffer.
Re: Proper ListIconGadget locking to prevent greying out?
Thanks for bringing this topic up Fangles. It helped me to remember a few things about speeding up my ListIconGadget in my current project.
Where are you pulling the data from? How many columns in the ListIcongadget? How long is it talking to load?
I'm pulling in 3900 lines of 3 columns each from a .csv file in under half a second. I use the #WM_SETREDRAW messages to help speed things up from 2.5 seconds.
Where are you pulling the data from? How many columns in the ListIcongadget? How long is it talking to load?
I'm pulling in 3900 lines of 3 columns each from a .csv file in under half a second. I use the #WM_SETREDRAW messages to help speed things up from 2.5 seconds.
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
- Fangbeast
- PureBasic Protozoa
- Posts: 4789
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Proper ListIconGadget locking to prevent greying out?
Any time master. Been a while since I 'saw' you and i'm between blood tests so had to think.Thanks for bringing this topic up Fangles. It helped me to remember a few things about speeding up my ListIconGadget in my current project.
Currently, 1899 records. Data will go up shortly!!!
From an SQLite databaseWhere are you pulling the data from?
15 columnsHow many columns in the ListIcongadget?
4.5 seconds. And as there will be many more in the future, this is already too long.How long is it talking to load?
That's pretty impressive.I'm pulling in 3900 lines of 3 columns each from a .csv file in under half a second. I use the #WM_SETREDRAW messages to help speed things up from 2.5 seconds.
I'm currently using the :
SendMessage_(GadgetID(#Gadget_DocMan_DocumentList), #WM_SETREDRAW, #False, 0)
before the mass display and
SendMessage_(GadgetID(#Gadget_DocMan_DocumentList), #WM_SETREDRAW, #True, 0)
Afterwards.
P.S. Nice to hear from you again!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet