Page 1 of 1

String Gadget is not beeing updated

Posted: Fri Jun 25, 2010 10:16 am
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?

Re: String Gadget is not beeing updated

Posted: Fri Jun 25, 2010 10:42 am
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

Re: String Gadget is not beeing updated

Posted: Fri Jun 25, 2010 11:58 am
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

Re: String Gadget is not beeing updated

Posted: Fri Jun 25, 2010 1:09 pm
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...