Problems with XRC on windows

Stephen Thorne wrote:

I've got a situation with some code that runs on linux, but doesn't on
windows.

Are you using the same version of wxPython on each platform?

class PrototypeFrame(wx.FramePtr):
    def __init__(self, parent, resource):
        self.parent = parent
        self.res = resource
        w = resource.LoadFrame(None, 'Test')
        wx.FramePtr.__init__(self, w.this)
        self.InitFrame()
    def InitFrame(): pass # called on linux, attributeerror on windows

The issue lays in that under windows, wx.FramePtr.__init__ mutates
self, converting the instance to a wx.Frame object, while under linux,
it remains an instance of PrototypeFrame.

This sounds like you are using 2.5 on Windows and 2.4 on Linux. In 2.5 the *Ptr classes are more of an implementation detail and shouldn't ever be used directly. (They really shouldn't have been used before either, but it wasn't a problem if they were...)

The correct way to do the above in 2.5 is something like this:

class PrototypeFrame(wx.Frame):
  def __init__(self, parent, resource):
    w = resource.LoadFrame(parent, "Test")
    self.PostCreate(w)

The PostCreate method is new in 2.5, but if you need your code to still be compatible with 2.4 you can do the same things in your code and I think it will work correctly. It's implemented like this:

     def PostCreate(self, pre):
         """
         Phase 3 of the 2-phase create <wink!>
         Call this method after precreating the window with the 2-phase create method.
         """
         self.this = pre.this
         self.thisown = pre.thisown
         pre.thisown = 0
         if hasattr(self, '_setOORInfo'):
             self._setOORInfo(self)
         if hasattr(self, '_setCallbackInfo'):
             self._setCallbackInfo(self, self.__class__)

···

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