An ObjectListView provides a more convenient and powerful interface to a wx.ListCtrl. The major features of an ObjectListView are:

An ObjectListView works in a declarative manner: the programmer configures how it should work, then gives it the list of objects to display. The primary configuration is in the definitions of the columns. Columns are configured to know which aspect of their model they should display, how it should be formatted, and even how new values should be written back into the model.

See the ObjectListView home page for more information. This site has lots of information about how to use this control, as well as a recipes, faq, and getting started information.

How do I use it?

   1 from ObjectListView import ObjectListView, ColumnDefn
   3 simpleColumns = [
   4 ("Title", "left", 160, valueGetter="title", imageGetter="trackIcon", minimumWidth=40, maximumWidth=200),
   5 ("Artist", valueGetter="artist", minimumWidth=40, maximumWidth=200, autoCompleteCellEditor=True),
   6 ("Album", valueGetter="album", minimumWidth=50, autoCompleteCellEditor=True),
   7 ("Genre", "left", 60, valueGetter="genre", autoCompleteComboBoxCellEditor=True),
   8 ("Rating", "center", valueGetter="rating"),
   9 ("Duration", "center", valueGetter="duration", stringConverter="%S seconds and %M minutes"),
  10 ("Last Played", valueGetter="lastPlayed", stringConverter="%x %X", maximumWidth=100),
  11 ("Comments", valueGetter="comments", minimumWidth=50, isSpaceFilling=True),
  12 ]
  13 self.olvSimple.SetColumns(simpleColumns)
  14 self.olvSimple.SetObjects(self.dataObjects)
  15 self.olvSimple.cellEditMode = ObjectListView.CELLEDIT_F2ONLY

The SetColumns() method defines what columns the control will have. The SetObjects() method tell the control which model objects the control will display. The control then takes those model objects and using the configuration information in the columns builds the contents of the list view.

With the above lines of code, the ObjectListView will

Not bad for 3 lines of your code.

You can download the project, which includes the required python module and documentation, from here (version 1.2, released 6 September, 2008)

ObjectListView (last edited 2010-01-15 00:27:06 by 79-65-133-135)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.