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


Groups > comp.lang.python > #31049

Re: FW: question Python custome events

References <FE568A5D442B314AA200D599AB6090F508F9134B@IE1AEX3001.global.ds.honeywell.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-09 10:45 -0600
Subject Re: FW: question Python custome events
Newsgroups comp.lang.python
Message-ID <mailman.2011.1349801169.27098.python-list@python.org> (permalink)

Show all headers | 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