Proper ListIconGadget locking to prevent greying out?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
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?

Post 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?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
hazard
New User
New User
Posts: 7
Joined: Sat Apr 14, 2012 5:40 pm

Re: Proper ListIconGadget locking to prevent greying out?

Post by hazard »

Why not simply hide the gadget until you are done populating it?
User avatar
Fangbeast
PureBasic Protozoa
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?

Post 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.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
hazard
New User
New User
Posts: 7
Joined: Sat Apr 14, 2012 5:40 pm

Re: Proper ListIconGadget locking to prevent greying out?

Post 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
criobot
User
User
Posts: 10
Joined: Sat Dec 27, 2008 9:42 pm
Location: Bulgaria
Contact:

Re: Proper ListIconGadget locking to prevent greying out?

Post 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
User avatar
Fangbeast
PureBasic Protozoa
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?

Post 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?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
hazard
New User
New User
Posts: 7
Joined: Sat Apr 14, 2012 5:40 pm

Re: Proper ListIconGadget locking to prevent greying out?

Post by hazard »

Set the threadsafe compiler switch and the compiler will automatically generate code in which each thread uses it's own string buffer.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Proper ListIconGadget locking to prevent greying out?

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
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?

Post 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!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply