Re: problem with wxPanel derivation class ~ thanks
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
Re: problem with wxPanel derivation class
On Oct 11, 4:01 pm, Chris Mellon [EMAIL PROTECTED] wrote: On 10/11/07, @bag.python.org none wrote: wxGlade created a simple Frame with a panel a sizer and 3 wxControls , saticText, TextCtrl, and a Button. snip 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? It's because you didn't call the base class __init__. wxPython is a SWIG wrapper around the C++ wxWidgets library, and if you don't call the base class the SWIG infrastructure that maps your class to an underlying C++ class doesn't happen and you get this error. Ah-so. I knew there was a more technical answer than what I gave. Hopefully I didn't muddy the issue with my doofy code. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with wxPanel derivation class ~ thanks
On 10/12/07, @bag.python.org none wrote: none wrote: wxGlade created a simple Frame with a panel a sizer and 3 wxControls , snip Thanks All, I didn't make the super() call (java terminology) to the base class. this is the only python group (en) on giganews, my first search no wx or qt. gmane.com.python.wxpython is not found gmane.org came up and crashed firefox 3 times searching for python. I'll try the wxpython forrum for x stuff, but you spoiled me with prompt and accurate responses. The wxpython mailing list is wxpython-users. You can subscribe at wxPython.org. It's not mirrored to an actual newsgroup, although I'm sure gmane has it. You'll find wxpython-users to be at least as prompt and accurate, at least with regard to wxPython-specific questions. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with wxPanel derivation class
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
Re: problem with wxPanel derivation class
You've got calls for properties in other classes and you don't initialize the panel object. I edited the code somewhat so it'll at least run. I tried to comment where I changed things, but I may have missed a few minor points. See below: code #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) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrameTwo.__do_layout sizer_1 = wx.BoxSizer(wx.VERTICAL) 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, parent, *args, **kwds): wx.Panel.__init__(self, parent) # Added line 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) self.__doLayout() # added self def __doLayout(self): # added argument 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.label.SetMinSize((-1, 15)) # moved from Frame # maybe comment this and uncommennt frame2's corresponding line self.SetAutoLayout(True) self.SetSizer(sizer) sizer.Fit(self) sizer.SetSizeHints(self) ## 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 Larry is correct. You'll get better help from the wxPython group. See http://wxpython.org/maillist.php Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with wxPanel derivation class
On 10/11/07, @bag.python.org none wrote: wxGlade created a simple Frame with a panel a sizer and 3 wxControls , saticText, TextCtrl, and a Button. snip 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? It's because you didn't call the base class __init__. wxPython is a SWIG wrapper around the C++ wxWidgets library, and if you don't call the base class the SWIG infrastructure that maps your class to an underlying C++ class doesn't happen and you get this error. -- http://mail.python.org/mailman/listinfo/python-list