[wxPython] own maximize for wxMDIChildFrame - bugs?

w.p. ptaku2_wywalto at tlen.pl
Thu May 5 03:56:12 EDT 2005


I use code below:
1) frame receive too many maximize events on create and on close child window - why?
2) how to catch key events for wxMDIParentFrame ?
3) childWin.SetSize() in OnMaximize send additional maximize event (?)
4) wxMDIChildFrame is initially visible!
5) sorry for english :)
6) wxPython 2.5.4.1 (Windows)

################################################################
import  wx

#----------------------------------------------------------------------

class MyParentFrame(wx.MDIParentFrame):
     def __init__(self):
         wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_NO_WINDOW_MENU)
         self.winCount = 0

         self.CreateStatusBar()
         self.MainTb=self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT)
         biblioBut=wx.Button(self.MainTb,1231,label="&Biblio")
         newWndBut=wx.Button(self.MainTb,1213,label="&NewWnd")
         wx.EVT_BUTTON(self,newWndBut.GetId(), self.OnNewWindow)
         self.MainTb.AddControl(biblioBut)
         self.MainTb.AddSeparator()
         self.MainTb.AddControl(newWndBut)
         self.MainTb.Realize()
         self.SetToolBar(self.MainTb)
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDownParent)


     def OnKeyDownParent(self, event):
         print "OnKeyDownParent"

     def OnKeyDownChild(self, event):
         print "OnKeyDownChild"

     def OnClose(self, evt):
         self.GetActiveChild().Close(True)

     def OnMaximize(self, event):
         childWin = event.GetEventObject()
         win = childWin.GetParent()
         print "maximize "+self.GetTitle()
         childWin.SetSize(wx.Size(win.GetClientSize().GetWidth(),win.GetClientSize().GetHeight()-1))
         childWin.SetPosition(wx.Point(0,-1*win.GetClientAreaOrigin().y+1))
         event.Skip()

     def OnNewWindow(self,event):
         self.winCount = self.winCount + 1
         win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
         win.Maximize()
         #win.Show() # !!!!!!!!!!!!!!!!!!

         MainTb=win.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT)
         SBut=wx.Button(MainTb,1213,label="&Func")
         MainTb.AddControl(SBut)
         MainTb.Realize()
         win.SetToolBar(MainTb)

         win.Bind(wx.EVT_MAXIMIZE, self.OnMaximize)
         win.Bind(wx.EVT_KEY_DOWN, self.OnKeyDownChild)
         win.Show(True)

#----------------------------------------------------------------------

if __name__ == '__main__':
     class MyApp(wx.App):
         def OnInit(self):
             wx.InitAllImageHandlers()
             frame = MyParentFrame()
             frame.Show(True)
             self.SetTopWindow(frame)
             return True

     app = MyApp(False)
     app.MainLoop()




More information about the Python-list mailing list