]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/VListBox.py
4 #----------------------------------------------------------------------
6 # The wx.VListBox is much like a regular wx.ListBox except you draw the
7 # items yourself and the items can vary in height.
8 class MyVListBox(wx
.VListBox
):
10 # This method must be overridden. When called it should draw the
11 # n'th item on the dc within the rect. How it is drawn, and what
12 # is drawn is entirely up to you.
13 def OnDrawItem(self
, dc
, rect
, n
):
14 if self
.GetSelection() == n
:
15 c
= wx
.SystemSettings
.GetColour(wx
.SYS_COLOUR_HIGHLIGHTTEXT
)
17 c
= self
.GetForegroundColour()#wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
18 dc
.SetTextForeground(c
)
19 dc
.DrawLabel(self
._getItemText
(n
), rect
,
20 wx
.ALIGN_LEFT | wx
.ALIGN_CENTER_VERTICAL
)
22 # This method must be overridden. It should return the height
23 # required to draw the n'th item.
24 def OnMeasureItem(self
, n
):
27 for line
in self
._getItemText
(n
).split('\n'):
28 w
, h
= self
.GetTextExtent(line
)
34 # These are also overridable:
36 # OnDrawSeparator(dc, rect, n)
37 # Draw a separator between items. Note that rect may be reduced
38 # in size if desired so OnDrawItem gets a smaller rect.
40 # OnDrawBackground(dc, rect, n)
41 # Draw the background and maybe a border if desired.
44 def _getItemText(self
, item
):
46 return "This is item# %d" % item
48 return "This is item# %d\n with an extra line" % item
50 #----------------------------------------------------------------------
52 # The wx.HtmlListBox derives from wx.VListBox, but draws each item
53 # itself as a wx.HtmlCell.
54 class MyHtmlListBox(wx
.HtmlListBox
):
56 def OnGetItem(self
, n
):
58 return "This is item# <b>%d</b>" % n
60 return "This is item# <b>%d</b> <br>Any <font color='RED'>HTML</font> is okay." % n
62 #----------------------------------------------------------------------
64 class TestPanel(wx
.Panel
):
65 def __init__(self
, parent
, log
):
67 wx
.Panel
.__init
__(self
, parent
, -1)
70 vlb
= MyVListBox(self
, -1, size
=(150, 250), style
=wx
.BORDER_SUNKEN
)
74 vlbSizer
= wx
.BoxSizer(wx
.VERTICAL
)
75 vlbSizer
.Add((spacer
, spacer
))
76 vlbSizer
.Add(wx
.StaticText(self
, -1, "wx.VListBox"), 0, 5, wx
.ALL
)
79 hlb
= MyHtmlListBox(self
, -1, size
=(150, 250), style
=wx
.BORDER_SUNKEN
)
82 hlbSizer
= wx
.BoxSizer(wx
.VERTICAL
)
83 hlbSizer
.Add((spacer
, spacer
))
84 hlbSizer
.Add(wx
.StaticText(self
, -1, "wx.HtmlListBox"), 0, 5, wx
.ALL
)
87 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
88 sizer
.Add((spacer
, spacer
))
90 sizer
.Add((spacer
, spacer
))
91 sizer
.Add((spacer
, spacer
))
97 #----------------------------------------------------------------------
99 def runTest(frame
, nb
, log
):
100 win
= TestPanel(nb
, log
)
103 #----------------------------------------------------------------------
107 overview
= """<html><body>
108 <h2><center>wx.VListBox and wx.HtmlListBox</center></h2>
111 The "V" in wxVListBox stands for both "virtual" because it can have an
112 unlimited number of items since it doesn't store them itself, and
113 "variable" since items can vary in height. It has much the same
114 interface as wxListBox and also emits the same events so you can use
115 the same EVT_LISTBOX function to connect a handler.
118 The wx.HtmlListBox derives from wx.VListBox, but draws each item itself
119 as a wx.HtmlCell. This means that you just need to provide a snippet
120 of HTML for each item when requested.
127 if __name__
== '__main__':
130 run
.main(['', os
.path
.basename(sys
.argv
[0])])