[wxPython] wxColumnSorterMixin, iterate over wxListCtrl ...

Hi,

I have a wxListCtrl that is already filled with data.
When I want to use wxColumnSorterMixin, then this method requires
self.itemDataMap as a dictionary filled with all the ListCtrl data ...

What is the most easy way to populate itemDataMap dictionary with the
data
from the wxListCtrl ?
How can I iterate ove a wxListCtrl ?
Are there alternate ways of implementing a column sort method ?

Thank you very much in advance!

Bye,
Harald

I have a wxListCtrl that is already filled with data.
When I want to use wxColumnSorterMixin, then this method requires
self.itemDataMap as a dictionary filled with all the ListCtrl data ...

What is the most easy way to populate itemDataMap dictionary with the
data
from the wxListCtrl ?

Populate it at the same time that you populate the wxListCtrl

How can I iterate ove a wxListCtrl ?

Are there alternate ways of implementing a column sort method ?

Yes, just do what is in the wxColumnSorterMixin in your own class, and
instead of getting the data from the itemDataMap in the sort compare method
get it however you want. Be warned however that it will be slow if you
fetch the data in the sort compare method directly from the list contorl.
That is why a second copy in itemDataMap is used.

If you don't like the overhead of having a second copy of the data then you
can use the list control in virtual mode and not put any data in the list
control at all. You just have to implement some methods that fetch the data
as needed for display from your own data structures. wxColumnSorterMixin
won't work with it this way, but you can implement sorting just in your data
structures and then call list.Refresh to redisplay the items in sorted
order.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thank you very much in advance!

Bye,
Harald

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Hi,

thanks a lot! Sorting works very well now.

But I've got still one (maybe newbie) prob:

Even thought no error comes up, the images in the column headers do not
display. I've set up everything like in wxPython demo:

[...]
        # Create image list
        self.ilSorter = wxImageList(16, 16)
        self.img_sort_up = self.ilSorter.Add(gfx.getImgSortUpBitmap())
        self.img_sort_down =
self.ilSorter.Add(gfx.getImgSortDownBitmap())
[...]
    # Getter for sorter
    def GetSortImages(self):
        return (self.img_sort_down, self.img_sort_up)
[...]
# Decode embedded image
def getImgSortUpData():
    return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV74S\x00"\x13\x05Cu\xae\xc4`u=\x85d\x05e70\x00\xf3
\xf3\
A>gW\x10\x04\xf3#@|\x0b\x03\x10\x04\xf3\x15\x80|\xbf\xfc\xbcT(\x07\x15PQ
P/\
\x02SP/??\x82(A\xa0\x18L\x14\xbf
X\x0c*\x8a\x10\x8c\x80\x00*\xfb\x88\xa0\xa0\
\x1e\x00\x8c\xcdK\xd3' ))

# Return decoded image
def getImgSortUpBitmap():
    return wxBitmapFromXPMData(getGetImgSortUpData())
[...]

Any hints?

Bye,
Harald

···

-----Ursprüngliche Nachricht-----
Von: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org] Im Auftrag
von Robin Dunn
Gesendet: Montag, 29. Juli 2002 20:22
An: wxpython-users@lists.wxwindows.org
Betreff: Re: [wxPython] wxColumnSorterMixin, iterate over
wxListCtrl ...

> I have a wxListCtrl that is already filled with data.
> When I want to use wxColumnSorterMixin, then this method requires
> self.itemDataMap as a dictionary filled with all the
ListCtrl data ...
>
> What is the most easy way to populate itemDataMap
dictionary with the
> data
> from the wxListCtrl ?

Populate it at the same time that you populate the wxListCtrl

> How can I iterate ove a wxListCtrl ?

> Are there alternate ways of implementing a column sort method ?

Yes, just do what is in the wxColumnSorterMixin in your own class, and
instead of getting the data from the itemDataMap in the sort
compare method
get it however you want. Be warned however that it will be
slow if you
fetch the data in the sort compare method directly from the
list contorl.
That is why a second copy in itemDataMap is used.

If you don't like the overhead of having a second copy of the
data then you
can use the list control in virtual mode and not put any data
in the list
control at all. You just have to implement some methods that
fetch the data
as needed for display from your own data structures.
wxColumnSorterMixin
won't work with it this way, but you can implement sorting
just in your data
structures and then call list.Refresh to redisplay the items in sorted
order.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

>
> Thank you very much in advance!
>
> Bye,
> Harald
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>
>
>

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

