I have a gui that that is calling a back end that just slogs away until it's done.
I have coded the back end so it is entirely separate from a gui, but I would like to now get some responses to the gui - namely some progress bar updating and when it has finished (so I can re-enable the controls).
However, I don't know what the best way of slotting in such a method.
The easiest method would be to hard code the gui updates in the
I'm thinking of using a Linked List which I can then add to for the messages of what's happened to the end, but I can keep polling the first item and then remove it once read - which is similar to how the existing gui events are generated.
Do you guys have any other ideas?
This was what I had in mind as a test, but the progress bar just doesn't work, but the reenabling of the button does:
Code: Select all
; CUSTOM EVENTS
Global NewList CustomOwnEvents.b()
Global NewList CustomOwnEventValues.l()
Global CustomOwnEvents_Mutex
Procedure RaiseEvent(EventType.b, EventValue.l)
LockMutex(CustomOwnEvents_Mutex)
LastElement(CustomOwnEvents())
AddElement(CustomOwnEvents())
CustomOwnEvents() = EventType
FirstElement(CustomOwnEvents())
LastElement(CustomOwnEventValues())
AddElement(CustomOwnEventValues())
CustomOwnEventValues() = EventValue
FirstElement(CustomOwnEventValues())
UnlockMutex(CustomOwnEvents_Mutex)
EndProcedure
Procedure.b GetEvents()
If CountList(CustomOwnEvents()) > 0
Protected e.b = CustomOwnEvents()
DeleteElement(CustomOwnEvents())
FirstElement(CustomOwnEvents())
EndIf
ProcedureReturn e
EndProcedure
Procedure.l GetEventValues()
If CountList(CustomOwnEventValues()) > 0
Protected e.l = CustomOwnEventValues()
DeleteElement(CustomOwnEventValues())
FirstElement(CustomOwnEventValues())
EndIf
ProcedureReturn e
EndProcedure
; BACKEND WORK
Procedure Test(stepper.l)
Protected count.l = 0
RaiseEvent(1, 100)
Repeat
count + stepper
RaiseEvent(2, count)
Delay(10)
Until count = 100
RaiseEvent(3, 1)
EndProcedure
; GUI WORK
Enumeration
#Window_0
EndEnumeration
Enumeration
#ProgressBar_0
#Button_1
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 216, 0, 600, 300, "New window ( 0 )", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Window_0))
ProgressBarGadget(#ProgressBar_0, 100, 150, 400, 20, 0, 10)
ButtonGadget(#Button_1, 230, 200, 140, 50, "")
EndIf
EndIf
EndProcedure
CustomOwnEvents_Mutex = CreateMutex()
Open_Window_0()
Define CustomEvents.b
Define CustomEventValues.l
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
LockMutex(CustomOwnEvents_Mutex)
CustomEvents = GetEvents()
CustomEventTypes = GetEventValues()
UnlockMutex(CustomOwnEvents_Mutex)
If Event = #PB_Event_Gadget
If GadgetID = #Button_1
DisableGadget(#Button_1, #True)
CreateThread(@Test(), 1)
EndIf
EndIf
Select CustomEvents
Case 1
SetGadgetAttribute(#ProgressBar_0, #PB_ProgressBar_Maximum, CustomEventValues)
Case 2
SetGadgetState(#ProgressBar_0, CustomEventValues)
Case 3
DisableGadget(#Button_1, #False)
EndSelect
Until Event = #PB_Event_CloseWindow



