I am using ObjectListView. This is Mike Driscoll’s code to demonstrate the problem.
Under wx 4.0.1 it works as expected, but under wx 4.2.0 any item under the cursor gets highlighted.
The colour scheme of the clicked item is different too… Dark blue with white text on 401, light blue with border and original black text on 420.
Any help to return to the previous behaviour gratefully received. Thanks.
(also tried wx v4.1.1 which behaves the same as 4.2.0)
import wx
from ObjectListView import ObjectListView, ColumnDefn
class book(object):
"""
model of the book object
contains the following attributes:
'isbn', 'author', 'manufacturer', 'title'
"""
def __init__(self, title, author, isbn, mfg):
self.isbn = isbn
self.author = author
self.mfg = mfg
self.title = title
def __repr__(self):
return "<book: {title}>".format(title=self.title)
class mainpanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
self.current_selection = None
self.products = [book("wxpython in action", "robin dunn",
"1932394621", "manning"),
book("hello world", "warren and carter sande",
"1933988495", "manning"),
book("core python programming", "wesley chun",
"0132269937", "prentice hall"),
book("python programming for the absolute beginner",
"michael dawson", "1598631128",
"course technology"),
book("learning python", "mark lutz",
"0596513984", "o'reilly")
]
self.dataolv = ObjectListView(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER | wx.LC_HRULES | wx.LC_VRULES)
self.setbooks()
# create up and down buttons
up_btn = wx.Button(self, -1, "up")
up_btn.Bind(wx.EVT_BUTTON, self.move_up)
down_btn = wx.Button(self, -1, "down")
down_btn.Bind(wx.EVT_BUTTON, self.move_down)
# create some sizers
mainsizer = wx.BoxSizer(wx.VERTICAL)
mainsizer.Add(self.dataolv, 1, wx.ALL|wx.EXPAND, 5)
mainsizer.Add(up_btn, 0, wx.ALL|wx.CENTER, 5)
mainsizer.Add(down_btn, 0, wx.ALL|wx.CENTER, 5)
self.SetSizer(mainsizer)
def move_up(self, event):
"""
move an item up the list
"""
self.current_selection = self.dataolv.GetSelectedObject()
data = self.dataolv.GetObjects()
if self.current_selection:
index = data.index(self.current_selection)
if index > 0:
new_index = index - 1
else:
new_index = len(data)-1
data.insert(new_index, data.pop(index))
self.products = data
self.setbooks()
self.dataolv.Select(new_index)
def move_down(self, event):
"""
move an item down the list
"""
self.current_selection = self.dataolv.GetSelectedObject()
data = self.dataolv.GetObjects()
if self.current_selection:
index = data.index(self.current_selection)
if index < len(data) - 1:
new_index = index + 1
else:
new_index = 0
data.insert(new_index, data.pop(index))
self.products = data
self.setbooks()
self.dataolv.Select(new_index)
def setbooks(self):
self.dataolv.SetColumns([
ColumnDefn("title", "left", 220, "title"),
ColumnDefn("author", "left", 200, "author"),
ColumnDefn("isbn", "right", 100, "isbn"),
ColumnDefn("mfg", "left", 180, "mfg")
])
self.dataolv.SetObjects(self.products)
class mainframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None,
title="objectlistview demo", size=(800,600))
panel = mainpanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = mainframe()
app.MainLoop()