]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxVListBox.py
1 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
8 #----------------------------------------------------------------------
10 # The wxVListBox is much like a regular wxListBox except you draw the
11 # items yourself and the items can vary in height.
12 class MyVListBox(wx
.VListBox
):
14 # This method must be overridden. When called it should draw the
15 # n'th item on the dc within the rect. How it is drawn, and what
16 # is drawn is entirely up to you.
17 def OnDrawItem(self
, dc
, rect
, n
):
18 dc
.DrawLabel(self
._getItemText
(n
), rect
,
19 wx
.ALIGN_LEFT | wx
.ALIGN_CENTER_VERTICAL
)
21 # This method must be overridden. It should return the height
22 # required to draw the n'th item.
23 def OnMeasureItem(self
, n
):
26 for line
in self
._getItemText
(n
).split('\n'):
27 w
, h
= self
.GetTextExtent(line
)
33 # These are also overridable:
35 # OnDrawSeparator(dc, rect, n)
36 # Draw a separator between items. Note that rect may be reduced
37 # in size if desired so OnDrawItem gets a smaller rect.
39 # OnDrawBackground(dc, rect, n)
40 # Draw the background and maybe a border if desired.
43 def _getItemText(self
, item
):
45 return "This is item# %d" % item
47 return "This is item# %d\n with an extra line" % item
49 #----------------------------------------------------------------------
51 # The wx.HtmlListBox derives from wx.VListBox, but draws each item
52 # itself as a wx.HtmlCell.
53 class MyHtmlListBox(wx
.HtmlListBox
):
55 def OnGetItem(self
, n
):
57 return "This is item# <b>%d</b>" % n
59 return "This is item# <b>%d</b> <br>Any <font color='RED'>HTML</font> is okay." % n
61 #----------------------------------------------------------------------
63 class TestPanel(wx
.Panel
):
64 def __init__(self
, parent
, log
):
66 wx
.Panel
.__init
__(self
, parent
, -1)
69 vlb
= MyVListBox(self
, -1, size
=(150, 250), style
=wx
.BORDER_SUNKEN
)
73 vlbSizer
= wx
.BoxSizer(wx
.VERTICAL
)
74 vlbSizer
.Add((spacer
, spacer
))
75 vlbSizer
.Add(wx
.StaticText(self
, -1, "wx.VListBox"), 0, 5, wx
.ALL
)
78 hlb
= MyHtmlListBox(self
, -1, size
=(150, 250), style
=wx
.BORDER_SUNKEN
)
81 hlbSizer
= wx
.BoxSizer(wx
.VERTICAL
)
82 hlbSizer
.Add((spacer
, spacer
))
83 hlbSizer
.Add(wx
.StaticText(self
, -1, "wx.HtmlListBox"), 0, 5, wx
.ALL
)
86 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
87 sizer
.Add((spacer
, spacer
))
89 sizer
.Add((spacer
, spacer
))
90 sizer
.Add((spacer
, spacer
))
96 #----------------------------------------------------------------------
98 def runTest(frame
, nb
, log
):
99 win
= TestPanel(nb
, log
)
102 #----------------------------------------------------------------------
106 overview
= """<html><body>
107 <h2><center>wxVListBox and wxHtmlListBox</center></h2>
110 The "V" in wxVListBox stands for both "virtual" because it can have an
111 unlimited number of items since it doesn't store them itself, and
112 "variable" since items can vary in height. It has much the same
113 interface as wxListBox and also emits the same events so you can use
114 the same EVT_LISTBOX function to connect a handler.
117 The wxHtmlListBox derives from wxVListBox, but draws each item itself
118 as a wxHtmlCell. This means that you just need to provide a snippet
119 of HTML for each item when requested.
126 if __name__
== '__main__':
129 run
.main(['', os
.path
.basename(sys
.argv
[0])])