By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

wxPython, sorting dates in a ListCtrl with the ColumnSorterMixin

P: n/a
I have a ListCtrl with 5 columns. The first 4 columns are either
strings or integers, but the last column is a string in the format of
MM-DD-YYYY. I searched google and also read over the
ColumnSorterMixin code & examples, but still can not figure out how to
to write a user-defined sort routine just for the last column in order
to sort that column by date. I still want the sorting of the first
four columns to work as expected. How is this done?

I am using Python 2.3.4 and wxPython 2.5.2.8.

Thanks,
-John
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
John Taylor wrote:
I have a ListCtrl with 5 columns. The first 4 columns are either
strings or integers, but the last column is a string in the format of
MM-DD-YYYY. I searched google and also read over the
ColumnSorterMixin code & examples, but still can not figure out how to
to write a user-defined sort routine just for the last column in order
to sort that column by date. I still want the sorting of the first
four columns to work as expected. How is this done?

I am using Python 2.3.4 and wxPython 2.5.2.8.


Here is a tiny bit of code to sort dates.

--------------------------------
# Dates must look like YYYY-MM-DD to be sortable.
# I hope your dates all have the same length.
# Otherwise, you'll have to improve the def.
#
def uniformized(dd): return dd[-4:]+dd[:2]+dd[3:5]

# Let's create some dates to sort.
#
entry=["12-31-2020","07-14-1792","10-08-2004","06-01-1920"]
nbr_of_entries=len(entry)

# Now, let's sort!
#
temp=[]

for foo in range(nbr_of_entries):
temp.append( (uniformized(entry[foo]),foo) ) # That's a tuple.

temp.sort()

for ignore,a in temp: # Only the var _a_ matters.
print entry[a]

--------------------------------

In the last loop, _a_ is the key to access all columns which will then be
sorted according to the dates in the fifth column.

In the _foo_ loop, if you replace the uniformized date by the content of any
other column, the whole table will be sorted according to this column when
you'll access it with the _a_ loop.

Of course, your datas remain untouched. Only the _a_ key enables you to
access them as if they were really sorted.

I hope that's clear...

See ya,

--
==================
Remi Villatel
maxilys_@_tele2.fr
==================
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.