Re: FW: question Python custome events

Discussion in 'Python' started by Ian Kelly, Oct 9, 2012.

  1. Ian Kelly

    Ian Kelly Guest

    On Tue, Oct 9, 2012 at 2:35 AM, Hussain, Mushabbar
    <> 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
     
    Ian Kelly, Oct 9, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mahesh Devjibhai Dhola

    Problem in deriving custome class from XmlNode

    Mahesh Devjibhai Dhola, Oct 15, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    499
    Mahesh Devjibhai Dhola
    Oct 15, 2004
  2. Samir Patel

    Custome Control...

    Samir Patel, Oct 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    456
    Samir Patel
    Oct 5, 2004
  3. KJ
    Replies:
    3
    Views:
    503
    =?Utf-8?B?RGVhc3Vu?=
    Nov 18, 2004
  4. =?Utf-8?B?cm9nZXIzMQ==?=

    Custome Smart Navigation

    =?Utf-8?B?cm9nZXIzMQ==?=, Oct 6, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    377
    =?Utf-8?B?cm9nZXIzMQ==?=
    Oct 6, 2005
  5. Ryan
    Replies:
    1
    Views:
    341
Loading...

Share This Page