Add wx.VListBox

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72352 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2012-08-16 00:45:48 +00:00
parent a546e29c18
commit 7bd1c71395
5 changed files with 196 additions and 1 deletions

View File

@@ -135,7 +135,6 @@ other dev stuff
* valgen (No. It could probably be reimplemented in Python easier than wrapping)
* valnum (No. Ditto)
* valtext (No. Ditto. It works by using a pointer to long-lived wxString object.)
* vlbox
* dialup ??
* docmdi ??
* docview ??

View File

@@ -0,0 +1,6 @@
item, cookie = vlbox.GetFirstSelected()
while item != wx.NOT_FOUND
# ... process item ...
item, cookie = vlbox.GetNextSelected(cookie)

View File

@@ -168,6 +168,7 @@ INCLUDES = [ # base and core stuff
'listbook',
'toolbook',
'treebook',
'vlbox',
# toplevel and dialogs
'nonownedwnd',

61
etg/vlbox.py Normal file
View File

@@ -0,0 +1,61 @@
#---------------------------------------------------------------------------
# Name: etg/vlbox.py
# Author: Robin Dunn
#
# Created: 14-Aug-2012
# Copyright: (c) 2012 by Total Control Software
# License: wxWindows License
#---------------------------------------------------------------------------
import etgtools
import etgtools.tweaker_tools as tools
PACKAGE = "wx"
MODULE = "_core"
NAME = "vlbox" # Base name of the file to generate to for this script
DOCSTRING = ""
# The classes and/or the basename of the Doxygen XML files to be processed by
# this script.
ITEMS = [ "wxVListBox",
]
#---------------------------------------------------------------------------
def run():
# Parse the XML file(s) building a collection of Extractor objects
module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
etgtools.parseDoxyXML(module, ITEMS)
#-----------------------------------------------------------------
# Tweak the parsed meta objects in the module object as needed for
# customizing the generated code and docstrings.
c = module.find('wxVListBox')
assert isinstance(c, etgtools.ClassDef)
tools.fixWindowClass(c)
c.find('GetFirstSelected.cookie').out = True
c.find('GetNextSelected.cookie').inOut = True
for name in ['OnDrawItem', 'OnDrawBackground', 'OnDrawSeparator', 'OnMeasureItem']:
c.find(name).ignore(False)
c.find(name).isVirtual = True
c.find('OnDrawItem').isPureVirtual = True
c.find('OnMeasureItem').isPureVirtual = True
# Let the wrapper generator know that there is an implementation for this
# pure virtual inherited from the base class.
c.addItem(etgtools.WigCode("virtual wxCoord OnGetRowHeight(size_t n) const;",
protection='protected'))
#-----------------------------------------------------------------
tools.doCommonTweaks(module)
tools.runGenerators(module)
#---------------------------------------------------------------------------
if __name__ == '__main__':
run()

128
unittests/test_vlbox.py Normal file
View File

@@ -0,0 +1,128 @@
import imp_unittest, unittest
import wtc
import wx
#---------------------------------------------------------------------------
class vlbox_Tests(wtc.WidgetTestCase):
def test_vlbox1(self):
with self.assertRaises(TypeError):
lb = wx.VListBox()
def test_vlbox2(self):
with self.assertRaises(TypeError):
lb = wx.VListBox(self.frame)
def test_vlbox3(self):
panel = wx.Panel(self.frame)
self.frame.SendSizeEvent()
lb = MyVListBox(panel, pos=(10,10), size=(100,150), style=wx.BORDER_THEME)
lb.data = ['zero', 'one two', 'three four', 'five six', 'seven eight', 'nine ten']
lb.SetItemCount(len(lb.data))
self.myYield()
# check the ItemCount property
self.assertEqual(len(lb.data), lb.ItemCount)
# check that the overridden virtuals were called
self.assertTrue(len(lb.drawItemCalls) > 0)
self.assertTrue(len(lb.drawBackgroundCalls) > 0)
self.assertTrue(len(lb.drawSeparatorCalls) > 0)
self.assertTrue(len(lb.measureItemCalls) > 0)
lb.SetSelection(2)
self.myYield()
self.assertEqual(lb.GetSelectedCount(), 1)
self.assertEqual(lb.GetSelection(), 2)
self.assertTrue(lb.IsSelected(2))
self.assertFalse(lb.IsSelected(3))
def test_vlbox4(self):
panel = wx.Panel(self.frame)
self.frame.SendSizeEvent()
lb = MyVListBox(panel, pos=(10,10), size=(100,150),
style=wx.BORDER_SIMPLE|wx.LB_MULTIPLE)
lb.data = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
lb.SetItemCount(len(lb.data))
self.myYield()
lb.Select(2)
lb.Select(5)
lb.Select(7)
lb.Select(8)
self.myYield()
self.assertTrue(lb.IsSelected(2))
self.assertTrue(lb.IsSelected(8))
self.assertFalse(lb.IsSelected(3))
sel = list()
idx, cookie = lb.GetFirstSelected()
while idx != wx.NOT_FOUND:
sel.append(idx)
idx, cookie = lb.GetNextSelected(cookie)
self.assertEqual(sel, [2,5,7,8])
class MyVListBox(wx.VListBox):
def __init__(self, *args, **kw):
wx.VListBox.__init__(self, *args, **kw)
self.data = list()
self.drawItemCalls = list()
self.drawBackgroundCalls = list()
self.drawSeparatorCalls = list()
self.measureItemCalls = list()
# overridable methods
def OnDrawItem(self, dc, rect, idx):
self.drawItemCalls.append(idx)
assert isinstance(dc, wx.DC)
color = 'black'
if self.IsSelected(idx):
color = 'white'
dc.SetTextForeground(color)
dc.DrawLabel(self.data[idx], rect)
def OnDrawBackground(self, dc, rect, idx):
self.drawBackgroundCalls.append(idx)
assert isinstance(dc, wx.DC)
color = 'white'
if self.IsSelected(idx):
color = self.GetSelectionBackground()
if not color:
color = 'navy'
dc.SetPen(wx.Pen(color, 1))
dc.SetBrush(wx.Brush(color))
dc.DrawRectangle(rect)
def OnDrawSeparator(self, dc, rect, idx):
self.drawSeparatorCalls.append(idx)
if idx == 0:
return
assert isinstance(dc, wx.DC)
dc.SetPen(wx.Pen('#c0c0c0', 1, wx.PENSTYLE_DOT_DASH))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
assert isinstance(rect, wx.Rect)
dc.DrawLine(rect.x, rect.y, rect.right, rect.y)
rect.y += 1
rect.height -= 2
def OnMeasureItem(self, idx):
self.measureItemCalls.append(idx)
#dc = wx.ClientDC(self)
w, h = self.GetTextExtent(self.data[idx])
return h + 6
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()