Page 1 of 1

Update a seperate Logging window

Posted: Fri Dec 12, 2025 11:16 am
by captain_skank
I have a main window ( WNDW_main ) and i have a logging window with just and editorgadget ( WNDW_log ).

I have a lot of processing steps in WNDW_main so would like to update the editor gadget on WNDW_log accordingly.

The editor gadget on the log window is defined as a GLOBAL variable using #PB_any.

But try as i might when i want to update the editorgadget from WNDW_main i get 'gadget not initialised' and when i check the gadget id is returned as zero even though its defined as a global.

Also should WNDW_log have /not have an eventloop because I dont want it to have the focus at any time as its just a visual aid.

Any help is appreciated.

Captain S.

Re: Update a seperate Logging window

Posted: Fri Dec 12, 2025 11:49 am
by TI-994A
The main event loop should be able to handle both windows.

If you don't require any window-specific control, this would suffice:

Code: Select all

Win1 = OpenWindow(#PB_Any, 300, 300, 300, 150, "Main Window", #PB_Window_SystemMenu)
Win1Text = TextGadget(#PB_Any, 20, 50, 260, 30, "Elapsed: 0 sec")
AddWindowTimer(Win1, 0, 1000)

Win2 = OpenWindow(#PB_Any, 620, 300, 300, 150, "Log Window", #PB_Window_SystemMenu)
Win2Editor = EditorGadget(#PB_Any, 20, 20, 260, 100, #PB_Editor_ReadOnly)

Repeat
  event = WaitWindowEvent()  
  Select event      
    Case #PB_Event_CloseWindow
      appQuit = #True      
    Case #PB_Event_Timer
      elapsed + 1
      If Not Mod(elapsed, 5)
        SetGadgetText(Win2Editor, "Another five second elapsed at: " + FormatDate("%hh:%ii:%ss", Date()))
      EndIf      
      SetGadgetText(Win1Text, "Elapsed: " + Str(elapsed) + " secs")
  EndSelect  
Until appQuit

However, if you would prefer to separate each window's events, do it like this:

Code: Select all

Win1 = OpenWindow(#PB_Any, 300, 300, 300, 150, "Main Window", #PB_Window_SystemMenu)
Win1Text = TextGadget(#PB_Any, 20, 50, 260, 30, "Elapsed: 0 sec")
AddWindowTimer(Win1, 0, 1000)

Win2 = OpenWindow(#PB_Any, 620, 300, 300, 150, "Log Window", #PB_Window_SystemMenu)
Win2Editor = EditorGadget(#PB_Any, 20, 20, 260, 100, #PB_Editor_ReadOnly)

Repeat
  event = WaitWindowEvent()  
  Select EventWindow()      
    Case Win1
      Select event          
        Case #PB_Event_CloseWindow
          appQuit = #True          
        Case #PB_Event_Timer
          elapsed + 1          
          If Not Mod(elapsed, 5)
            SetGadgetText(Win2Editor, "Another five second elapsed at: " + FormatDate("%hh:%ii:%ss", Date()))
          EndIf                
          SetGadgetText(Win1Text, "Elapsed: " + Str(elapsed) + " secs")          
      EndSelect      
    Case Win2
      Select event      
        Case #PB_Event_CloseWindow
          MessageRequester("Win2", "Close app from Main Window.")
      EndSelect      
  EndSelect    
Until appQuit
The #PB_Editor_ReadOnly flag would prevent the editor gadget from pulling focus.

Hope it helps. :D

Re: Update a seperate Logging window

Posted: Fri Dec 12, 2025 11:58 am
by Axolotl
In addition to the above post.
The error message indicates a “race condition.”
You may be calling the output before creating the window gadgets.
So: Before using the gadgets, simply check for their existence with IsGadget().

BTW: If the main loop is to be kept free of special events, there is also BindEvent() and its companions.

Re: Update a seperate Logging window

Posted: Fri Dec 12, 2025 12:51 pm
by captain_skank
Thanks for the replies, found an alternate way of acheiving the required result.

The interesting pasrt for me was that i was creating and displaying the WNDW_log and showing the gadgetid in the editor gadget, but when i tried show it ( using debug ) in WNDW_main it was always returning an id of 0.

Anyhooo thanks for the pointers.

Cheers

Re: Update a seperate Logging window

Posted: Sat Dec 13, 2025 12:51 pm
by spikey
captain_skank wrote: Fri Dec 12, 2025 12:51 pm The interesting pasrt for me was that i was creating and displaying the WNDW_log and showing the gadgetid in the editor gadget, but when i tried show it ( using debug ) in WNDW_main it was always returning an id of 0.
Are you using modules, and are WNDW_main and WNDW_log in different modules?

Re: Update a seperate Logging window

Posted: Sat Dec 13, 2025 12:55 pm
by mk-soft
You need named enumerations and with modules a common module.