X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0c8392cac2d36d0d211432e71d3b24d3d93c22db..3628e0888696a4a1d306e621d477a89c43898f05:/wxPython/demo/wxVListBox.py
diff --git a/wxPython/demo/wxVListBox.py b/wxPython/demo/wxVListBox.py
new file mode 100644
index 0000000000..51faff85d9
--- /dev/null
+++ b/wxPython/demo/wxVListBox.py
@@ -0,0 +1,124 @@
+
+from wxPython.wx import *
+
+#----------------------------------------------------------------------
+
+# The wxVListBox is much like a regular wxListBox except you draw the
+# items yourself and the items can vary in height.
+class MyVListBox(wxVListBox):
+
+ # 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):
+ dc.DrawLabel(self._getItemText(n), rect,
+ wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL)
+
+ # This method must be overridden. It should return the height
+ # required to draw the n'th item.
+ def OnMeasureItem(self, n):
+ height = 0
+ for line in self._getItemText(n).split('\n'):
+ w, h = self.GetTextExtent(line)
+ height += h
+ 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
+
+#----------------------------------------------------------------------
+
+# The wxHtmlListBox derives from wxVListBox, but draws each item
+# itself as a wxHtmlCell.
+class MyHtmlListBox(wxHtmlListBox):
+
+ def OnGetItem(self, n):
+ if n % 2 == 0:
+ return "This is item# %d" % n
+ else:
+ return "This is item# %d
Any HTML is okay." % n
+
+#----------------------------------------------------------------------
+
+class TestPanel(wxPanel):
+ def __init__(self, parent, log):
+ self.log = log
+ wxPanel.__init__(self, parent, -1)
+ spacer = 50
+
+ vlb = MyVListBox(self, -1, size=(150, 250), style=wxBORDER_SUNKEN)
+ vlb.SetItemCount(50)
+ vlb.SetSelection(0)
+ vlb.SetFocus()
+ vlbSizer = wxBoxSizer(wxVERTICAL)
+ vlbSizer.Add((spacer, spacer))
+ vlbSizer.Add(wxStaticText(self, -1, "wxVListBox"), 0, 5, wxALL)
+ vlbSizer.Add(vlb)
+
+ hlb = MyHtmlListBox(self, -1, size=(150, 250), style=wxBORDER_SUNKEN)
+ hlb.SetItemCount(50)
+ hlb.SetSelection(0)
+ hlbSizer = wxBoxSizer(wxVERTICAL)
+ hlbSizer.Add((spacer, spacer))
+ hlbSizer.Add(wxStaticText(self, -1, "wxHtmlListBox"), 0, 5, wxALL)
+ hlbSizer.Add(hlb)
+
+ sizer = wxBoxSizer(wxHORIZONTAL)
+ 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 = """
+ +The wxHtmlListBox derives from wxVListBox, but draws each item itself +as a wxHtmlCell. This means that you just need to provide a snippet +of HTML for each item when requested. + + +""" + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) +