OLV Different behaviour 4.0.1 > 4.2.0

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)

        # 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)
    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
                new_index = len(data)-1
            data.insert(new_index, data.pop(index))
            self.products = data

    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
                new_index = 0
            data.insert(new_index, data.pop(index))
            self.products = data

    def setbooks(self):
            ColumnDefn("title", "left", 220, "title"),
            ColumnDefn("author", "left", 200, "author"),
            ColumnDefn("isbn", "right", 100, "isbn"),
            ColumnDefn("mfg", "left", 180, "mfg")


class mainframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, 
                          title="objectlistview demo", size=(800,600))
        panel = mainpanel(self)

if __name__ == "__main__":
    app = wx.App(False)
    frame = mainframe()
1 Like

First, I had to install ObjectListView from pypi. Second I needed to make a change to ObjectListView.py
line 1752 changed “sz.GetHeight()/3” to " int(sz.GetHeight() / 3)" Just to get your code to work.
Using Ubuntu 22.04 with python 3.10.6 and wxPython 4.2.0 I get the following:
I click on a row -> the row turns to a red color with white color for the text. When I click on the up the row goes up and the down makes the row go down. Taking a quick review of the code that is what I would have expected.

Thanks for taking the trouble.
Ignoring the up/down buttons, if you move your mouse up and down the entries in the OLV does each one highlight as it is under the cursor? This is what I get with py310/wx420 (not wanted), but not with py36/wx401.
Plus the colours are different, surely they are set locally and should not differ between versions of wx.

When I use the keyboard up and down keys the focus moves as I would expect. The highlight moves to the row below or above depending on the up or down key pressed (does not highlight all the rows).
If you do not want the up or down key to effect the focus then you will need to subclass the event methods (just a quick review - maybe there are other ways).
I have never used ObjectListView. But if this code is the same code you used with wx401 then there must have been a bug some where. Also I did you make the same changes to the code as I was forced to do?

OLV is slightly out of date, so yes we have to make that small modification (actually there are few other changes needed but they are not apparent in this small app).
Its not about OLV it’s about different behaviour under different versions of wx.

Forget the up and down buttons / keys. The question is: is there some kind of hot tracking happening for you when you move the cursor over the entries? As I place the pointer on an entry (with no clicking) it highlights that entry in 4.2.0 but not in 4.0.1

Sorry I am not sure what you mean by “hot tracking happening”.
I do NOT have anything happen when I place the cursor on any row without clicking.

OK, it must be specific to windows then. Thanks.

Thanks for figuring this out. Someone else just reported this exact bug to me and I was quite happy to find someone else had already figured it out.

I wonder if there’s a way to put in a PR on the OLV project to bring it up to date?

1 Like

I’m the one Mike is referring to. Same problem on Mac OS / wxPython 4.2.0. Another vote to get it fixed.

Don’t you have permission to make the changes?

OLV is a really great tool, it’s just a shame that the Python version is no longer maintained.
The C# version has lots of neat new features and bug fixes :slightly_frowning_face: