wxPython – UltimateListCtrl How to highlight row when Item gets selected?

  python, python-3.x, user-interface, wxpython

I use different types of widgets inside my UltimateListCtrl. The problem I have in some cases is that I need most of the list to be filled with them. This makes highlighting a row pretty annoying because if you click on a widget the row does not get highlighted, because the focus is on the widget.

How do I prevent that from happening or pass the focus to the row/list?

Here is a sample code to use:

import wx
from wx.lib.agw import ultimatelistctrl as ULC

class TestUltimateListCtrlPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(640,300))

        self.list_ctrl = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
        self.list_ctrl.InsertColumn(0, "Make")
        self.list_ctrl.InsertColumn(1, "Model")
        self.list_ctrl.InsertColumn(2, "Year")
        self.list_ctrl.InsertColumn(3, "Color")

        rows = [("Ford", "Taurus", "1996", "Blue"),
                ("Nissan", "370Z", "2010", "Green"),
                ("Porche", "911", "2009", "Red")
                ]

        for rowIndex, data in enumerate(rows):
            for colIndex, coldata in enumerate(data):
                if colIndex == 0:
                    self.list_ctrl.InsertStringItem(rowIndex, coldata)
                else:
                     self.tab_st = wx.StaticText(self.list_ctrl, label=coldata)            
                     self.list_ctrl.SetItemWindow(rowIndex, colIndex, self.tab_st, expand=True)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list_ctrl, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)


class MyForm(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,wx.ID_ANY,size=(640,300),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
        panel = TestUltimateListCtrlPanel(self)

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop() 

Source: Python Questions

LEAVE A COMMENT