OK .. got it! The solution stands in big letters in the demo:

        if 0:
            # for normal simple columns, you can add them like this:
            self.list.InsertColumn(0, "Artist")
            self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT)
            self.list.InsertColumn(2, "Genre")
        else:
            # but since we want images on the column header we have to
do it the hard way:
            info = wxListItem()
            info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE |
wxLIST_MASK_FORMAT
            info.m_image = -1
            info.m_format = 0
            info.m_text = "Artist"
            self.list.InsertColumnInfo(0, info)

            info.m_format = wxLIST_FORMAT_RIGHT
            info.m_text = "Title"
            self.list.InsertColumnInfo(1, info)

            info.m_format = 0
            info.m_text = "Genre"
            self.list.InsertColumnInfo(2, info)

···

---

Sorry about that!

Bye,
Harald

-----Ursprüngliche Nachricht-----
Von: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org] Im Auftrag
von Harald Schneider
Gesendet: Dienstag, 30. Juli 2002 10:32
An: wxpython-users@lists.wxwindows.org
Betreff: AW: [wxPython] wxColumnSorterMixin, iterate over
wxListCtrl ...

Hi,

thanks a lot! Sorting works very well now.

But I've got still one (maybe newbie) prob:

Even thought no error comes up, the images in the column
headers do not
display. I've set up everything like in wxPython demo:

[...]
        # Create image list
        self.ilSorter = wxImageList(16, 16)
        self.img_sort_up = self.ilSorter.Add(gfx.getImgSortUpBitmap())
        self.img_sort_down =
self.ilSorter.Add(gfx.getImgSortDownBitmap())
[...]
    # Getter for sorter
    def GetSortImages(self):
        return (self.img_sort_down, self.img_sort_up)
[...]
# Decode embedded image
def getImgSortUpData():
    return cPickle.loads(zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV74S\x00"\x13\x05Cu\xae\xc4`u=\x85d\x05e
70\x00\xf3
\xf3\
A>gW\x10\x04\xf3#@|\x0b\x03\x10\x04\xf3\x15\x80|\xbf\xfc\xbcT(
\x07\x15PQ
P/\
\x02SP/??\x82(A\xa0\x18L\x14\xbf
X\x0c*\x8a\x10\x8c\x80\x00*\xfb\x88\xa0\xa0\
\x1e\x00\x8c\xcdK\xd3' ))

# Return decoded image
def getImgSortUpBitmap():
    return wxBitmapFromXPMData(getGetImgSortUpData())
[...]

Any hints?

Bye,
Harald

> -----Ursprüngliche Nachricht-----
> Von: wxpython-users-admin@lists.wxwindows.org
> [mailto:wxpython-users-admin@lists.wxwindows.org] Im Auftrag
> von Robin Dunn
> Gesendet: Montag, 29. Juli 2002 20:22
> An: wxpython-users@lists.wxwindows.org
> Betreff: Re: [wxPython] wxColumnSorterMixin, iterate over
> wxListCtrl ...
>
>
> > I have a wxListCtrl that is already filled with data.
> > When I want to use wxColumnSorterMixin, then this method requires
> > self.itemDataMap as a dictionary filled with all the
> ListCtrl data ...
> >
> > What is the most easy way to populate itemDataMap
> dictionary with the
> > data
> > from the wxListCtrl ?
>
> Populate it at the same time that you populate the wxListCtrl
>
>
> > How can I iterate ove a wxListCtrl ?
>
>
>
> > Are there alternate ways of implementing a column sort method ?
>
> Yes, just do what is in the wxColumnSorterMixin in your own
class, and
> instead of getting the data from the itemDataMap in the sort
> compare method
> get it however you want. Be warned however that it will be
> slow if you
> fetch the data in the sort compare method directly from the
> list contorl.
> That is why a second copy in itemDataMap is used.
>
> If you don't like the overhead of having a second copy of the
> data then you
> can use the list control in virtual mode and not put any data
> in the list
> control at all. You just have to implement some methods that
> fetch the data
> as needed for display from your own data structures.
> wxColumnSorterMixin
> won't work with it this way, but you can implement sorting
> just in your data
> structures and then call list.Refresh to redisplay the
items in sorted
> order.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
>
> >
> > Thank you very much in advance!
> >
> > Bye,
> > Harald
> >
> >
> > _______________________________________________
> > wxpython-users mailing list
> > wxpython-users@lists.wxwindows.org
> > http://lists.wxwindows.org/mailman/listinfo/wxpython-users
> >
> >
> >
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users