problem with wxPanel derivation class

Larry Bates larry.bates at websafe.com
Thu Oct 11 15:00:54 EDT 2007


none wrote:
> wxGlade created a simple Frame with a panel a sizer and 3 wxControls ,
> saticText, TextCtrl, and a Button.
> 
> The resulting code works fine.
> 
> Now the problem.
> I wish to make a separate class derrived from wxPanel that has the sized
> and controls as above.  It jusst won't work
> 
> 
> <code id="gladeGen" class="works_ok">
> #!/usr/bin/env python
> # -*- coding: ISO-8859-1 -*-
> # generated by wxGlade 0.4cvs on Thu Oct 11 13:26:19 2007
> 
> import wx
> 
> class MyFrameOne(wx.Frame):
>     def __init__(self, *args, **kwds):
>         # begin wxGlade: MyFrameOne.__init__
>         kwds["style"] = wx.DEFAULT_FRAME_STYLE
>         wx.Frame.__init__(self, *args, **kwds)
>         self.panel = wx.Panel(self, -1)
>         self.staticbox = wx.StaticBox(self.panel, -1, "StaticBox")
>         self.label = wx.StaticText(self.panel, -1, "Field Name")
>         self.textBox = wx.TextCtrl(self.panel, -1, "Field Value")
>         self.button = wx.Button(self.panel, -1, "Edit")
> 
>         self.__set_properties()
>         self.__do_layout()
>         # end wxGlade
> 
>     def __set_properties(self):
>         # begin wxGlade: MyFrameOne.__set_properties
>         self.SetTitle("frame_1")
>         self.label.SetMinSize((-1, 15))
>         # end wxGlade
> 
>     def __do_layout(self):
>         # begin wxGlade: MyFrameOne.__do_layout
>         sizer_1 = wx.BoxSizer(wx.VERTICAL)
>         sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
>         sizer.Add(self.label, 0, wx.ALL, 3)
>         sizer.Add(self.textBox, 0, wx.ALL, 3)
>         sizer.Add(self.button, 0, wx.ALL, 3)
>         self.panel.SetAutoLayout(True)
>         self.panel.SetSizer(sizer)
>         sizer.Fit(self.panel)
>         sizer.SetSizeHints(self.panel)
>         sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
>         self.SetAutoLayout(True)
>         self.SetSizer(sizer_1)
>         sizer_1.Fit(self)
>         sizer_1.SetSizeHints(self)
>         self.Layout()
>         # end wxGlade
> 
> # end of class MyFrameOne
> 
> ## modified from BoaApp
> class App(wx.App):
> 	def OnInit(self):
> 		wx.InitAllImageHandlers()
> 		self.main = MyFrameOne(None)
> 		self.main.Show()
> 		self.SetTopWindow(self.main)
> 		return True
> 
> def main():
> 	application = App(0)
> 	application.MainLoop()
> 
> if __name__ == '__main__':
> 	main()
> 
> </code>
> 
> <code id="modifiedFromGlade" class="fails">
> #!/usr/bin/env python
> # -*- coding: ISO-8859-1 -*-
> #The commented out code from MyFrame was moved to class Panel \
> # and appropriately modified by changing self.panel to self etc
> 
> import wx
> 
> class MyFrameTwo(wx.Frame):
> 	def __init__(self, *args, **kwds):
> 		# begin wxGlade: MyFrameTwo.__init__
> 		kwds["style"] = wx.DEFAULT_FRAME_STYLE
> 		wx.Frame.__init__(self, *args, **kwds)
> ##		self.panel = panel(self, -1)
> 		self.panel = Panel(self, -1)
> 		self.__set_properties()
> 		self.__do_layout()
> 		# end wxGlade
> 
> 	def __set_properties(self):
> 		# begin wxGlade: MyFrameTwo.__set_properties
> 		self.SetTitle("frame_1")
> 		self.label.SetMinSize((-1, 15))
> 		# end wxGlade
> 
> 	def __do_layout(self):
> 		# begin wxGlade: MyFrameTwo.__do_layout
> 		sizer_1 = wx.BoxSizer(wx.VERTICAL)
> ##		sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
> ##		sizer.Add(self.label, 0, wx.ALL, 3)
> ##		sizer.Add(self.textBox, 0, wx.ALL, 3)
> ##		sizer.Add(self.button, 0, wx.ALL, 3)
> ####		self.panel.SetAutoLayout(True)
> ##		self.panel.SetSizer(sizer)
> ##		sizer.Fit(self.panel)
> ##		sizer.SetSizeHints(self.panel)
> 		sizer_1.Add(self.panel, 1, wx.EXPAND, 0)
> 		self.SetAutoLayout(True)
> 		self.SetSizer(sizer_1)
> 		sizer_1.Fit(self)
> 		sizer_1.SetSizeHints(self)
> 		self.Layout()
> 		# end wxGlade
> 
> # end of class MyFrameTwo
> 
> 
> class Panel (wx.Panel):
> 	def __init__(self, *args, **kwds):
> 		self.staticbox = wx.StaticBox(self, -1, "StaticBox")
> 		self.label = wx.StaticText(self, -1, "Field Name")
> 		self.textBox = wx.TextCtrl(self, -1, "Field Value")
> 		self.button = wx.Button(self, -1, "Edit")
> 		__doLayout()
> 
> 	def __doLayout():
> 		sizer = wx.StaticBoxSizer(self.staticbox, wx.HORIZONTAL)
> 		sizer.Add(self.label, 0, wx.ALL, 3)
> 		sizer.Add(self.textBox, 0, wx.ALL, 3)
> 		sizer.Add(self.button, 0, wx.ALL, 3)
> 		
> 		# maybe comment this and uncommennt  frame2's corresponding line
> 		panel.SetAutoLayout(True)
> 		
> 		self.SetSizer(sizer)
> 		sizer.Fit(self.panel)
> 		sizer.SetSizeHints(self.panel)
> 		
> 
> ## modified from BoaApp
> class App(wx.App):
> 	def OnInit(self):
> 		wx.InitAllImageHandlers()
> 		self.main = MyFrameTwo(None)
> 		self.main.Show()
> 		self.SetTopWindow(self.main)
> 		return True
> 
> def main():
> 	application = App(0)
> 	application.MainLoop()
> 
> if __name__ == '__main__':
> 	main()
> 
> </code>
> 
> <errorMessages>
>  /home/xaos/xpy/cnc/i2g/prefDialog/test/frame2.py
> Traceback (most recent call last):
>  File "/home/xaos/xpy/cnc/i2g/prefDialog/test/frame2.py", line 82, in ?
> main()
>  File "~/xpy/cnc/i2g/prefDialog/test/frame2.py", line 78, in main
> application = App(0)
>  File
> "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py", line
> 7473, in __init__
> self._BootstrapApp()
>  File
> "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py", line
> 7125, in _BootstrapApp
> return _core_.PyApp__BootstrapApp(*args, **kwargs)
>  File "~/xpy/cnc/i2g/prefDialog/test/frame2.py", line 72, in OnInit
> self.main = MyFrameTwo(None)
>  File "~/xpy/cnc/i2g/prefDialog/test/frame2.py", line 13, in __init__
> self.panel = Panel(self, -1)
>  File "~/xpy/cnc/i2g/prefDialog/test/frame2.py", line 48, in __init__
> self.staticbox = wx.StaticBox(self, -1, "StaticBox")
>  File
> "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_controls.py",
> line 990, in __init__
> newobj = _controls_.new_StaticBox(*args, **kwargs)
> TypeError: argument number 1: a 'wxWindow *' is expected, 'Panel' is
> received
> Script terminated.
> 
> </errorMessages>
> 
> 
> It seems as though the complaint is that  a 'wxWindow *' is expected,
> 'Panel' is received
> However, Panel IS a wx.Panel derivative which IS a wx.Window derivative!
> Additionally, the methods in the code of Panel and MyFrameOne seem to be
> identical.
> I can't understand this. Anyone have any thoughts?
> 
> I'm using spe as an IDE
> 
> ~S~
> 
> I taught myself everything I know about Python and wxPython in the lasst
> week and I still don't know everything.
> 
> 
You will probably get better results if you post this to 
gmane.com.python.wxpython list as it is specific to wxPython.

-Larry



More information about the Python-list mailing list