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/<strong>The</strong> previous example showed a wx.ListCtrl in a report view. With noheaders. We shall create our own headers. We show two wx.ListCtrl widgets.One is on the right side and the other one on the left side of the application.splitter = wx.SplitterWindow(self, -1, style=wx.SP_LIVE_UPDATE|wx.SP_NOBORDER)...splitter.SplitVertically(panel1, panel2)<strong>The</strong> splitter will split the main window into two vertical parts. <strong>The</strong> splitterwill show two panels. Those two panels will have another two panels. <strong>The</strong>ycreate Feeds and Articles headers. <strong>The</strong> rest of the space will be occupied byour two wx.ListCtrl widgets.list2 = ListCtrlRight(panel22, -1)list2.SetName('ListControlOnRight')When we create ListCtrlRight object, we give it a name ListControlOnRight.This is because we need ListCtrlRight and ListCtrlLeft two widgets tocommunicate.def OnSelect(self, event):window = self.parent.GetGrandParent().FindWindowByName('ListControlOnRight')index = event.GetIndex()window.LoadData(index)This code is in ListCtrlLeft class. Here we locate the ListCtrlRight object andcall it's LoadData() method.def LoadData(self, index):self.DeleteAllItems()for i in range(3):self.InsertStringItem(0, articles[index][i])<strong>The</strong> LoadData() method first clears all items. <strong>The</strong>n it inserts the articlenames from the globally defined articles list. <strong>The</strong> index has been passed.def OnSize(self, event):size = self.parent.GetSize()self.SetColumnWidth(0, size.x-5)event.Skip()Both wx.ListCtrls have only one column. Here we ensure that the size of thecolumn equals to size of the parent panel. <strong>The</strong> application would not looknice otherwise. Why do we extract 5px? This number is a kind of magicnumber. If we extract exactly 5px, the horizotal scrollbars do not appear. Onother platforms, the number might be different.18 de 21 27/04/2008 1:05

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

Saved successfully!

Ooh no, something went wrong!