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


Groups > comp.lang.python > #31049

Re: FW: question Python custome events

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'implements': 0.07; 'variable,': 0.07; 'subject:question': 0.08; 'python': 0.09; 'callback': 0.09; 'events.': 0.09; 'bind': 0.16; 'cleaner': 0.16; 'oct': 0.16; 'window;': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'variable': 0.20; 'changes': 0.20; 'define': 0.20; 'simpler': 0.22; 'cheers,': 0.23; 'external': 0.24; 'header :In-Reply-To:1': 0.25; 'url:wiki': 0.26; 'values': 0.26; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this.': 0.29; 'at:': 0.31; 'could': 0.32; 'message.': 0.33; 'received:74.125.82': 0.33; 'skip:s 30': 0.33; 'event.': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'said,': 0.35; 'something': 0.35; 'received:74.125': 0.36; 'url:org': 0.36; 'should': 0.36; 'possible': 0.37; 'itself': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'you.': 0.61; 'fire': 0.62; 'information': 0.63; 'easier,': 0.84; 'observer': 0.84; 'subject:events': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Ha1u4mFRpvbzUzZWvf45nJA8Q+LZ1ptcm376kuxnNtA=; b=zE3SZZrRjtiGEJySUcaYpljJbJvwWA2ESs85uxH2BBjsx1ugktdFG4XLibh0oF/LIM /Ct/WNVsslBARtNSzoVWmZ2tKKRp/zAdrA/nXf0Yj4Ybv4rNvj8PYvA5KbtCAa/OANxO G6kRzosRZnawyUwWoydrRFNYeI13If8CP/3KfoqvmjdB58JROyPLyWPvthtPpjSk2Bx9 IWiQjYdfsNOb7Wt/G1d13KWvGXacd48u6VO/ERZbRYT8pyxJVrK27ItYe3rFL0QyBvs2 NV/cSYH0AcLR9+r+SWa1H6s7tLFqJU4eFzAsrL91Sya9Gd9ZHgxcM2NzzSsvH3L+K/KJ Juqw==
MIME-Version 1.0
In-Reply-To <FE568A5D442B314AA200D599AB6090F508F9134B@IE1AEX3001.global.ds.honeywell.com>
References <FE568A5D442B314AA200D599AB6090F508F9134B@IE1AEX3001.global.ds.honeywell.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 9 Oct 2012 10:45:31 -0600
Subject Re: FW: question Python custome events
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.2011.1349801169.27098.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349801169 news.xs4all.nl 6904 [2001:888:2000:d::a6]:40202
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31049

Show key headers only | View raw


On Tue, Oct 9, 2012 at 2:35 AM, Hussain, Mushabbar
<Mushabbar.Hussain@honeywell.com> wrote:
>
>
> Hi,
>
> Is it possible to define an Event which should fire when a value of a
> variable changes? Something like below
>
>
>
> self.Bind(wx.EVT_ON_VAL_CHANGE, variable_to_watch, self.Callback)
>
>
>
> I need a Text ctrl UI which continuously changes values based on external
> data changes. Unfortunately I could not find events in Python which can be
> triggered when a variable value changes?  Please let me know how this can be
> achieved?

Yes, you would need to:

1) encapsulate the variable;

2) define a custom event;

3) set up a wx.EvtHandler for the variable, since it's not itself
associated with a window;

4) bind your callback to the event handler;

5) have the variable setter fire the custom event.

That said, an event is likely not going to be the best way to do this.
 You should instead use the wx.lib.pubsub module, which implements the
observer pattern for you.  This will be cleaner and easier, as you
only need to:

1) encapsulate the variable;

2) subscribe your callback to the update message;

3) have the variable setter publish the update message.

Observers are also conceptually simpler than events.  You can find
information about pubsub at:

http://wiki.wxpython.org/WxLibPubSub

Cheers,
Ian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: FW: question Python custome events Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-09 10:45 -0600

csiph-web