Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19296
| References | (2 earlier) <CAGz2ECYB=__eKdhdbgWDzRY2DSW4ZcFzuobQCMJFPogV0hcOJA@mail.gmail.com> <CALwzidmYEc9q1ve7u1Vgu-AAVJ6ZBrF36hCZ_=fndvuAFgXMfg@mail.gmail.com> <CAGz2ECYY9bpNrY3aOS95dwi_vC4p0KHQtERLF51pFHFTaKv6Tg@mail.gmail.com> <CALwzidk23=b2nmGZy=d_nB1yQiLSnRiw7sw4FYkkJZv9v+CEEQ@mail.gmail.com> <CAGz2ECbMEGSTj1_L665fSkzkSXGkhXhD8YOH9LiAE0xerx2=-Q@mail.gmail.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2012-01-23 15:57 -0700 |
| Subject | Re: Using an object inside a class |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4995.1327359452.27778.python-list@python.org> (permalink) |
On Mon, Jan 23, 2012 at 3:45 PM, Jonno <jonnojohnson@gmail.com> wrote:
> 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.
Yeah, that's a good point. In that case, that code really doesn't
belong in the Class1 __init__ method, as it depends on the whole
hierarchy having already been properly initialized. Instead, I
suggest using the wx.CallAfter function to schedule that code for when
the event loop has actually been started. For example:
class Class1(wx.Panel):
def __init__(self, parent, id = -1, dpi = None, **kwargs):
# Do all your initialization stuff. Then:
wx.CallAfter(self._init_graph_panel)
def _init_graph_panel(self):
wx.GetApp().frame.graph_panel.plot([1,2,3,4,5],[3,4,3,4,3])
wx.GetApp().frame.graph_panel.figure.canvas.draw()
By the way, looking at your object hierarchy more closely, isn't
"app.frame.graph_panel" going to end up being the same thing as just
"self.figure"? Why not just use the latter and remove the reliance on
finding the correct frame?
Cheers,
Ian
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Using an object inside a class Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 15:57 -0700
csiph-web