473,426 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

wxPython, sorting dates in a ListCtrl with the ColumnSorterMixin

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
1 4284
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fabio Pliger | last post by:
Hi all, i'm working on a very large project using wx 2.5... On one frame i have a wx.lib.mixins.listctrl widget, wich is a listctrl extended with the possibility to edit the columns text...
0
by: Sven Tissot | last post by:
Hello, I am trying to build an editable ListCtrl_edit via TextEditMixin. It displays o.k. and I can edit the first field with this is the code piece: class VokabelListCtrl(wxListCtrl,...
6
by: ReMEn | last post by:
My question is this: How can I apply some kind of a function to a listview that allows it to sort by both string and numbers whenever a header is clicked? For example: -------------------...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
6
by: zdp | last post by:
Dear all: I made a window program by wxPython. Split windows, treectrl, listctrl and textctrl are used. When I program in python, the look & feel of the window controls are like the windos XP...
1
by: Benjamin | last post by:
Hello! I am writing a search engine with wxPython as the GUI. As the search thread returns items, it adds them to a Queue which is picked up by the main GUI thread calling itself recursively with...
1
by: vedrandekovic | last post by:
Hello, How can I Insert image with string in ListCtrl with this example: # Import ftputil module - like ftplib from ftputil import FTPHost # Create connection...
0
by: asrekdal | last post by:
Hi, I am working with a wxPython ListCtrl Control and wondering if it is possilbe to place images in the cell rather than a string? -- Andrew
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.