Update a seperate Logging window

Just starting out? Need help? Post your questions and find answers here.
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 644
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Update a seperate Logging window

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2777
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Update a seperate Logging window

Post 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
Last edited by TI-994A on Fri Dec 12, 2025 12:01 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Axolotl
Addict
Addict
Posts: 901
Joined: Wed Dec 31, 2008 3:36 pm

Re: Update a seperate Logging window

Post 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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 644
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: Update a seperate Logging window

Post 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
User avatar
spikey
Enthusiast
Enthusiast
Posts: 792
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Update a seperate Logging window

Post 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?
User avatar
mk-soft
Always Here
Always Here
Posts: 6433
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Update a seperate Logging window

Post by mk-soft »

You need named enumerations and with modules a common module.
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
Post Reply