I want to create an ultimate list ctrl based table where the user can sort the columns by clicking on the column header. Here's the code I attempted: - import wx
-
import wx.lib.mixins.listctrl as listmix
-
from wx.lib.agw import ultimatelistctrl as ULC
-
-
APPNAME='Sortable Ultimate List Ctrl'
-
APPVERSION='1.0'
-
MAIN_WIDTH=300
-
MAIN_HEIGHT=300
-
-
musicdata = {
-
0 : ("Bad English", "The Price Of Love"),
-
1 : ("DNA featuring Suzanne Vega", "Tom's Diner"),
-
2 : ("George Michael", "Praying For Time"),
-
3 : ("Gloria Estefan", "Here We Are"),
-
4 : ("Linda Ronstadt", "Don't Know Much"),
-
5 : ("Michael Bolton", "How Am I Supposed To Live Without You"),
-
6 : ("Paul Young", "Oh Girl"),
-
}
-
-
########################################################################
-
class TestUltimateListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
-
-
#----------------------------------------------------------------------
-
def __init__(self, parent):
-
wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(MAIN_WIDTH,MAIN_HEIGHT))
-
-
self.index = 0
-
-
self.list_ctrl = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
-
self.list_ctrl.InsertColumn(0, "Artist")
-
self.list_ctrl.InsertColumn(1, "Title", wx.LIST_FORMAT_RIGHT)
-
self.list_ctrl.InsertColumn(2, "Download")
-
-
items = musicdata.items()
-
index = 0
-
for key, data in items:
-
pos=self.list_ctrl.InsertStringItem(index, data[0])
-
self.list_ctrl.SetStringItem(index, 1, data[1])
-
#self.list_ctrl.SetStringItem(index, 2, data[2])
-
button = wx.Button(self.list_ctrl, id=wx.ID_ANY, label="Download")
-
self.list_ctrl.SetItemWindow(pos, col=2, wnd=button, expand=True)
-
self.list_ctrl.SetItemData(index, key)
-
index += 1
-
-
# Now that the list exists we can init the other base class,
-
# see wx/lib/mixins/listctrl.py
-
self.itemDataMap = musicdata
-
listmix.ColumnSorterMixin.__init__(self, 3)
-
self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list_ctrl)
-
-
sizer = wx.BoxSizer(wx.VERTICAL)
-
sizer.Add(self.list_ctrl, 1, wx.ALL|wx.EXPAND, 5)
-
self.SetSizer(sizer)
-
-
-
def GetListCtrl(self):
-
return self.list_ctrl
-
-
#----------------------------------------------------------------------
-
def OnColClick(self, event):
-
pass
-
-
########################################################################
-
class MyForm(wx.Frame):
-
-
#----------------------------------------------------------------------
-
def __init__(self):
-
wx.Frame.__init__(self,None,wx.ID_ANY,'%s v%s' % (APPNAME,APPVERSION),size=(MAIN_WIDTH,MAIN_HEIGHT),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
-
-
# Add a panel so it looks the correct on all platforms
-
panel = TestUltimateListCtrlPanel(self)
-
-
#----------------------------------------------------------------------
-
# Run the program
-
if __name__ == "__main__":
-
app = wx.App(False)
-
frame = MyForm()
-
frame.Show()
-
app.MainLoop()
Clicking on the column does not sort the 'Artist' or 'Title' fields. I want to be able to sort them when the user clicks on the column headers. Please help.
This is how it looks like 0 1436 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Krick |
last post by:
I was talking to a co-worker today. He used to work in computers way,
way, back in the days when computers had little to no memory,
operating systems hadn't been invented yet, and everything was...
|
by: juglesh |
last post by:
Hello, I would like to be able to have the user sort a list of items
similarly to the way you sort your queue on Netflix.com. (the numbers
dont change dynamically on netflix, they must be doing...
|
by: Robin Tucker |
last post by:
How do I sort the items in a list box?
I am using a class derived from IComparer to sort items on columns in a
ListView, but the ListBox doesn't support this kind of facility. The
"items" in my...
|
by: Shi Mu |
last post by:
I have a list like ,,,]. How can I sort the list
based on the second value in the item?
That is,
I want the list to be:
,,,]
|
by: Jan Smith |
last post by:
I've searched the overloads for the Array.Sort method, and I haven't found a
clear answer to my question. Maybe it's not in Array.Sort.
Here's the question:
I initialize an array X with the...
|
by: Alex Chudnovsky |
last post by:
I have come across with what appears to be a significant performance bug in
..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same
data. Same data on the same CPU gets sorted a...
|
by: Stuart |
last post by:
I am using Visual Basic 2005.
I have created a two dimensional ArrayList named aSystem that is populated as
follows:-
aSystem.Add(New PickList(0, "Undefined"))
aSystem.Add(New PickList(-1,...
|
by: Michael Hamm |
last post by:
I'd like to sort items in an XML file using XSLT. Say I have
<item><n>Jefferson</n><n>Hancock</n><foo>bar</foo></item>
<item><n>Washington</n><foo>baz</foo></item>...
|
by: rn5a |
last post by:
Can the items in a ListBox be sorted by the name of the items?
The ListBox actually lists all directories & files existing in a
directory on the server. Note that all the directories should be...
|
by: neehakale |
last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort.
I got an idea,in which situation we can use...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |