On Mon, Jan 23, 2012 at 4:20 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > > The App object is created and the wx framework already knows about it. > It's just not assigned to the app global yet, and the OnInit call has > not completed yet. See: > > Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import wx > >>> class MyApp(wx.App): > ... def OnInit(self): > ... print "wx.GetApp() =", wx.GetApp() > ... print "app =", app > ... return True > ... > >>> app = MyApp(0) > wx.GetApp() = <__main__.MyApp; proxy of <Swig Object of type 'wxPyApp > *' at 0x18d8fc0> > > app = > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 7823, in __init__ > self._BootstrapApp() > File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", > line 7420, in _BootstrapApp > return _core_.PyApp__BootstrapApp(*args, **kwargs) > File "<stdin>", line 4, in OnInit > NameError: global name 'app' is not defined > > I see, so that would get me access to the app instance during init of Class1 but if I can't access frame or the object as they still aren't created yet. I can only do that in attributes that I know won't be called until the app is created. I'd have to do something like this:
class Class1: def __init__(self): self.app = wx.GetApp() def Method1(self): self.app.frame.object This doesn't seem that pythonic. Is there a better way to do what I'm trying to do? Is there a better way to create my object for example?
-- http://mail.python.org/mailman/listinfo/python-list