Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19296

Re: Using an object inside a class

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'attributes': 0.05; 'stuff.': 0.05; 'method,': 0.07; 'subject:object': 0.07; 'def': 0.13; 'cc:addr:python-list': 0.15; 'mon,': 0.15; '**kwargs):': 0.16; '__init__': 0.16; 'hierarchy': 0.16; 'then:': 0.16; 'wrote:': 0.16; 'instance': 0.18; 'yet.': 0.18; 'jan': 0.19; 'cheers,': 0.20; 'suggest': 0.20; 'cc:no real name:2**0': 0.21; "aren't": 0.21; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'received:74.125.82.174': 0.24; 'cc:2**0': 0.25; 'code': 0.25; 'pm,': 0.26; 'skip:_ 20': 0.26; 'function': 0.27; 'depends': 0.28; 'message-id:@mail.gmail.com': 0.28; 'see,': 0.28; 'cc:addr:python.org': 0.29; 'class': 0.29; '-1,': 0.30; 'none,': 0.30; 'app': 0.31; 'correct': 0.31; 'actually': 0.32; "can't": 0.32; "isn't": 0.32; "won't": 0.33; 'object': 0.33; 'belong': 0.34; 'loop': 0.34; 'frame': 0.34; 'init': 0.34; 'latter': 0.34; 'received:74.125.82': 0.34; 'skip:" 20': 0.35; 'instead,': 0.36; 'skip:" 10': 0.36; 'but': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'skip:_ 10': 0.37; 'event': 0.38; 'created': 0.38; 'finding': 0.39; 'why': 0.39; 'being': 0.39; 'called': 0.39; 'subject:: ': 0.39; 'more': 0.61; 'your': 0.61; 'schedule': 0.63; 'skip:w 30': 0.63; 'skip:w 50': 0.73
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=zp9bS9FerWQUQ5QrpDv/STSHi2nKn5Oc1OmL8BUnoiA=; b=hRgHDzmS9aX1dpDVM4oBZSkFREnLhD4u15qE7EQnAdkEvZgs5SuMZiSIkhjBvnqRaJ Q+A8Ng9YTZZsWoIZ0k/pLGpCypgUcOkB7Aiic/3/qML2LYB198rBXI9DyKpD+ALet+tJ 9MCL47PSYb8kNYfE3m633bBdmgF+YnmqoyWFY=
MIME-Version 1.0
In-Reply-To <CAGz2ECbMEGSTj1_L665fSkzkSXGkhXhD8YOH9LiAE0xerx2=-Q@mail.gmail.com>
References <CAGz2ECYwdnB2ZoTo-DXHhO1_MzdjWeYB+nxeNJ+xivPa8N-tVA@mail.gmail.com> <jfkfn3$92a$1@dough.gmane.org> <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 Mon, 23 Jan 2012 15:57:00 -0700
Subject Re: Using an object inside a class
To Jonno <jonnojohnson@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4995.1327359452.27778.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327359452 news.xs4all.nl 6869 [2001:888:2000:d::a6]:55770
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19296

Show key headers only | View raw


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


Thread

Re: Using an object inside a class Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 15:57 -0700

csiph-web