Emulating an evt generation in code rather than user clicking

If you have bound an event to a list eg:

self.bind(wx.EVT_LIST_ITEM_SELECTED,self.onRowSelected, self.searchlist)

which would jumpt to a subroutine when the user clicked on a row on the list:

def onRowSelected(self,evt):
  dothenextthing

Is it possible to trigger the event in code to execute the subroutine
contents without the user clicking on the actual list?

Reason is in this situation is that I've a couple of linked lists. When the
first list contents contains only 1 item, I want to automatically populate
the second list without the user having to click on it.

Thanks in anticipation of example, not just a 'yes'.

Richard

Presumably you use the methods of the event object to discover what item
was clicked on. You can emulate that via...

    class fakeEvent:
        def __init__(self, STUFF_TO_SAVE):
            self.saved = STUFF_TO_SAVE
        def whatevermethodname(self):
            return self.saved

    self.onRowSelected(fakeEvent(ARG))

Is that sufficient code?

- Josiah

···

Richard Terry <rterry@internode.on.net> wrote:

If you have bound an event to a list eg:

self.bind(wx.EVT_LIST_ITEM_SELECTED,self.onRowSelected, self.searchlist)

which would jumpt to a subroutine when the user clicked on a row on the list:

def onRowSelected(self,evt):
  dothenextthing

Is it possible to trigger the event in code to execute the subroutine
contents without the user clicking on the actual list?

Reason is in this situation is that I've a couple of linked lists. When the
first list contents contains only 1 item, I want to automatically populate
the second list without the user having to click on it.

Thanks in anticipation of example, not just a 'yes'.

Richard Terry wrote:

If you have bound an event to a list eg:

self.bind(wx.EVT_LIST_ITEM_SELECTED,self.onRowSelected,
self.searchlist)

which would jumpt to a subroutine when the user clicked on a
row on the list:

def onRowSelected(self,evt):
  dothenextthing

Is it possible to trigger the event in code to execute the
subroutine contents without the user clicking on the actual list?

Reason is in this situation is that I've a couple of linked
lists. When the first list contents contains only 1 item, I
want to automatically populate the second list without the
user having to click on it.

Thanks in anticipation of example, not just a 'yes'.

Here are two ideas.

1. def onRowSelected(self,evt):
        self.dothenextthing()

    def dothenextthing(self):
        do whatever you want

    To call the method programatically, just call self.dothenextthing()

2. def onRowSelected(self,evt=None):
        dothenexthing

    Now onRowSelected can be called directly as well as via an event.

My guess is that you have some logic to derive which row was selected before
you 'dothenextthing', whereas if you call it yourself, you know in advance
which row to use. If so, a variation on idea 1 may be the way to go -

    def onRowSelected(self,evt):
        row = evt.RowSelected() [I'm guessing at the syntax here]
        self.dothenextthing(row)

    def dothenextthing(self,row):
        do whatever you want

Frank Millman

Thanks frank.

I'd already implemented example 1, but I ended up using your
last example 3.

Also BTW big thanks for taking the time to actually type out those few
concrete code examples, they really made a difference to me.

Richard

···

On Tuesday 09 January 2007 16:27, Frank Millman wrote:

Richard Terry wrote:
> If you have bound an event to a list eg:
>
> self.bind(wx.EVT_LIST_ITEM_SELECTED,self.onRowSelected,
> self.searchlist)
>
> which would jumpt to a subroutine when the user clicked on a
> row on the list:
>
> def onRowSelected(self,evt):
> dothenextthing
>
> Is it possible to trigger the event in code to execute the
> subroutine contents without the user clicking on the actual list?
>
> Reason is in this situation is that I've a couple of linked
> lists. When the first list contents contains only 1 item, I
> want to automatically populate the second list without the
> user having to click on it.
>
> Thanks in anticipation of example, not just a 'yes'.

Here are two ideas.

1. def onRowSelected(self,evt):
        self.dothenextthing()

    def dothenextthing(self):
        do whatever you want

    To call the method programatically, just call self.dothenextthing()

2. def onRowSelected(self,evt=None):
        dothenexthing

    Now onRowSelected can be called directly as well as via an event.

My guess is that you have some logic to derive which row was selected
before you 'dothenextthing', whereas if you call it yourself, you know in
advance which row to use. If so, a variation on idea 1 may be the way to go
-

    def onRowSelected(self,evt):
        row = evt.RowSelected() [I'm guessing at the syntax here]
        self.dothenextthing(row)

    def dothenextthing(self,row):
        do whatever you want

Frank Millman

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