13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advanced widgetshttp://www.zetcode.com/wxpython/advanced/for i in packages:index = self.list.InsertStringItem(sys.maxint, i[0])self.list.SetStringItem(index, 1, i[1])self.list.SetStringItem(index, 2, i[2])We insert data into the wx.ListCtrl using two methods. Each row begins witha InsertStringItem() method. <strong>The</strong> first parameter of the method specifiesthe row number. By giving a sys.maxint we ensure, that each call will insertdata after the last row. <strong>The</strong> method returns the row index. <strong>The</strong>SetStringItem() method adds data to the consecutive columns of the currentrow.MixinsMixins are classes that further enhance the functionality of a wx.ListCtrl.Mixin classes are so called helper classes. <strong>The</strong>y are located inwx.lib.mixins.listctrl module. In order to use them, the programmer has toinherit from these classes.<strong>The</strong>re are five available mixins. As of 2.8.1.1.wx.ColumnSorterMixinwx.ListCtrlAutoWidthMixinwx.ListCtrlSelectionManagerMixwx.TextEditMixinwx.CheckListCtrlMixinwx.ColumnSorterMixin is a mixin that enables sorting of columns in a reportview. wx.ListCtrlAutoWidthMixin class automatically resizes the last columnto the end of the wx.ListCtrl. By default, the last column does not take theremaining space. See the previous example. wx.ListCtrlSelectionManagerMixdefines platform independent selection policy. wx.TextEditMixin enables textto be edited. wx.CheckListCtrlMixin adds a check box to each row. This waywe can control rows. We can set every row to be checked or unchecked.<strong>The</strong> following code shows, how we can use ListCtrlAutoWidthMixin#!/usr/bin/python# autowidth.pyimport wximport sysfrom wx.lib.mixins.listctrl import ListCtrlAutoWidthMixinactresses = [('jessica alba', 'pomona', '1981'), ('sigourney weaver', 'new york', '1949'),('angelina jolie', 'los angeles', '1975'), ('natalie portman', 'jerusalem', '1981'),('rachel weiss', 'london', '1971'), ('scarlett johansson', 'new york', '1984' )]class AutoWidthListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin):def __init__(self, parent):wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT)ListCtrlAutoWidthMixin.__init__(self)12 de 21 27/04/2008 1:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!