A curious behavior with wx.App

Microsoft Windows XP [Version 5.1.2600]

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)]

wxPython 3.0.3.dev78327 msw (phoenix)

dir()

[‘EOL’, ‘_’, ‘builtins’, ‘cached’, ‘doc’, ‘loader’, ‘name’, ‘package’, ‘spec’, ‘os’, ‘sys’, ‘wx’]

wx.GetApp()

wx.App()

<wx.core.App object at 0x00BA8D20>

wx.GetApp()

<wx.core.App object at 0x00BA8D20>

wx.GetApp()

<wx.core.App object at 0x00BA8D20>

wx.App()

<wx.core.App object at 0x00BCA780>

wx.GetApp()

wx.GetApp()

wx.App()

<wx.core.App object at 0x00BA8D20>

wx.GetApp()

wx.GetApp()

app = wx.App()

wx.GetApp()

<wx.core.App object at 0x00BCA780>

app

<wx.core.App object at 0x00BCA780>

I taking a shot in the dark here, is this realated to weak references.

More significantly will this effect

app = wx.GetApp() or wx.App()
stuff()
app.MainLoop()

``

DevPlayer wrote:

Microsoft Windows XP [Version 5.1.2600]

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32
bit (Intel)]
wxPython 3.0.3.dev78327 msw (phoenix)
>>>
>>> dir()
['EOL', '_', '__builtins__', '__cached__', '__doc__', '__loader__',
'__name__', '__package__', '__spec__', 'os', 'sys', 'wx']
>>>
>>> wx.GetApp()
>>> wx.App()
<wx.core.App object at 0x00BA8D20>
>>> wx.GetApp()
<wx.core.App object at 0x00BA8D20>
>>> wx.GetApp()
<wx.core.App object at 0x00BA8D20>
>>> wx.App()
<wx.core.App object at 0x00BCA780>
>>> wx.GetApp()
>>> wx.App()
<wx.core.App object at 0x00BA8D20>
>>> wx.GetApp()
>>> app = wx.App()
>>> wx.GetApp()
<wx.core.App object at 0x00BCA780>
>>> app
<wx.core.App object at 0x00BCA780>
>>>

I taking a shot in the dark here, is this realated to weak references.

Probably just that the new app object was allocated at the same address as the old one. The wx.GetApp implementation looks like this:

wxPyApp* wxGetApp()
{
     return wxPyApp::ms_appInstance;
}

And the wxPyApp class has this code:

class wxPyApp : public wxApp
{
public:
     wxPyApp() : wxApp() {
         m_assertMode = wxAPP_ASSERT_EXCEPTION;
         m_startupComplete = false;
         ms_appInstance = this;
     }

     ~wxPyApp() {
         ms_appInstance = NULL;
         wxApp::SetInstance(NULL);
     }
...
};

So wx.GetApp is basically just returning a pointer to the most recently instantiated wxPyApp object, and it is cleared when the app object is destroyed.

More significantly will this effect

>>
app =wx.GetApp()orwx.App()
stuff()
app.MainLoop()

No.

···

--
Robin Dunn
Software Craftsman