Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19296 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2012-01-23 15:57 -0700 |
| Last post | 2012-01-23 15:57 -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:57 -0700
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-01-23 15:57 -0700 |
| Subject | Re: Using an object inside a class |
| Message-ID | <mailman.4995.1327359452.27778.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web