Page 1 of 1

Multiple windows in an app.

Posted: Wed Jun 11, 2014 7:53 pm
by hgcoon
OK, I have vertigo with all the different "multiple windows" questions -- all interesting but none of them quite speaking to my use. I run simulations (evolutionary and genetic) but when items are ready I need to plot them in the appropriate window. I think what I'm saying is simplified as: 1) Make 3-5 Windows (one or more for images) the others are graphs to which data are added (plotted) periodically -- I need to see their progress en passant. 2) According to what is going on In my main loop (program), I want to focus first on one window and plot some data, then go back to the data generator code and later focus on another window and plot data appropriate to it. Back and forth as needed. I am bewildered by the issue of switching back and forth among the windows, first setting focus on one, and then another.... I have practiced with two windows and two graphs, I can get one (the first one to work) and then later, the second is ignored. I guess the best way to say it is: open a window - plot some data; open a second window plot other data there; then go back to the first window and add some new stuff. etc., etc., shifting focus among the windows as needed. Meanwhile, I try to use a single event loop at the end to quit when I kill a window (or all of them).
Has an example program got such code or can someone help me get started juggling Gadgets, and Creating images and the like... Thanks to the brave souls who have followed thus far. hgc

Re: Multiple windows in an app.

Posted: Wed Jun 11, 2014 8:03 pm
by Zebuddi123
Hi try the multiple windows example code section

http://purearea.net/pb/CodeArchiv/English.html#21

zebuddi. :)

Re: Multiple windows in an app.

Posted: Wed Jun 11, 2014 9:58 pm
by infratec
Hi,

maybe this gives you an idea:

Code: Select all


EnableExplicit

Structure WindowStructure
  No.i
  Button.i
EndStructure




Procedure NewWindow(Map WindowMap.WindowStructure())
  
  Protected.i Win
  
  
  Win = OpenWindow(#PB_Any, 0, 0, 100, 50, "", #PB_Window_SystemMenu)
  If Win
    
    SetWindowTitle(Win, Str(Win))
    
    AddMapElement(WindowMap(), Str(Win))
    WindowMap()\No = Win
    
    WindowMap()\Button = ButtonGadget(#PB_Any, 10, 10, 40, 20, "Test")
    
  EndIf
  
EndProcedure



Define.i MainWindow, Button, Exit, Event, EventWin, TimerCounter, SelWin, i

NewMap WindowMap.WindowStructure()

MainWindow = OpenWindow(#PB_Any, 0, 0, 400, 300, "Main", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If MainWindow
  
  Button = ButtonGadget(#PB_Any, 10, 10, 40, 20, "New")
  
  AddWindowTimer(MainWindow, 1, 1000)
  
  Exit = #False
  Repeat
    
    Event = WaitWindowEvent()
    EventWin = EventWindow()
    
    Select EventWin
      Case MainWindow
        Select Event
          Case #PB_Event_Timer
            If EventTimer() = 1
              
              If MapSize(WindowMap())
                
                TimerCounter + 1
                
                SelWin = TimerCounter % MapSize(WindowMap()) + 1
                ResetMap(WindowMap())
                For i = 1 To SelWin
                  NextMapElement(WindowMap())
                Next i
                
                SetGadgetText(WindowMap()\Button, Str(TimerCounter))
                
              EndIf
              
            EndIf
          Case #PB_Event_Gadget
            Select EventGadget()
              Case Button
                NewWindow(WindowMap())
            EndSelect
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
        
      Default
        If FindMapElement(WindowMap(), Str(EventWin))
          
          Select Event
            Case #PB_Event_Gadget
              Select EventGadget()
                Case WindowMap()\Button
                  Debug WindowMap()\No
              EndSelect
            Case #PB_Event_CloseWindow
              CloseWindow(WindowMap()\No)
              DeleteMapElement(WindowMap())
          EndSelect
          
        EndIf
        
    EndSelect
    
    
  Until Exit
  
  ForEach WindowMap()
    CloseWindow(WindowMap()\No)
  Next
  
EndIf
Bernd

Re: Multiple windows in an app.

Posted: Mon Jun 16, 2014 7:31 pm
by davido
@infratec,

Very nice. Thank you for sharing. :D