I gradually discovered PureBasic by writing a program to drive an eprom programmer via rs232 and am satisfied with what I am learning little by little.
I understand event loops and I even manage to manage several windows but not yet with a task running in the background!
The skeleton of my code works but I stumble on this point.
An operation on the eprom can be quite long so a progress bar would be nice and also I wish I could possibly interrupt it.
So I imagine that launching the task in the main window opens a small control window with this progress bar and a start button and another stop button.
This window should be common to several different operations on the eprom so the code (basically a long loop) that performs this operation is in a subroutine (a different subroutine per operation).
How can I monitor the start and stop buttons of the control window in the loop and also that the progress bar being updated?
I tried different thing but without success so far ...
While browsing the doc I have the feeling that the piloting window should be a different thread from that of the main program ???
Here is a sample what I try to do :
Code: Select all
;
;
Global PilotWin
Global MainWin
Global ProgressBar_0, ButStart, ButStop
Global ButCalc
Procedure OpenPilotWin(x = 0, y = 0, width = 600, height = 400)
PilotWin = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
ProgressBar_0 = ProgressBarGadget(#PB_Any, 180, 130, 270, 60, 0, 100)
ButStart = ButtonGadget(#PB_Any, 170, 250, 100, 40, "Start")
ButStop = ButtonGadget(#PB_Any, 360, 250, 90, 40, "Stop")
EndProcedure
;
;
Procedure OpenMainWin(x = 0, y = 0, width = 600, height = 400)
MainWin = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
ButCalc = ButtonGadget(#PB_Any, 180, 210, 220, 40, "Calcul")
EndProcedure
;
;
Procedure.s Calculate()
;
Define.i i, FlgButStart, FlgButStop
;
OpenPilotWin()
;
FlgBuSTop = #False
FlgButStart = #False
;
While FlgButStop = #False And FlgButStart = #False
; Here we wait ButStart or ButStop
; si ButStop --> FlgButStop = #True
; si ButStart --> FlgButStart = #True
Wend
;
If FlgButStop : CloseWindow(PilotWin) : ProcedureReturn "Aborted" : EndIf
;
; so it's ButCalc
;
For i=1 To 10000000
;
;
SetGadgetState(ProgressBar_0, 100 * i / 10000000)
;
; Here look at ButStop
; If ButStop --> FlgButStop = #True
; and update ProgressBar_0
;
If FlgButStop : CloseWindow(PilotWin) : ProcedureReturn "Aborted" : EndIf
;
;
Next i
;
;
CloseWindow(PilotWin)
ProcedureReturn "Finished"
;
;
EndProcedure
;
OpenMainWin()
;
;
Repeat
;
Event = WaitWindowEvent()
;
Select Event
;
Case #PB_Event_Menu
;
Select EventMenu()
;
EndSelect
;
Case #PB_Event_Gadget
;
Select EventGadget()
;
Case ButCalc : Debug Calculate()
;
EndSelect
;
EndSelect
;
Until Event = #PB_Event_CloseWindow
;
Maybe you have this in your drawers?
Thank you. Best regards.
Philippe