wxPython smart list control with model-based data display and virtual scrolling.
- Cross-platform ListView/DataView abstraction
- Model-based data display with configurable columns
- Virtual lists for large datasets
- Windows performance optimizations (IAT hooking)
- Supports attributes, dict keys, and callables
uv add smart_list
# or
pip install smart_list
import wx
from smart_list import SmartList, Column
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
people = [Person("Alice", 30), Person("Bob", 25)]
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="Smart List", size=(400, 300))
panel = wx.Panel(self)
self.list = SmartList(parent=panel, style=wx.LC_REPORT)
self.list.set_columns([
Column(title="Name", model_field="name", width=150),
Column(title="Age", model_field="age", width=100)
])
self.list.add_items(people)
self.Show()
app = wx.App()
MyFrame()
app.MainLoop()
from smart_list import VirtualSmartList
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, size=(400, 300))
panel = wx.Panel(self)
self.data = [{"name": f"Item {i}", "value": i} for i in range(10000)]
self.list = VirtualSmartList(
parent=panel, style=wx.LC_REPORT,
get_virtual_item=lambda i: self.data[i],
update_cache=lambda start, end: self.data[start:end+1]
)
self.list.set_columns([
Column(title="Name", model_field="name"),
Column(title="Value", model_field="value")
])
self.list.update_count(len(self.data))
self.Show()
set_columns(columns)
: Set column definitionsadd_items(items)
: Add items to listget_items()
: Get all model objectsupdate_models(models)
: Update all models and refreshinsert_item(index, item)
: Insert item at positiondelete_item(item)
: Remove itemupdate_item(item)
: Update specific item
- Requires
get_virtual_item(index)
function - Optional
update_cache(from_row, to_row)
for batch loading update_count(count)
: Set total item countrefresh()
: Refresh display and clear cachefind_index_of_item(item)
: Find item index
title
: Header textwidth
: Column width (-1 for auto)model_field
: Attribute name, dict key, or callable
Column(title="Name", model_field="name")
Column(title="Email", model_field="email")
Column(title="Full", model_field=lambda p: f"{p.first} {p.last}")
- wxPython
- frozendict
- resource_finder
- pywin32 (Windows only)