Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19294 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2012-01-23 15:20 -0700 |
| Last post | 2012-01-23 15:20 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Using an object inside a class Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 15:20 -0700
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-01-23 15:20 -0700 |
| Subject | Re: Using an object inside a class |
| Message-ID | <mailman.4992.1327357292.27778.python-list@python.org> |
On Mon, Jan 23, 2012 at 2:52 PM, Jonno <jonnojohnson@gmail.com> wrote:
> On Mon, Jan 23, 2012 at 3:42 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>>
>> Exactly. The line "app = MyApp(0)" creates a MyApp instance and then
>> assigns it to "app". As part of the MyApp creation process, it
>> creates a MyFrame, which creates a Tab, which creates a Class1, which
>> attempts to reference "app". All of this happens before that
>> "MyApp(0)" call has returned, so the result of that call has not
>> actually been assigned to "app" yet.
>>
>> I suggest using wx.GetApp() instead.
>>
> That totally makes sense. However I'm not sure I understand your suggestion
> how to use wx.GetApp()
> Isn't the wxApp still not created before Class1 is instantiated so I still
> can't call wx.GetApp() in __init__ of Class1 can I?
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
Cheers,
Ian
Back to top | Article view | comp.lang.python
csiph-web