PostEvent no send

Just starting out? Need help? Post your questions and find answers here.
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

PostEvent no send

Post by mestnyi »

now on the contrary, it works fine in Windows, but in Mac and Linux the message is not sent.

Code: Select all

Procedure Quit( )
   ;\\ stop main loop
   CompilerSelect #PB_Compiler_OS 
      CompilerCase #PB_OS_Linux
         gtk_main_quit_( )
         
      CompilerCase #PB_OS_Windows
         PostQuitMessage_( 0 )
         
      CompilerCase #PB_OS_MacOS
         CocoaMessage( 0, CocoaMessage( 0, 0, "NSApplication sharedApplication" ), "stop:", 0 )
         
   CompilerEndSelect
EndProcedure

Procedure Message( Title.s, Text.s, flag.q, *parent )
   Protected result
   
   Protected *message = OpenWindow(#PB_Any, 0, 0, 400, 120, Title, #PB_Window_SystemMenu|#PB_Window_WindowCentered, *parent)
   
   BindEvent( #PB_Event_CloseWindow, @Quit(), *message )
   
    ; macos bug no post event
   PostEvent( #PB_Event_Gadget, 0,0, #PB_EventType_FirstCustomValue )
   
   ;\\ start main loop
   CompilerSelect #PB_Compiler_OS 
      CompilerCase #PB_OS_Linux
         gtk_main_( )
         
      CompilerCase #PB_OS_Windows
         Protected msg.MSG
         
         While GetMessage_( @msg, #Null, 0, 0 )
            TranslateMessage_( msg ) 
            DispatchMessage_( msg ) 
         Wend
         
      CompilerCase #PB_OS_MacOS
         CocoaMessage( 0, CocoaMessage( 0, 0, "NSApplication sharedApplication" ), "run" )
         
   CompilerEndSelect
   
   
   ;\\ close
   CloseWindow( *message )
   
   ProcedureReturn result
EndProcedure


;-
Procedure CanvasEvents( )
   
   If EventType() = #PB_EventType_FirstCustomValue
      Debug "#PB_EventType_FirstCustomValue "
   EndIf
   
EndProcedure

If OpenWindow( 0, 150, 150, 600, 300, "demo message", #PB_Window_SizeGadget | #PB_Window_SystemMenu )
   CanvasGadget(0,10,10,490, 250 )
   BindGadgetEvent( 0, @canvasevents() )
   
   
   Message("Title", "Please make your input:", 0, WindowID(0))
   
   Define Event
   Repeat
      Event = WaitWindowEvent( )
   Until Event = #PB_Event_CloseWindow
   
EndIf
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: PostEvent no send

Post by mestnyi »

Code: Select all

 ; macos bug no post event
   PostEvent( #PB_Event_Gadget, 0,0, #PB_EventType_FirstCustomValue )
   
Do you think this is how it should be? that is, it should not send a message in my example?
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PostEvent no send

Post by mk-soft »

Two run levels cannot run simultaneously under Linux or macOS.

There can only ever be one event loop in the program so that no events are lost.
However, you can lock a parent window as long as the client window is open

Modify your code ...

Update 2

Code: Select all


Structure ArrayOfGadgets
  Index.i[0]
EndStructure


Procedure DoMessageEvents()
  Protected window, *gadget.ArrayOfGadgets
  Protected dx, dy
  
  window = EventWindow()
  *gadget.ArrayOfGadgets = GetWindowData(window)
  
  Select Event()
    Case #PB_Event_CloseWindow
      DisableWindow(0, #False)
      CloseWindow(window)
      ; Free gadget array
      FreeMemory(*gadget)
      
    Case #PB_Event_SizeWindow
      dx = WindowWidth(window)
      dy = WindowHeight(window)
      ResizeGadget(*gadget\Index[0], 10, dy - 40, #PB_Ignore, #PB_Ignore)
      ResizeGadget(*gadget\Index[1], dx - 130, dy - 40, #PB_Ignore, #PB_Ignore)
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case *gadget\Index[0]
          Debug "Button Ok"
        Case *gadget\Index[1]
          Debug "Button Close"
          PostEvent(#PB_Event_CloseWindow, window, 0)
          
      EndSelect
      
  EndSelect
  
EndProcedure

Procedure OpenMessageWindow( Title.s, Text.s, flag.q, parent_window = -1)
  Protected message, parent, *gadget.ArrayOfGadgets
  Protected dx, dy
  
  If parent_window >= 0
    parent = WindowID(parent_window)
    DisableWindow(parent_window, #True)
  EndIf
  
  #MessageStyle = #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_SizeGadget
  message = OpenWindow(#PB_Any, 0, 0, 400, 120, Title, #MessageStyle, parent)
  
  
  dx = WindowWidth(message)
  dy = WindowHeight(message)
  
  ; Allocate gadget array
  *gadget = AllocateMemory(2 * SizeOf(integer))
  
  *gadget\Index[0] = ButtonGadget(#PB_Any, 10, dy - 40, 120, 25, "Ok")
  *gadget\Index[1] = ButtonGadget(#PB_Any, dx - 130, dy - 40, 120, 25, "Close")
  
  ; Save info of gadgets
  SetWindowData(message, *gadget)
  
  BindEvent(#PB_Event_CloseWindow, @DoMessageEvents(), message )
  BindEvent(#PB_Event_SizeWindow, @DoMessageEvents(), message )
  BindEvent(#PB_Event_Gadget, @DoMessageEvents(), message )
  
  ; Post event to CanvasGadget
  PostEvent( #PB_Event_Gadget, 0,0, #PB_EventType_FirstCustomValue )
  
EndProcedure


;-
Procedure DoCanvasEvents( )
  
  If EventType() = #PB_EventType_FirstCustomValue
    Debug "#PB_EventType_FirstCustomValue "
  EndIf
  
EndProcedure

Procedure DoMainEvents()
  Protected window = EventWindow()
  Protected dx, dy
  
  Select Event()
    Case #PB_Event_SizeWindow
      dx = WindowWidth(window)
      dy = WindowHeight(window)
      ResizeGadget(0, 10, 10, dx -20, dy - 20)
      
  EndSelect
  
EndProcedure

Procedure Main()
  Protected dx, dy
  
  If OpenWindow( 0, 150, 150, 600, 300, "demo message", #PB_Window_SizeGadget | #PB_Window_SystemMenu )
    dx = WindowWidth(0)
    dy = WindowHeight(0)
    
    CanvasGadget(0, 10, 10,dx - 20, dy - 20 )
    
    ; Bind events
    BindEvent(#PB_Event_SizeWindow, @DoMainEvents(), 0)
    
    ; Bind gadget events
    BindGadgetEvent( 0, @DoCanvasEvents() )
    
    ; Open message window
    OpenMessageWindow("Title", "Please make your input:", 0, 0)
    
    Repeat
      Select WaitWindowEvent( )
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
      EndSelect
    ForEver
    
  EndIf
EndProcedure : Main()

End
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
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: PostEvent no send

Post by mestnyi »

How come you don’t understand me?
mk-soft wrote: Wed Dec 06, 2023 8:18 pm Two run levels cannot run simultaneously under Linux or macOS.
How does MessageRequester do this?

Don't try to give me options, or better yet, help me with examples of binding gadget window events using API
User avatar
mk-soft
Always Here
Always Here
Posts: 5216
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PostEvent no send

Post by mk-soft »

You asked why the PostEvent is not working.
Because you interrupt the event management of purebasic with gtk_main_( ) or "NSApplication sharedApplication.run".

There is nothing about MessageRequester here.
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
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: PostEvent no send

Post by mestnyi »

how does it interrupt MessageRequester?
Post Reply