Child Windows in Top Windows Question

Greetings all,

I'm mostly a newbie to wxPython and I'm writing an application to help me learn some of its ins and outs.

I'm trying to write an application with one top-level window, and multiple child windows that will exist only inside the top-level window frame, much the same way that the Windows PythonWin program manages its text editing sessions. There's only one button on the Start bar regardless of how many editing sessions the program actually has open.

I've been working with this for a couple of days now, and I don't feel like I'm making any headway. I'm assuming that what I want to do is possible, but I don't know for sure. Any help would be appreciated.

I've put together this small bit of sample code to demonstrate what I'm trying to do.

···

=================
SAMPLE CODE START

'''Document Object Model Test (I think that's what it's called)'''

import wx

class topWindow(wx.Frame):
     def __init__( self ):
         wx.Frame.__init__(self, None, -1, "My Top Window", pos=(100,100), size=(300,300))

         panel = wx.Panel(self)
         self.CreateStatusBar()

         menu = wx.Menu()
         child = menu.Append(-1, "Open child window", "Open a child window")
         menu.AppendSeparator()
         exit = menu.Append(-1, "Exit", "Done testing")
         self.Bind(wx.EVT_MENU, self.OnChild, child)
         self.Bind(wx.EVT_MENU, self.OnExit, exit)

         menuBar = wx.MenuBar()
         menuBar.Append(menu, "Start Here")
         self.SetMenuBar(menuBar)

     def OnChild(self, event):
         # I'm specifying the current window as the parent,
         # so how do I keep the child inside the parent window?
         f = childWindow(self, -1)
         f.Show()

     def OnExit(self, event):
         self.Close()

class childWindow(wx.Frame):
     def __init__( self, parent, id ):
         wx.Frame.__init__(self, parent, id, "My Child Window", pos=(25,25), size=(250,100))
         panel = wx.Panel(self)
         wx.StaticText(panel, wx.NewId(), "I want this window inside the top window.", (10,10))
         wx.StaticText(panel, wx.NewId(), "And I don't want it moving outside the top", (10,25))
         wx.StaticText(panel, wx.NewId(), "window. Is this possible?", (10,40))

if __name__ == '__main__':
     app = wx.PySimpleApp()
     f = topWindow()
     app.SetTopWindow(f)
     f.Show()
     app.MainLoop()

===============
SAMPLE CODE END

Thanks in advance,

Paul

Hello,

I am not completely clear on what you are trying to do, but I think you are thinking of MDI.

See the MDI sample in the wxPython demo for an example.

Cody

···

On Sep 26, 2008, at 8:01 PM, Paul wrote:

Greetings all,

I'm mostly a newbie to wxPython and I'm writing an application to help me learn some of its ins and outs.

I'm trying to write an application with one top-level window, and multiple child windows that will exist only inside the top-level window frame, much the same way that the Windows PythonWin program manages its text editing sessions. There's only one button on the Start bar regardless of how many editing sessions the program actually has open.

I've been working with this for a couple of days now, and I don't feel like I'm making any headway. I'm assuming that what I want to do is possible, but I don't know for sure. Any help would be appreciated.

I've put together this small bit of sample code to demonstrate what I'm trying to do.

=================
SAMPLE CODE START

'''Document Object Model Test (I think that's what it's called)'''

import wx

class topWindow(wx.Frame):
   def __init__( self ):
       wx.Frame.__init__(self, None, -1, "My Top Window", pos=(100,100), size=(300,300))

       panel = wx.Panel(self)
       self.CreateStatusBar()

       menu = wx.Menu()
       child = menu.Append(-1, "Open child window", "Open a child window")
       menu.AppendSeparator()
       exit = menu.Append(-1, "Exit", "Done testing")
       self.Bind(wx.EVT_MENU, self.OnChild, child)
       self.Bind(wx.EVT_MENU, self.OnExit, exit)

       menuBar = wx.MenuBar()
       menuBar.Append(menu, "Start Here")
       self.SetMenuBar(menuBar)

   def OnChild(self, event):
       # I'm specifying the current window as the parent,
       # so how do I keep the child inside the parent window?
       f = childWindow(self, -1)
       f.Show()

   def OnExit(self, event):
       self.Close()

