2003-08-08 17:32:52 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
2003-08-08 17:32:52 -04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
# The wx.VListBox is much like a regular wx.ListBox except you draw the
|
2003-08-08 17:32:52 -04:00
|
|
|
# items yourself and the items can vary in height.
|
2003-12-08 20:23:28 -05:00
|
|
|
class MyVListBox(wx.VListBox):
|
2003-08-08 17:32:52 -04:00
|
|
|
|
|
|
|
# This method must be overridden. When called it should draw the
|
|
|
|
# n'th item on the dc within the rect. How it is drawn, and what
|
|
|
|
# is drawn is entirely up to you.
|
|
|
|
def OnDrawItem(self, dc, rect, n):
|
2003-12-29 14:24:16 -05:00
|
|
|
if self.GetSelection() == n:
|
|
|
|
c = wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
|
|
|
|
else:
|
2004-03-04 19:06:33 -05:00
|
|
|
c = self.GetForegroundColour()#wx.SystemSettings.GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
|
|
|
|
dc.SetFont(self.GetFont())
|
2003-12-29 14:24:16 -05:00
|
|
|
dc.SetTextForeground(c)
|
2003-08-08 17:32:52 -04:00
|
|
|
dc.DrawLabel(self._getItemText(n), rect,
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
|
2003-08-08 17:32:52 -04:00
|
|
|
|
|
|
|
# This method must be overridden. It should return the height
|
|
|
|
# required to draw the n'th item.
|
|
|
|
def OnMeasureItem(self, n):
|
|
|
|
height = 0
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-08-08 17:32:52 -04:00
|
|
|
for line in self._getItemText(n).split('\n'):
|
|
|
|
w, h = self.GetTextExtent(line)
|
|
|
|
height += h
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2003-08-08 17:32:52 -04:00
|
|
|
return height + 5
|
|
|
|
|
|
|
|
|
|
|
|
# These are also overridable:
|
|
|
|
#
|
|
|
|
# OnDrawSeparator(dc, rect, n)
|
|
|
|
# Draw a separator between items. Note that rect may be reduced
|
|
|
|
# in size if desired so OnDrawItem gets a smaller rect.
|
|
|
|
#
|
|
|
|
# OnDrawBackground(dc, rect, n)
|
|
|
|
# Draw the background and maybe a border if desired.
|
|
|
|
|
|
|
|
|
|
|
|
def _getItemText(self, item):
|
|
|
|
if item % 2 == 0:
|
|
|
|
return "This is item# %d" % item
|
|
|
|
else:
|
|
|
|
return "This is item# %d\n with an extra line" % item
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
# The wx.HtmlListBox derives from wx.VListBox, but draws each item
|
|
|
|
# itself as a wx.HtmlCell.
|
|
|
|
class MyHtmlListBox(wx.HtmlListBox):
|
2003-08-08 17:32:52 -04:00
|
|
|
|
|
|
|
def OnGetItem(self, n):
|
|
|
|
if n % 2 == 0:
|
|
|
|
return "This is item# <b>%d</b>" % n
|
|
|
|
else:
|
|
|
|
return "This is item# <b>%d</b> <br>Any <font color='RED'>HTML</font> is okay." % n
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestPanel(wx.Panel):
|
2003-08-08 17:32:52 -04:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-08-08 17:32:52 -04:00
|
|
|
spacer = 50
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
vlb = MyVListBox(self, -1, size=(150, 250), style=wx.BORDER_SUNKEN)
|
2003-08-08 17:32:52 -04:00
|
|
|
vlb.SetItemCount(50)
|
|
|
|
vlb.SetSelection(0)
|
|
|
|
vlb.SetFocus()
|
2003-12-08 20:23:28 -05:00
|
|
|
vlbSizer = wx.BoxSizer(wx.VERTICAL)
|
2003-08-08 17:32:52 -04:00
|
|
|
vlbSizer.Add((spacer, spacer))
|
2003-12-08 20:23:28 -05:00
|
|
|
vlbSizer.Add(wx.StaticText(self, -1, "wx.VListBox"), 0, 5, wx.ALL)
|
2003-08-08 17:32:52 -04:00
|
|
|
vlbSizer.Add(vlb)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
hlb = MyHtmlListBox(self, -1, size=(150, 250), style=wx.BORDER_SUNKEN)
|
2003-08-08 17:32:52 -04:00
|
|
|
hlb.SetItemCount(50)
|
|
|
|
hlb.SetSelection(0)
|
2003-12-08 20:23:28 -05:00
|
|
|
hlbSizer = wx.BoxSizer(wx.VERTICAL)
|
2003-08-08 17:32:52 -04:00
|
|
|
hlbSizer.Add((spacer, spacer))
|
2003-12-08 20:23:28 -05:00
|
|
|
hlbSizer.Add(wx.StaticText(self, -1, "wx.HtmlListBox"), 0, 5, wx.ALL)
|
2003-08-08 17:32:52 -04:00
|
|
|
hlbSizer.Add(hlb)
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
2003-08-08 17:32:52 -04:00
|
|
|
sizer.Add((spacer, spacer))
|
|
|
|
sizer.Add(vlbSizer)
|
|
|
|
sizer.Add((spacer, spacer))
|
|
|
|
sizer.Add((spacer, spacer))
|
|
|
|
sizer.Add(hlbSizer)
|
|
|
|
|
|
|
|
self.SetSizer(sizer)
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
2004-01-12 22:17:17 -05:00
|
|
|
<h2><center>wx.VListBox and wx.HtmlListBox</center></h2>
|
2003-08-08 17:32:52 -04:00
|
|
|
<hr>
|
|
|
|
|
|
|
|
The "V" in wxVListBox stands for both "virtual" because it can have an
|
|
|
|
unlimited number of items since it doesn't store them itself, and
|
|
|
|
"variable" since items can vary in height. It has much the same
|
|
|
|
interface as wxListBox and also emits the same events so you can use
|
|
|
|
the same EVT_LISTBOX function to connect a handler.
|
|
|
|
<p>
|
|
|
|
|
2004-01-12 22:17:17 -05:00
|
|
|
The wx.HtmlListBox derives from wx.VListBox, but draws each item itself
|
|
|
|
as a wx.HtmlCell. This means that you just need to provide a snippet
|
2003-08-08 17:32:52 -04:00
|
|
|
of HTML for each item when requested.
|
|
|
|
|
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-08-08 17:32:52 -04:00
|
|
|
|