Select item without triggering event handler

Hi All,

When I update my GUI state, I populate ListCtrl with data and then call ListCtrl.Select(index) to select appropriate item in the list. The problem is that in this particular case I don't want to trigger the EVT_LIST_ITEM_SELECTED handler.

How can I avoid that?

Best regards,
Igor

···

--
Igor Jese, igor@jeseonline.com
http://mockupscreens.com
igor@mockupscreens.com

Hi Igor,

my solution for the same kind of problem was to create a decorator like this:

def if_not_updating(func):
def wrapper(*args):
if not “updating” in dir(args[0]) or not args[0].updating:

        return func(*args)
    else: return None
return wrapper

and I simply decorate the event handler

@if_not_updating
def OnItemSelected(self, event):
    ...

now when you want your events silenced… just do a

self.updating = True

ListCtrl.Select(index)

self.updating = False

or alternatively you can create another decorator for this methods that does this automatically like this:

def updateGuard(func):
def wrapper(*args):
args[0].updating = True
ret = func(*args)
args[0].updating = False
return ret
return wrapper

and use it like:

@updateGuard
def MySilentScreenUpdating(…)

···

On 1/18/07, Igor Jese igor@jeseonline.com wrote:

Hi All,

When I update my GUI state, I populate ListCtrl with data and then call

ListCtrl.Select(index) to select appropriate item in the list. The problem
is that in this particular case I don’t want to trigger the
EVT_LIST_ITEM_SELECTED handler.

How can I avoid that?

Best regards,

Igor


Igor Jese, igor@jeseonline.com
http://mockupscreens.com
igor@mockupscreens.com


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


There is NO FATE, we are the creators.

I tried the first solution and it works, thanks!

Unfortunately, this leads to a different problem: no row is selected at the end.

What I try to do basically is:

1. Click on the row in ListCtrl (report-style and single-selection)
(Handle EVT_ITEM_SELECTED like follows:)
2. delete all items from ListCtrl
3. populate ListCtrl
4. select correct row with ListCtrl.Select()
5. some other gui updating

The reason I want to do this is I have many GUI dependencies on the underlaying data, so I want to refresh whole gui in one sweep each time a relevant event happens.

I'm fairly new to wxPython (migrating from C++/Fox). What am I doing wrong?

Best regards,
Igor

···

On Thu, 18 Jan 2007 08:55:50 +0100, Peter Damoc <pdamoc@gmail.com> wrote:

Hi Igor,

my solution for the same kind of problem was to create a decorator like
this:

def if_not_updating(func):
    def wrapper(*args):
        if not "updating" in dir(args[0]) or not args[0].updating:
            return func(*args)
        else: return None
    return wrapper

and I simply decorate the event handler

    @if_not_updating
    def OnItemSelected(self, event):
        ...

now when you want your events silenced... just do a

self.updating = True
...
ListCtrl.Select(index)
...
self.updating = False

or alternatively you can create another decorator for this methods that does
this automatically like this:

def updateGuard(func):
    def wrapper(*args):
        args[0].updating = True
        ret = func(*args)
        args[0].updating = False
        return ret
    return wrapper

and use it like:

@updateGuard
def MySilentScreenUpdating(...)

On 1/18/07, Igor Jese <igor@jeseonline.com> wrote:

Hi All,

When I update my GUI state, I populate ListCtrl with data and then call
ListCtrl.Select(index) to select appropriate item in the list. The problem
is that in this particular case I don't want to trigger the
EVT_LIST_ITEM_SELECTED handler.

How can I avoid that?

Best regards,
Igor

--
Igor Jese, igor@jeseonline.com
http://mockupscreens.com
igor@mockupscreens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
Igor Jese, igor@jeseonline.com

igor@mockupscreens.com

This is a very very wrong way to approach things… DON’T DO IT!

I know it looks easier now but take my word for it… you will live to regret it!
I’m not speaking from theory but from the pain that I’m feeling every time I try to change some code in one of my programs.

Take a piece of paper and a pen and just try to brainstorm a way to break the app in modules… do it now while it is still young.

Independent modules are way easier to maintain.

I know it feels like wasting time… it sure did seamed that way to me too, and now I’m looking at some very weird flickering in some areas that shouldn’t change… :wink:

You can either learn from my mistake or just repeat it… your choice :wink:

Peter

···

On 1/19/07, Igor Jese igor@jeseonline.com wrote:

The reason I want to do this is I have many GUI dependencies on the
underlaying data, so I want to refresh whole gui in one sweep each time a
relevant event happens.


There is NO FATE, we are the creators.

Thanks for sound advice, Peter!

I do try to break app in pieces with as little dependencies as possible. What I have meant is that GUI has many *logical* dependencies on my data: many parts of the screen has to be updated reflected changes on exactly the same data. Up to now, I have been dealing with this by implementing Model-View-Controller, with GUI "views" (parts of screen) subscribing to changes in the model.

This time I want to implement different flavor of MVC, Martin Fowler describes it as "Passive View":

What I'm fed up with when implementing MVC using observers/publishers is very painfull and troublesome both testing and debugging.

But this is my first app in wxPython, so I'm quite prepared for a long journey. I started reading "wxPython in Action" and also I have found this list's archives very informative :slight_smile:

Best regards,
Igor

···

The reason I want to do this is I have many GUI dependencies on the
underlaying data, so I want to refresh whole gui in one sweep each time a
relevant event happens.

This is a very very wrong way to approach things... DON'T DO IT!
I know it looks easier now but take my word for it... you will live to
regret it!
I'm not speaking from theory but from the pain that I'm feeling every time I
try to change some code in one of my programs.

Take a piece of paper and a pen and just try to brainstorm a way to break
the app in modules... do it now while it is still young.

Independent modules are way easier to maintain.

I know it feels like wasting time... it sure did seamed that way to me too,
and now I'm looking at some very weird flickering in some areas that
shouldn't change... :wink:

You can either learn from my mistake or just repeat it... your choice :wink:

Peter

--
Igor Jese, igor@jeseonline.com

igor@mockupscreens.com

Have you seen wx.lib.pubsub? It may make the whole publish/subscribe
business easier than what you were doing before.

- Josiah

···

"Igor Jese" <igor@jeseonline.com> wrote:

What I'm fed up with when implementing MVC using observers/publishers is
very painfull and troublesome both testing and debugging.

I indeed heard about wx.lib.pubsub, and it surely is an advantage.

What worries me though, is having to test and debug *everything else* through publish/subscribe - not the publish/subscribe implementation itself. I've been doing things that way for years and I'm convinced there must be a better way. So I plan to try "Passive View" and if this doesn't cut it then "Supervising controller" variants.
(see Passive View)

Best regards,
Igor

···

"Igor Jese" <igor@jeseonline.com> wrote:

What I'm fed up with when implementing MVC using observers/publishers is
very painfull and troublesome both testing and debugging.

Have you seen wx.lib.pubsub? It may make the whole publish/subscribe
business easier than what you were doing before.

--
Igor Jese, igor@jeseonline.com

igor@mockupscreens.com