class childWindow(wx.Frame):
   def __init__( self, parent, id ):
       wx.Frame.__init__(self, parent, id, "My Child Window", pos=(25,25), size=(250,100))
       panel = wx.Panel(self)
       wx.StaticText(panel, wx.NewId(), "I want this window inside the top window.", (10,10))
       wx.StaticText(panel, wx.NewId(), "And I don't want it moving outside the top", (10,25))
       wx.StaticText(panel, wx.NewId(), "window. Is this possible?", (10,40))

if __name__ == '__main__':
   app = wx.PySimpleApp()
   f = topWindow()
   app.SetTopWindow(f)
   f.Show()
   app.MainLoop()

===============
SAMPLE CODE END

Thanks in advance,

Paul

_______________________________________________
wxpython-dev mailing list
wxpython-dev@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-dev

Thanks much for your help. I just needed the right term to use. That's what I was looking for.

Cody Precord wrote:

···

Hello,

I am not completely clear on what you are trying to do, but I think you are thinking of MDI.

See the MDI sample in the wxPython demo for an example.

Cody

On Sep 26, 2008, at 8:01 PM, Paul wrote:

Greetings all,

I'm mostly a newbie to wxPython and I'm writing an application to help me learn some of its ins and outs.

I'm trying to write an application with one top-level window, and multiple child windows that will exist only inside the top-level window frame, much the same way that the Windows PythonWin program manages its text editing sessions. There's only one button on the Start bar regardless of how many editing sessions the program actually has open.

I've been working with this for a couple of days now, and I don't feel like I'm making any headway. I'm assuming that what I want to do is possible, but I don't know for sure. Any help would be appreciated.

I've put together this small bit of sample code to demonstrate what I'm trying to do.

=================
SAMPLE CODE START

'''Document Object Model Test (I think that's what it's called)'''

import wx

class topWindow(wx.Frame):
   def __init__( self ):
       wx.Frame.__init__(self, None, -1, "My Top Window", pos=(100,100), size=(300,300))

       panel = wx.Panel(self)
       self.CreateStatusBar()

       menu = wx.Menu()
       child = menu.Append(-1, "Open child window", "Open a child window")
       menu.AppendSeparator()
       exit = menu.Append(-1, "Exit", "Done testing")
       self.Bind(wx.EVT_MENU, self.OnChild, child)
       self.Bind(wx.EVT_MENU, self.OnExit, exit)

       menuBar = wx.MenuBar()
       menuBar.Append(menu, "Start Here")
       self.SetMenuBar(menuBar)

   def OnChild(self, event):
       # I'm specifying the current window as the parent,
       # so how do I keep the child inside the parent window?
       f = childWindow(self, -1)
       f.Show()

   def OnExit(self, event):
       self.Close()

class childWindow(wx.Frame):
   def __init__( self, parent, id ):
       wx.Frame.__init__(self, parent, id, "My Child Window", pos=(25,25), size=(250,100))
       panel = wx.Panel(self)
       wx.StaticText(panel, wx.NewId(), "I want this window inside the top window.", (10,10))
       wx.StaticText(panel, wx.NewId(), "And I don't want it moving outside the top", (10,25))
       wx.StaticText(panel, wx.NewId(), "window. Is this possible?", (10,40))

if __name__ == '__main__':
   app = wx.PySimpleApp()
   f = topWindow()
   app.SetTopWindow(f)
   f.Show()
   app.MainLoop()

===============
SAMPLE CODE END

Thanks in advance,

Paul

_______________________________________________
wxpython-dev mailing list
wxpython-dev@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-dev

_______________________________________________
wxpython-dev mailing list
wxpython-dev@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-dev

Paul wrote:

Thanks much for your help. I just needed the right term to use. That's what I was looking for.

Yes, but please don't use it!

1) it only works on Windows

2) it's and Awful UI! Even MS has abandoned it!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov