Ich wollte mich mal etwas näher mit virtuellen ListCtrl auseinenader zu setzten und hätte da ein kleines Problem ...
Die virtuelle ListCtrl sieht so aus:
Code: Alles auswählen
class VirtualListCtrl(wx.ListCtrl):
def __init__(self, parent, data_source):
wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VIRTUAL|wx.LC_VRULES)
self.data = data_source
self.update_len()
for col, text in enumerate(self.data.get_column_headers()):
self.InsertColumn(col, text)
self.alt = wx.ListItemAttr()
self.alt.SetBackgroundColour("light gray")
def OnGetItemText(self, item, col):
data = self.data.get_item(item+1)
value = data[col]
if value is None:
value = u""
return value
def OnGetItemAttr(self, item):
return self.alt if item % 2 else None
def update_len(self):
self.SetItemCount(self.data.get_count())
Code: Alles auswählen
class DataSource(object):
COLUMNS = ["Index", "Song", "Band", "Album", "Url", "Comment"]
def __init__(self, dbname):
conn = sqlite.connect(dbname)
self.cursor = conn.cursor()
def get_column_headers(self):
return DataSource.COLUMNS
def get_count(self):
self.cursor.execute("select count(*) from info")
return self.cursor.fetchone()[0]
def get_item(self, index):
self.cursor.execute("select * from info where id=?", (index,))
data = list(self.cursor.fetchone())
if not data:
data = [None, u"", u"", u"", u"", u""]
return data
def insert(self, data):
self.cursor.execute("insert into info values (?, ?, ?, ?, ?, ?)", data)
self.cursor.connection.commit()
def update(self, data):
data = data[1:] + [data[0]]
self.cursor.execute("update info set song=?, band=?, album=?, url=?, comment=? where id=?", data)
self.cursor.connection.commit()
def delete(self, index):
self.cursor.execute("delete from info where id=?", (index,))
self.cursor.connection.commit()
Wie kann ich nach einzelnen Spalten sortieren (zB nach Album) ?