subclassing of wx.Frame

Tim van der Leeuw wrote:

Hi Martijn,

    Hi All,
    I do not want to do all initialisation of a wx.Frame in the OnInit
    method of wx.App, but in wx.Frame.__init__()

    What I did:

    class MainFrame(wx.Frame):
           def __init__(self, res):
                   self.frame = res.LoadFrame(None,"main_frame")
                   <snip>

You need to call the constructor of wx.Frame from your __init__ method:
        wx.Frame.__init__(self, parent, id, title, ...)

This might conflict with your desire to load the frame from a resource and set it as a property of your 'MainFrame'.

Since I don't use resources, I'm not sure how to solve that problem, since I don't use resources.

Use 2-phase create, like this:

class MainFrame(wx.Frame):
  def __init__(self, res):
    pre = wx.PreFrame()
    res.LoadOnFrame(pre, None, "main_frame")
    self.PostCreate(pre)

···

On Mon, Mar 24, 2008 at 1:37 PM, Martijn <martijn.brouwer@fiberworld.nl > <mailto:martijn.brouwer@fiberworld.nl>> wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Martijn wrote:

···

On Mon, 2008-03-24 at 11:01 -0700, Robin Dunn wrote:

Tim van der Leeuw wrote:

Hi Martijn,

On Mon, Mar 24, 2008 at 1:37 PM, Martijn <martijn.brouwer@fiberworld.nl >>> <mailto:martijn.brouwer@fiberworld.nl>> wrote:

Use 2-phase create, like this:

class MainFrame(wx.Frame):
  def __init__(self, res):
    pre = wx.PreFrame()
    res.LoadOnFrame(pre, None, "main_frame")
    self.PostCreate(pre)

Thanks, this works, but I still have a problem. When I try to get
references to the child widgets of my MainFrame, XRCCTRL always returns
None:

class ControlFrame(wx.Frame):
  def __init__(self, res):
    Pre = wx.PreFrame()
    res.LoadOnFrame(Pre, None, "control_frame")
    self.PostCreate(Pre)
    self.Bind(wx.EVT_WINDOW_CREATE, self.OnCreate)

  def OnCreate(self, event):
    # setting up event handling, XRCCTRL returns None
    self.my_control = xrc.XRCCTRL(self, "my_control")
    wx.EVT_SCROLL_CHANGED(self.my_control, self.call_back)

How to solve this?

Are you sure there is a widget within the frame with a name of "my_control"? The name matching is probably case-sensitive.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!