system : PB 6.02 under Windows 11 x64
When reading long lists of data (dictionary style, between 10 000 and 20 000 items) into a ListView gadget, the gadget's display remains blank until the lengthy operation completes. That leaves the user with the false impression that nothing is happening or that the app has frozen.
I tried using a progress bar to indicate that the operation is progressing, but even that does not work since control does not revert to the system until the filling operation has completed.
Anyone with a possible solution ? I remember a DoEvents() (or something similar) function in Visual Basic that made possible a screen refresh during lengthy operations. I can't figure an equivalent in PB.
The provided code attempts to demonstrate the problem. When the data quantity gets beyond 10000, the progress bar can clearly be seen not updating, and the ListView display boxes remain desperately blank for a long time...
Code: Select all
; ••• ••• ••• ••• ••• ••• •••
; • Guy - mai 2023 •
; • remplissage de ListViews •
; ••• ••• ••• ••• ••• ••• •••
EnableExplicit
; - constantes des gadgets
Enumeration
;{
#APP_titre
#CMD_encore : #CMD_combien
#LABEL_1 : #LV_1 : #TOTAL_1
#LABEL_2 : #LV_2 : #TOTAL_2
#LABEL_3 : #LV_3 : #TOTAL_3
#TiMER_bar : #TiMER_chrono
;}
EndEnumeration
; - polices
Define font$ = "Segoe UI"
Define font0 = LoadFont(0, font$, 14, #PB_Font_Bold)
Define font1 = LoadFont(1, font$, 12, #PB_Font_Bold)
Define font2 = LoadFont(2, font$, 11)
Define font3 = LoadFont(3, font$, 9)
; - fenêtre
OpenWindow(0, 0, 0, 400, 300, "LV tests w PROC", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; - gadgets
Define gi, gX,gY,gW,gH
#dX = 10 : #dY = 10
gi = #CMD_encore
#multiplic = 3
gH = 30 : gW = 60
gY = #dY : gX = WindowWidth(0) - gW - #dx
ButtonGadget(gi, gX,gY,gW,gH,"< Again")
SetGadgetFont(gi, font3)
gi = #CMD_combien
gX = #dx
ButtonGadget(gi, gX,gY,gW,gH,"" + #multiplic + " * >")
SetGadgetFont(gi, font3)
gi = #APP_titre
gX + gW
gW = GadgetX(#CMD_encore) - gX
TextGadget(gi, gX,gY,gW,gH,"infos", #PB_Text_Center| #PB_Text_Border)
SetGadgetFont(gi, font0)
SetGadgetColor(gi,#PB_Gadget_FrontColor,#Red)
SetGadgetColor(gi,#PB_Gadget_BackColor,#Yellow)
gi = #LABEL_1
gX = #dX : gY + gH + 4
gW = 120 : gH = 20
TextGadget(gi, gX,gY,gW,gH," items A")
gi + 3
gX + gW + #dX
TextGadget(gi, gX,gY,gW,gH," items B")
gi + 3
gX + gW + #dX
TextGadget(gi, gX,gY,gW,gH," items C")
gi = #TOTAL_1
gX = #dX : gY = WindowHeight(0) - #dY - #dY - #dY - gH
TextGadget(gi, gX,gY,gW,gH,"Please wait...")
gi + 3
gX + gW + #dX
TextGadget(gi, gX,gY,gW,gH,"Please wait...")
gi + 3
gX + gW + #dX
TextGadget(gi, gX,gY,gW,gH,"Please wait...")
gi = #LV_1
gY = GadgetY(#LABEL_1) + gH
gH = GadgetY(#TOTAL_1) - gY - 4
gX = #dX
ListViewGadget(gi, gX,gY,gW,gH)
gi + 3
gX + gW + #dX
ListViewGadget(gi, gX,gY,gW,gH)
SetGadgetColor(gi,#PB_Gadget_BackColor,$E1FFFF)
gi + 3
gX + gW + #dX
ListViewGadget(gi, gX,gY,gW,gH)
For gi = #LABEL_1 To #LABEL_3 Step 3
SetGadgetColor(gi,#PB_Gadget_FrontColor,#Blue)
SetGadgetColor(gi+2,#PB_Gadget_FrontColor,#Red)
SetGadgetFont(gi ,font1) ; identificateur
SetGadgetFont(gi+1,font3) ; ListView
SetGadgetFont(gi+2,font2) ; information
Next
ProgressBarGadget(#TiMER_bar, 0, WindowHeight(0)-16, WindowWidth(0), 16, 0, 100)
Declare Remplir_LV(nLines)
Define n = 150
Remplir_LV(n)
; - -------------------------------------
; - boucle Windows
Define event, item$, barre
Repeat
event = WaitWindowEvent()
gi = EventGadget()
Select event
Case #PB_Event_Timer : Gosub mettre_a_jour
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget :
Select gi
Case #LV_1, #LV_2, #LV_3 : Gosub montrer_choix
Case #CMD_combien : Gosub augmenter
Case #CMD_encore : Remplir_LV(n)
EndSelect
EndSelect
ForEver
End
; - -------------------------------------
#inc = 3
mettre_a_jour:
barre + #inc
SetGadgetState(#TiMER_bar, barre)
If barre >= 100 : barre = -#inc : EndIf
Return
montrer_choix:
item$ = GetGadgetText(gi)
SetGadgetText(gi+1,item$)
Debug GetGadgetText(EventGadget())
Return
augmenter:
n * #multiplic
If n > 125000
n = 150
EndIf
Remplir_LV(n)
Return
Procedure Remplir_LV(nLines)
; - affichage des données
Protected i, maxi, n, t1, t2
SetGadgetText(#APP_titre, Str(nLines) + " data entries")
RemoveWindowTimer(0, #TiMER_chrono)
AddWindowTimer(0, #TiMER_chrono, 200)
For i = #LV_1 To #LV_3 Step 3
ClearGadgetItems(i)
Next
t2 = ElapsedMilliseconds()
t1 = t2
n = nLines/3 ; pcq 3 LV
maxi = n
For i = 1 To maxi
AddGadgetItem(#LV_1,-1,"item # "+ i)
Next
t2 = ElapsedMilliseconds() - t2
SetGadgetText(#TOTAL_1, "" + t2 + " ms")
Debug "LV 1 " + t2 + " ms"
maxi + n
t2 = ElapsedMilliseconds()
For i = i To maxi
AddGadgetItem(#LV_2,-1,"item # "+ i)
Next
t2 = ElapsedMilliseconds() - t2
SetGadgetText(#TOTAL_2, "" + t2 + " ms")
Debug "LV 2 " + t2 + " ms"
maxi + n
t2 = ElapsedMilliseconds()
For i = i To maxi
AddGadgetItem(#LV_3,-1,"item # "+ i)
Next
t2 = ElapsedMilliseconds() - t2
SetGadgetText(#TOTAL_3, "" + t2 + " ms")
Debug "LV 3 " + t2 + " ms"
t1 = ElapsedMilliseconds() - t1
SetWindowTitle(0, "LV remplis en " + t1 + " ms")
Debug "durée totale " + t1 + " ms"
EndProcedure