Re: Recipe management software?
Posted: Tue Mar 01, 2016 7:21 am
Very Nice App, Thank You for all your hard work. 

http://www.purebasic.com
https://www.purebasic.fr/english/
Thanks for that but it's still not quite working right in parts. Some of the control buttons stay in their 'pressed' state and there seems no reason for it.GoodNPlenty wrote:Very Nice App, Thank You for all your hard work.
Hope it's okay. Going to fix all the little things before I add anything else.jack wrote:hello GoodNPlenty
I think you jumped the gun too soon, wait a few more minutes because the file you got is 3 days old.
Hi Fangbeast
that's big update
That's going to be a problem as the routine that shows a category of recipes on start (and the main culprit due to how many recipes it must retrieve) and user choice updates a stringgadget from the record. No idea at the moment how to separate that out.Keep all GUI stuff out of the thread fangles.
Don't really understand it.The thread can always use PostEvent() to send custom messages to the main program (there is a good example in PB's user manual).
And, finally, make sure you set the threadsafe compiler switch.
Code: Select all
;PostEvent() would give the best solution. However...
;we use a couple of simple global variables instead.
Global gMessageFromThread ;Informs the main program what to do.
Global gDataFromThread ;Used to hold some dummy data from the thread.
;The following constants are for convenience only.
;The global variable gMessageFromThread would assume one of the following values.
Enumeration
#threadMSG_DONOTHING
#threadMSG_UPDATESTRINGGADGET
EndEnumeration
Procedure myThread(Value)
Repeat
;DATA PROCESSING. GET DATA FROM SQLite etc.
;We simply increment the gDataFromThread variable and inform the main program that we have new data.
gDataFromThread + 1
;Signal the main event loop through the gMEssageFromThread variable.
gMessageFromThread = #threadMSG_UPDATESTRINGGADGET
Delay(1000)
ForEver
EndProcedure
OpenWindow(0, 200, 200, 200, 100, "PostEvent")
TextGadget(0, 10, 10, 100, 20, "Thread running...")
StringGadget(1, 10, 40, 180, 20, "")
thread = CreateThread(@myThread(), 0)
Repeat
Event = WaitWindowEvent(100) ;Notice the time limit. You can remove this if using PostEvent().
;Check thread message.
If gMessageFromThread = #threadMSG_UPDATESTRINGGADGET
SetGadgetText(1, Str(gDataFromThread))
gMessageFromThread = #threadMSG_DONOTHING
EndIf
Until Event = #PB_Event_CloseWindow
Code: Select all
EnableExplicit
Enumeration #PB_Event_FirstCustomValue
#UpdateProgress
#UpdateFinished
EndEnumeration
Procedure workerthread(WndId)
Protected progress = 0
Repeat
Delay (20) ;simulate some work
progress + 1
PostEvent(#UpdateProgress,WndId,#PB_Ignore,#PB_Ignore,progress) ;send update msg
Until progress => 100
PostEvent(#UpdateFinished,WndId,#PB_Ignore,#PB_Ignore,0) ;send finish msg
EndProcedure
OpenWindow(0, 0, 0, 640, 80, "Worker-Thread GUI Demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ProgressBarGadget(1, 12, 30, 620, 20, 0, 100)
ButtonGadget(2, 1, 1, 50, 20, "Start")
Define Event
Repeat
Event = WaitWindowEvent()
Select Event
Case #UpdateProgress ;worker thread has signaled the main thread to update the progress
SetGadgetState(1, EventData())
Case #UpdateFinished
MessageRequester("Done","Finished!")
Case #PB_Event_Gadget
If EventGadget() = 2 ;Start button
CreateThread(@workerthread(), WindowID(0))
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
Perhaps display a timer-based splash screen (about 2 to 3 seconds) to allow the main form to load?Fangbeast wrote:...can't make it any faster unless anyone has some ideas?
What a silly comment!!! I haven't been able to progress this far without your help. I keep telling people I'm not much of a coder but more of an assembler of bits and bobs. You and others have provided me the means to make lots of interesting stuff (At least to me!!) that I can give back.If this is any use to you fangles then let me know when you have digested it and I will post an identical snippet using PostEvent() instead of globals.