Auto scrolling a list to a selected item

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto scrolling a list to a selected item

Brennan Williams
I'm using a TableEditor in a view to display a list of item names with a
selected= and I have a search string so that I can look for the name of
an item and select it. This works ok but I was wondering if it is
possible to get the list to scroll down to the row for the selected
item. I presume that is probably a wx or qt feature (I'm using wx) that
isn't easily accessible via Traits. I've been taking a look at the
TableEditor documentation and there's a lot there that I didn't realise
was there but doesn't look like there's a way to do it.

Brennan
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Auto scrolling a list to a selected item

Adam Hughes
Don't have time to give this a test right now, but the table editor should
have a *selected_indices* parameter.   So when you change your selected
trait, just have an event listener that looks up the index to which the
selected trait belongs in your list and then set it.  Here's some
pseudocode, if you need a working example, I"ll try to give one tomorrow:

class Test(HasTraits):
entrybox=Str  #This is your search box
mylist=List  #This is the list that you edit with table_editor
table_editor=TableEditor(
                            ... blah blah
                            selected='my_selection'
                            selected_indicies='my_index'
                                    )

def _entrybox_changed(self):
       if self.entrybox in self.mylist:
             self.my_index=mylist.index(self.entrybox)


All that does is looks for the item in your list that matches your search
criteria and sets the "my_index' trait to the index of that item in the
list.


On Tue, Feb 14, 2012 at 8:56 PM, Brennan Williams <
[hidden email]> wrote:

> I'm using a TableEditor in a view to display a list of item names with a
> selected= and I have a search string so that I can look for the name of
> an item and select it. This works ok but I was wondering if it is
> possible to get the list to scroll down to the row for the selected
> item. I presume that is probably a wx or qt feature (I'm using wx) that
> isn't easily accessible via Traits. I've been taking a look at the
> TableEditor documentation and there's a lot there that I didn't realise
> was there but doesn't look like there's a way to do it.
>
> Brennan
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev