Page 1 of 1
Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 8:52 am
by Fangbeast
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?
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 8:59 am
by hazard
Why not simply hide the gadget until you are done populating it?
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 9:51 am
by Fangbeast
hazard wrote:Why not simply hide the gadget until you are done populating it?
I hide the whole form for aesthetics but obviously not long enough. Too long and it would not look right.
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.
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 10:30 am
by hazard
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...
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?
Posted: Mon Apr 16, 2012 11:41 am
by criobot
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
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 1:09 pm
by Fangbeast
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
I don't know much about threads having not used them in many years but it sounds like a good approach.
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?
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 1:47 pm
by hazard
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?
Posted: Mon Apr 16, 2012 1:51 pm
by Sparkie
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.
Re: Proper ListIconGadget locking to prevent greying out?
Posted: Mon Apr 16, 2012 2:50 pm
by Fangbeast
Thanks for bringing this topic up Fangles. It helped me to remember a few things about speeding up my ListIconGadget in my current project.
Any time master. Been a while since I 'saw' you and i'm between blood tests so had to think.
Currently, 1899 records. Data will go up shortly!!!
Where are you pulling the data from?
From an SQLite database
How many columns in the ListIcongadget?
15 columns
How long is it talking to load?
4.5 seconds. And as there will be many more in the future, this is already too long.
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.
That's pretty impressive.
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!