问题
What is the best choice for a Python GUI application to display large number of thumbnails, e.g. 10000 or more? For performance reasons such thumbnail control must support virtual items, i.e. request application for those thumbnails only which are currently visible to user.
回答1:
In wxPython you can use wxGrid for this as it supports virtual mode and custom cell renderers.
This is the minimal interface you have to implement for a wxGrid "data provider":
class GridData(wx.grid.PyGridTableBase):
def GetColLabelValue(self, col):
pass
def GetNumberRows(self):
pass
def GetNumberCols(self):
pass
def IsEmptyCell(self, row, col):
pass
def GetValue(self, row, col):
pass
This is the minimal interface you have to implement for a wxGrid cell renderer:
class CellRenderer(wx.grid.PyGridCellRenderer):
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
pass
You can find a working example that utilizes these classes in wxPython docs and demos, it's called Grid_MegaExample.
回答2:
If you had to resort to writing your own, I've had good results using the Python Imaging Library to create thumbnails in the past. http://www.pythonware.com/products/pil/
回答3:
Just for completeness: there is a thumbnailCtrl written in/for wxPython, which might be a good starting point.
来源:https://stackoverflow.com/questions/215052/efficient-image-thumbnail-control-for-python