我正在使用 ObjectListView 1.2 (Python),并且对奇怪的行为感到非常困惑。我有一个具有双字段的对象。如果该值非零(无论是 int 还是 double),OLV 将显示该值,但只要该值为零,它就不会在该列中显示该对象的任何内容。
SSCCE:
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import wx
from ObjectListView import ObjectListView, ColumnDefn
class MyObj:
def __init__(self, name, id):
self.name = name
self.id = id
@staticmethod
def getObjects():
objList = []
for i in range(0,5):
objList.append(MyObj("item" + str(i), i))
return objList
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.Init()
def Init(self):
self.InitModel()
self.InitWidgets()
self.InitObjectListView()
def InitModel(self):
self.songs = MyObj.getObjects()
def InitWidgets(self):
panel = wx.Panel(self, -1)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(panel, 1, wx.ALL|wx.EXPAND)
self.SetSizer(sizer_1)
self.myOlv = ObjectListView(panel, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_2.Add(self.myOlv, 1, wx.ALL|wx.EXPAND, 4)
panel.SetSizer(sizer_2)
self.Layout()
def InitObjectListView(self):
self.myOlv.SetColumns([
ColumnDefn("Title", "left", 120, "name"),
ColumnDefn("ID", "left", 120, "id")
])
self.myOlv.SetObjects(self.songs)
if __name__ == '__main__':
app = wx.PySimpleApp(1)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "ObjectListView Simple Example1")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()