Fix some glitches in the dataview samples

This commit is contained in:
Robin Dunn
2020-04-02 16:33:48 -07:00
parent de25f3091f
commit 28f9534a91
2 changed files with 14 additions and 8 deletions

View File

@@ -263,12 +263,14 @@ class TestPanel(wx.Panel):
tr = dv.DataViewTextRenderer() tr = dv.DataViewTextRenderer()
c0 = dv.DataViewColumn("Genre", # title c0 = dv.DataViewColumn("Genre", # title
tr, # renderer tr, # renderer
0, # data model column 0) # data model column
width=80)
self.dvc.AppendColumn(c0) self.dvc.AppendColumn(c0)
else: else:
# otherwise there are convenience methods for the simple cases # otherwise there are convenience methods for the simple cases
self.dvc.AppendTextColumn("Genre", 0, width=80) c0 = self.dvc.AppendTextColumn("Genre", 0)
c0.SetMinWidth(80)
c0.SetAlignment(wx.ALIGN_LEFT)
c1 = self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE) c1 = self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE)
c2 = self.dvc.AppendTextColumn("Title", 2, width=260, mode=dv.DATAVIEW_CELL_EDITABLE) c2 = self.dvc.AppendTextColumn("Title", 2, width=260, mode=dv.DATAVIEW_CELL_EDITABLE)
@@ -295,6 +297,7 @@ class TestPanel(wx.Panel):
self.Sizer.Add(b1, 0, wx.ALL, 5) self.Sizer.Add(b1, 0, wx.ALL, 5)
wx.CallAfter(c0.SetMinWidth, 80)
def OnNewView(self, evt): def OnNewView(self, evt):
f = wx.Frame(None, title="New view, shared model", size=(600,400)) f = wx.Frame(None, title="New view, shared model", size=(600,400))
@@ -328,7 +331,7 @@ def runTest(frame, nb, log):
genre = Genre(song.genre) genre = Genre(song.genre)
data[song.genre] = genre data[song.genre] = genre
genre.songs.append(song) genre.songs.append(song)
data = data.values() data = list(data.values())
# Finally create the test window # Finally create the test window
win = TestPanel(nb, log, data=data) win = TestPanel(nb, log, data=data)

View File

@@ -72,11 +72,14 @@ class TestModel(dv.DataViewIndexListModel):
item2, item1 = item1, item2 item2, item1 = item1, item2
row1 = self.GetRow(item1) row1 = self.GetRow(item1)
row2 = self.GetRow(item2) row2 = self.GetRow(item2)
a = self.data[row1][col]
b = self.data[row2][col]
if col == 0: if col == 0:
return cmp(int(self.data[row1][col]), int(self.data[row2][col])) a = int(a)
else: b = int(b)
return cmp(self.data[row1][col], self.data[row2][col]) if a < b: return -1
if a > b: return 1
return 0
def DeleteRows(self, rows): def DeleteRows(self, rows):
# make a copy since we'll be sorting(mutating) the list # make a copy since we'll be sorting(mutating) the list