String Gadget is not beeing updated

Just starting out? Need help? Post your questions and find answers here.
pga3
New User
New User
Posts: 2
Joined: Fri Jun 25, 2010 9:51 am

String Gadget is not beeing updated

Post by pga3 »

hi,

I didn't do anything with PB for quite a long time, and I'm still using 4.00. Today, I tried to write a little GUI for an command line application, but somehow my string gadget (used for status messages) is not being updated while RunProgram runs.

As soon as RunProgram is finished, all the messages show up at once. This is pretty annoying since I need those status texts during the process. Code is like this:

Code: Select all


global TIMER1.l, TIMER2.l

procedure MyThread(NULL)
  runprogram("MyApp.exe", "MyParams", GetCurrentDirectory(), #PB_Program_Wait|#PB_Program_Hide)
endprocedure

TIMER1 = GetTickCount_()

xxx = createthread(@MyThread(), #NULL)

While IsThread(xxx) <> 0
  TIMER2 = GetTickCount_()
  If TIMER2 - TIMER1 >= 1000
    SetGadgetText(#MyStringGadget, GetGadgetText(#MyStringGadget) + "#")
    TIMER1 = GetTickCount_()
  EndIf
Wend
Any ideas how I can solve my problem?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: String Gadget is not beeing updated

Post by srod »

You are not processing window events and so the string gadget is not being repainted. Only when you process window events via some kind of event loop will things like string gadgets be repainted etc.

The following shows one way through this (I'm not sure which version of PB is required for the timer functions. You may have to use an api timer instead.)

Code: Select all

lobal TIMER1.l, TIMER2.l

Procedure MyThread(NULL)
;  RunProgram("MyApp.exe", "MyParams", GetCurrentDirectory(), #PB_Program_Wait|#PB_Program_Hide)
Delay(4000)
EndProcedure

OpenWindow(0, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
  StringGadget(0, 10, 10, 120, 30, "")



TIMER1 = GetTickCount_()

xxx = CreateThread(@MyThread(), #Null)

AddWindowTimer(0, 100, 500)

Repeat
  eventID = WaitWindowEvent()
  Select eventID
    Case #PB_Event_Timer
      If EventTimer()= 100
        If IsThread(xxx) <> 0
          SetGadgetText(0, GetGadgetText(0) + "#")
        ElseIf IsGadget(0)
          FreeGadget(0)
        EndIf
      EndIf
  EndSelect
Until eventID = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.
pga3
New User
New User
Posts: 2
Joined: Fri Jun 25, 2010 9:51 am

Re: String Gadget is not beeing updated

Post by pga3 »

Hi, thx for the reply. After checking the SetTimer_() function I found a much simpler solution:

WindowEvent()

When putting that after the SetGadgetText() command, everything works as it should.
Btw. The PB internal timer functions are unfortunately not included in 4.00. I guess it's time to update ^^

BR,
pga3
Jihugen
User
User
Posts: 45
Joined: Mon Jun 07, 2010 11:36 pm
Location: Normandy, France

Re: String Gadget is not beeing updated

Post by Jihugen »

I have not read the topic in detail, so maybe my answer will not make a lot of sense here, but using this line:

While WindowEvent() : Wend

should be better as a rule than a simple call to WindowEvent() (as stated in the PB help file).
That way, you're sure that after this line, all queued events have been processed and each Gadget repainted...
Post Reply