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


Groups > comp.lang.python > #31049 > unrolled thread

Re: FW: question Python custome events

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-10-09 10:45 -0600
Last post2012-10-09 10:45 -0600
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.


Contents

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

#31049 — Re: FW: question Python custome events

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-10-09 10:45 -0600
SubjectRe: FW: question Python custome events
Message-ID<mailman.2011.1349801169.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web