Work order for Bind-Commands

Everything else that doesn't fall into one of the other PB categories.
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Work order for Bind-Commands

Post by jacdelad »

Hi,
are calls of functions linked via Bind... processed serially or simultaneously like threads?

Code: Select all

Global NewList MyList.i()

Procedure Processor()
  SelectElement(MyList(),20)
  Delay(3000)
EndProcedure

For counter=1 To 100
  AddElement(MyList())
  MyList()=counter
Next
OpenWindow(0,0,0,300,200,"Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(1,0,0,300,200,"Push me!")
BindGadgetEvent(1,@Processor(),#PB_EventType_LeftClick)
SelectElement(MyList(),10)
Repeat
  Debug MyList()
  SelectElement(MyList(),10)
Until WaitWindowEvent(1000)=#PB_Event_CloseWindow
I hope this example explains it: Pushing the button causes to call the function which selects a different element and waits for 3 seconds (to be sure the WaitWindowEvent() is triggered at least three times). When I execute it the WaitWindowEvent() is not triggered when I pushed the button, element 21 is debugged once and then it goes on like normal. -> I conclude, that the program processes events triggered with BindGadgetEvent() and such serially. Is that correct and always the case (threads aside)?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Work order for Bind-Commands

Post by mk-soft »

Procedures connected to BindEvent or BindGadgetEvent are processed internally when WaitWindowEvent is called, so these procedures run in the main programme (GUI).
Therefore, no delay may be used, as otherwise the entire GUI will hang.

If an event comes from the OS (WaitWindowEvent waits for it), the connected procedures are first called before WaitWindowEvent passes the event to the main loop.

Code: Select all

;-TOP

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  #Button
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration


Procedure DoEventButton()
  Debug "Process Button Click Over BindGadgetEvent"
EndProcedure

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    ButtonGadget(#Button, 10, 10, 120, 25, "ClickMe!")
    
    BindGadgetEvent(#Button, @DoEventButton(), #PB_EventType_LeftClick)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #Button
              Debug "Process Button Click Over Main Event Loop"
          EndSelect
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Work order for Bind-Commands

Post by jacdelad »

Ah, yes, that's what I wanted to hear. I only used the delay to test whether other events are handled simultaneously or not. So, without WaitWindowEvent all Binds won't work?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Work order for Bind-Commands

Post by mk-soft »

That right,

without WaitWindowEvent, nothing bind's work!
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Work order for Bind-Commands

Post by STARGÅTE »

As an important info I have to say, that the call order of multiple bound events is from the last to the first.

Code: Select all

Enumeration
	#Window
	#Button
EndEnumeration

Procedure Event1()
  Debug "Event1 called"
EndProcedure

Procedure Event2()
  Debug "Event2 called"
EndProcedure

Procedure Event3()
  Debug "Event3 called"
EndProcedure

If OpenWindow(#Window, 0, 0, 140, 45, "Window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	ButtonGadget(#Button, 10, 10, 120, 25, "ClickMe!")
	
	BindGadgetEvent(#Button, @Event1(), #PB_EventType_LeftClick)
	BindGadgetEvent(#Button, @Event2(), #PB_EventType_LeftClick)
	BindGadgetEvent(#Button, @Event3(), #PB_EventType_LeftClick)
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow
				Break
		EndSelect
	ForEver
	
EndIf
Event3 called
Event2 called
Event1 called
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Work order for Bind-Commands

Post by mk-soft »

Hello STARGÅTE,

Even though your example is very nice, it bothers me a little that you put Window objects and Gadget objects in the same enumeration. Otherwise the new users will think that this is correct, even if this works.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Work order for Bind-Commands

Post by jacdelad »

@STARGÅTE: thanks for the annotation, that's good to know (and a bit odd imo...).
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply