More tweaks and unittests for the wx.grid classes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73501 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2013-02-12 05:12:48 +00:00
parent bbe768fcdc
commit 31a7a477b3
2 changed files with 432 additions and 35 deletions

View File

@@ -49,6 +49,8 @@ ITEMS = [ 'wxGridCellCoords',
'wxGridCellAttrProvider',
'wxGridTableBase',
'wxGridTableMessage',
'wxGridStringTable',
'wxGridSizesInfo',
'wxGrid',
@@ -72,6 +74,20 @@ def run():
# Tweak the parsed meta objects in the module object as needed for
# customizing the generated code and docstrings.
module.addGlobalStr('wxGridNameStr', module.items[0])
module.addPyCode("""\
GRID_VALUE_STRING = "string"
GRID_VALUE_BOOL = "bool"
GRID_VALUE_NUMBER = "long"
GRID_VALUE_FLOAT = "double"
GRID_VALUE_CHOICE = "choice"
GRID_VALUE_TEXT = "string"
GRID_VALUE_LONG = "long"
GRID_VALUE_CHOICEINT = "choiceint"
GRID_VALUE_DATETIME = "datetime"
""")
#-----------------------------------------------------------------
c = module.find('wxGridCellCoords')
assert isinstance(c, etgtools.ClassDef)
tools.addAutoProperties(c)
@@ -106,30 +122,9 @@ def run():
tools.wxArrayWrapperTemplate('wxGridCellCoordsArray', 'wxGridCellCoords', module))
#-----------------------------------------------------------------
c = module.find('wxGridCellAttrProvider')
c.addPrivateCopyCtor()
#-----------------------------------------------------------------
c = module.find('wxGrid')
tools.fixWindowClass(c)
c.bases = ['wxScrolledWindow']
#-----------------------------------------------------------------
c = module.find('wxGridSizesInfo')
c.find('m_customSizes').ignore() # TODO: Add support for wxUnsignedToIntHashMap??
#-----------------------------------------------------------------
for name in ['wxGridEvent',
'wxGridSizeEvent',
'wxGridRangeSelectEvent',
'wxGridEditorCreatedEvent',
]:
c = module.find(name)
tools.fixEventClass(c)
#-----------------------------------------------------------------
@@ -158,7 +153,9 @@ def run():
if 'Cell' in name and 'Renderer' in name:
fixRendererClass(name)
module.addPyCode("PyGridCellRenderer = wx.deprecated(GridCellRenderer, 'Use GridCellRenderer instead.')")
#-----------------------------------------------------------------
def fixEditorClass(name):
klass = module.find(name)
@@ -172,9 +169,16 @@ def run():
('EndEdit', "virtual bool EndEdit(int row, int col, const wxGrid* grid, const wxString& oldval, wxString* newval);"),
('ApplyEdit', "virtual void ApplyEdit(int row, int col, wxGrid* grid);"),
('Reset', "virtual void Reset();"),
('GetValue', "virtual wxString GetValue() const;"),
]
for method, code in methods:
if not klass.findItem(method):
klass.addItem(etgtools.WigCode(code))
# TODO: Fix up EndEdit so it returns newVal on success or None on failure
c = module.find('wxGridCellEditor')
c.addPrivateCopyCtor()
c.find('~wxGridCellEditor').ignore(False)
@@ -186,24 +190,20 @@ def run():
if 'Cell' in name and 'Editor' in name:
fixEditorClass(name)
module.addPyCode("PyGridCellEditor = wx.deprecated(GridCellEditor, 'Use GridCellEditor instead.')")
#-----------------------------------------------------------------
c = module.find('wxGridCellAttr')
c.addPrivateCopyCtor()
c.find('~wxGridCellAttr').ignore(False)
#-----------------------------------------------------------------
c = module.find('wxGridUpdateLocker')
c.addPrivateCopyCtor()
#-----------------------------------------------------------------
c = module.find('wxGridTableBase')
c.addPrivateCopyCtor()
c.find('GetAlignment.hAlign').out = True
c.find('GetAlignment.vAlign').out = True
c.find('GetNonDefaultAlignment.hAlign').out = True
c.find('GetNonDefaultAlignment.vAlign').out = True
#-----------------------------------------------------------------
# The insanceCode attribute is code that is used to make a default
# instance of the class. We can't create them using the same class in
@@ -219,7 +219,129 @@ def run():
c.instanceCode = 'sipCpp = new wxGridColumnHeaderRendererDefault;'
#-----------------------------------------------------------------
c = module.find('wxGridCellAttrProvider')
c.addPrivateCopyCtor()
c.find('SetAttr.attr').transfer = True
c.find('SetRowAttr.attr').transfer = True
c.find('SetColAttr.attr').transfer = True
module.addPyCode("PyGridCellAttrProvider = wx.deprecated(GridCellAttrProvider, 'Use GridCellAttrProvider instead.')")
#-----------------------------------------------------------------
c = module.find('wxGridTableBase')
c.addPrivateCopyCtor()
c.find('SetAttr.attr').transfer = True
c.find('SetRowAttr.attr').transfer = True
c.find('SetColAttr.attr').transfer = True
module.addPyCode("PyGridTableBase = wx.deprecated(GridTableBase, 'Use GridTableBase instead.')")
#-----------------------------------------------------------------
c = module.find('wxGridTableMessage')
c.addPrivateCopyCtor()
#-----------------------------------------------------------------
c = module.find('wxGrid')
tools.fixWindowClass(c, ignoreProtected=False)
c.bases = ['wxScrolledWindow']
c.find('GetColLabelAlignment.horiz').out = True
c.find('GetColLabelAlignment.vert').out = True
c.find('GetRowLabelAlignment.horiz').out = True
c.find('GetRowLabelAlignment.vert').out = True
c.find('GetCellAlignment.horiz').out = True
c.find('GetCellAlignment.vert').out = True
c.find('GetDefaultCellAlignment.horiz').out = True
c.find('GetDefaultCellAlignment.vert').out = True
c.find('RegisterDataType.renderer').transfer = True
c.find('RegisterDataType.editor').transfer = True
c.find('SetCellEditor.editor').transfer = True
c.find('SetCellRenderer.renderer').transfer = True
# This overload is deprecated, so don't generate code for it.
c.find('SetCellValue').findOverload('wxString &val').ignore()
c.find('SetDefaultEditor.editor').transfer = True
c.find('SetDefaultRenderer.renderer').transfer = True
#-----------------------------------------------------------------
c = module.find('wxGridUpdateLocker')
c.addPrivateCopyCtor()
# context manager methods
c.addPyMethod('__enter__', '(self)', 'return self')
c.addPyMethod('__exit__', '(self, exc_type, exc_val, exc_tb)', 'return False')
#-----------------------------------------------------------------
for name in ['wxGridSizeEvent',
'wxGridRangeSelectEvent',
'wxGridEditorCreatedEvent',
'wxGridEvent'
]:
c = module.find(name)
tools.fixEventClass(c)
c.addPyCode("""\
EVT_GRID_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK )
EVT_GRID_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK )
EVT_GRID_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK )
EVT_GRID_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK )
EVT_GRID_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK )
EVT_GRID_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK )
EVT_GRID_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK )
EVT_GRID_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK )
EVT_GRID_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE )
EVT_GRID_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE )
EVT_GRID_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT )
EVT_GRID_CELL_CHANGING = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGING )
EVT_GRID_CELL_CHANGED = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGED )
EVT_GRID_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL )
EVT_GRID_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN )
EVT_GRID_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN )
EVT_GRID_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED )
EVT_GRID_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG )
EVT_GRID_COL_MOVE = wx.PyEventBinder( wxEVT_GRID_COL_MOVE )
EVT_GRID_COL_SORT = wx.PyEventBinder( wxEVT_GRID_COL_SORT )
EVT_GRID_TABBING = wx.PyEventBinder( wxEVT_GRID_TABBING )
# The same as above but with the ability to specify an identifier
EVT_GRID_CMD_CELL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_CLICK, 1 )
EVT_GRID_CMD_CELL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_CLICK, 1 )
EVT_GRID_CMD_CELL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_LEFT_DCLICK, 1 )
EVT_GRID_CMD_CELL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_CELL_RIGHT_DCLICK, 1 )
EVT_GRID_CMD_LABEL_LEFT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_CLICK, 1 )
EVT_GRID_CMD_LABEL_RIGHT_CLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_CLICK, 1 )
EVT_GRID_CMD_LABEL_LEFT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_LEFT_DCLICK, 1 )
EVT_GRID_CMD_LABEL_RIGHT_DCLICK = wx.PyEventBinder( wxEVT_GRID_LABEL_RIGHT_DCLICK, 1 )
EVT_GRID_CMD_ROW_SIZE = wx.PyEventBinder( wxEVT_GRID_ROW_SIZE, 1 )
EVT_GRID_CMD_COL_SIZE = wx.PyEventBinder( wxEVT_GRID_COL_SIZE, 1 )
EVT_GRID_CMD_RANGE_SELECT = wx.PyEventBinder( wxEVT_GRID_RANGE_SELECT, 1 )
EVT_GRID_CMD_CELL_CHANGING = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGING, 1 )
EVT_GRID_CMD_CELL_CHANGED = wx.PyEventBinder( wxEVT_GRID_CELL_CHANGED, 1 )
EVT_GRID_CMD_SELECT_CELL = wx.PyEventBinder( wxEVT_GRID_SELECT_CELL, 1 )
EVT_GRID_CMD_EDITOR_SHOWN = wx.PyEventBinder( wxEVT_GRID_EDITOR_SHOWN, 1 )
EVT_GRID_CMD_EDITOR_HIDDEN = wx.PyEventBinder( wxEVT_GRID_EDITOR_HIDDEN, 1 )
EVT_GRID_CMD_EDITOR_CREATED = wx.PyEventBinder( wxEVT_GRID_EDITOR_CREATED, 1 )
EVT_GRID_CMD_CELL_BEGIN_DRAG = wx.PyEventBinder( wxEVT_GRID_CELL_BEGIN_DRAG, 1 )
EVT_GRID_CMD_COL_MOVE = wx.PyEventBinder( wxEVT_GRID_COL_MOVE, 1 )
EVT_GRID_CMD_COL_SORT = wx.PyEventBinder( wxEVT_GRID_COL_SORT, 1 )
EVT_GRID_CMD_TABBING = wx.PyEventBinder( wxEVT_GRID_TABBING, 1 )
""")
#-----------------------------------------------------------------
#-----------------------------------------------------------------
tools.doCommonTweaks(module)

View File

@@ -1,15 +1,290 @@
import imp_unittest, unittest
import wtc
import wx
import wx.grid
#---------------------------------------------------------------------------
class grid_Tests(wtc.WidgetTestCase):
# TODO: Remove this test and add real ones.
def test_grid1(self):
self.fail("Unit tests for grid not implemented yet.")
# NOTE: Most of these tests simply check that the class exists and can be
# instantiated. It would be nice to add more here, but in the meantime it
# will probably be easier to test features and interoperability between
# the classes in a non-unitest situation. See Phoenix/samples/grid
def test_grid01(self):
c1 = wx.grid.GridCellCoords()
c2 = wx.grid.GridCellCoords(5,10)
def test_grid02(self):
r = wx.grid.GridCellAutoWrapStringRenderer()
def test_grid03(self):
r = wx.grid.GridCellBoolRenderer()
def test_grid04(self):
r = wx.grid.GridCellDateTimeRenderer()
def test_grid05(self):
r = wx.grid.GridCellEnumRenderer()
def test_grid06(self):
r = wx.grid.GridCellFloatRenderer()
def test_grid07(self):
r = wx.grid.GridCellNumberRenderer()
def test_grid08(self):
r = wx.grid.GridCellStringRenderer()
def test_grid09(self):
class MyRenderer(wx.grid.GridCellRenderer):
def Clone(self):
return MyRenderer()
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
pass
def GetBestSize(self, grid, attr, dc, row, col):
return (80,20)
r = MyRenderer()
def test_grid10(self):
e = wx.grid.GridCellAutoWrapStringEditor()
def test_grid11(self):
e = wx.grid.GridCellBoolEditor()
def test_grid12(self):
e = wx.grid.GridCellChoiceEditor('one two three'.split())
def test_grid13(self):
e = wx.grid.GridCellEnumEditor()
def test_grid14(self):
e = wx.grid.GridCellTextEditor()
def test_grid15(self):
e = wx.grid.GridCellFloatEditor()
def test_grid16(self):
e = wx.grid.GridCellNumberEditor()
def test_grid17(self):
class MyEditor(wx.grid.GridCellEditor):
def Clone(self):
return MyEditor()
def BeginEdit(self, row, col, grid):
pass
def Create(self, parent, id, evtHandler):
pass
def EndEdit(self, row, col, grid, oldval):
return None
def ApplyEdit(self, row, col, grid):
pass
def Reset(self):
pass
def GetValue(self):
return ""
e = MyEditor()
def test_grid18(self):
a = wx.grid.GridCellAttr()
a.DecRef()
def test_grid19(self):
wx.grid.GridCellAttr.Any
wx.grid.GridCellAttr.Cell
wx.grid.GridCellAttr.Row
wx.grid.GridCellAttr.Col
def test_grid20(self):
class MyRenderer(wx.grid.GridCornerHeaderRenderer):
def DrawBorder(self, grid, dc, rect):
pass
r = MyRenderer()
def test_grid21(self):
class MyRenderer(wx.grid.GridHeaderLabelsRenderer):
def DrawBorder(self, grid, dc, rect):
pass
def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
pass
r = MyRenderer()
def test_grid22(self):
class MyRenderer(wx.grid.GridRowHeaderRenderer):
def DrawBorder(self, grid, dc, rect):
pass
def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
pass
r = MyRenderer()
def test_grid23(self):
class MyRenderer(wx.grid.GridColumnHeaderRenderer):
def DrawBorder(self, grid, dc, rect):
pass
def DrawLabel(self, grid, dc, value, rect, horizAlign, vertAlign, textOrientation):
pass
r = MyRenderer()
def test_grid24(self):
r = wx.grid.GridRowHeaderRendererDefault()
def test_grid25(self):
r = wx.grid.GridColumnHeaderRendererDefault()
def test_grid26(self):
r = wx.grid.GridCornerHeaderRendererDefault()
def test_grid27(self):
p = wx.grid.GridCellAttrProvider()
def test_grid28(self):
class MyTable(wx.grid.GridTableBase):
def GetNumberRows(self): return 1
def GetNumberCols(self): return 1
def GetValue(self, row, col): return ""
def SetValue(self, row, col, value): pass
t = MyTable()
def test_grid29(self):
t = wx.grid.GridStringTable()
def test_grid30(self):
m = wx.grid.GridTableMessage()
def test_grid31(self):
m = wx.grid.GridSizesInfo()
def test_grid32(self):
g = wx.grid.Grid(self.frame)
g.CreateGrid(10,5)
def test_grid33(self):
g = wx.grid.Grid(self.frame)
g.CreateGrid(10,5)
ul = wx.grid.GridUpdateLocker(g)
g.SetCellValue(1,2, 'hello')
g.SetCellValue((2,2), 'world')
del ul
def test_grid34(self):
g = wx.grid.Grid(self.frame)
g.CreateGrid(10,5)
with wx.grid.GridUpdateLocker(g):
g.SetCellValue(1,2, 'hello')
g.SetCellValue((2,2), 'world')
def test_grid35(self):
e = wx.grid.GridEvent()
def test_grid36(self):
e = wx.grid.GridSizeEvent()
def test_grid37(self):
e = wx.grid.GridRangeSelectEvent()
def test_grid38(self):
e = wx.grid.GridEditorCreatedEvent()
def test_grid39(self):
wx.grid.wxEVT_GRID_CELL_LEFT_CLICK
wx.grid.wxEVT_GRID_CELL_RIGHT_CLICK
wx.grid.wxEVT_GRID_CELL_LEFT_DCLICK
wx.grid.wxEVT_GRID_CELL_RIGHT_DCLICK
wx.grid.wxEVT_GRID_LABEL_LEFT_CLICK
wx.grid.wxEVT_GRID_LABEL_RIGHT_CLICK
wx.grid.wxEVT_GRID_LABEL_LEFT_DCLICK
wx.grid.wxEVT_GRID_LABEL_RIGHT_DCLICK
wx.grid.wxEVT_GRID_ROW_SIZE
wx.grid.wxEVT_GRID_COL_SIZE
wx.grid.wxEVT_GRID_RANGE_SELECT
wx.grid.wxEVT_GRID_CELL_CHANGING
wx.grid.wxEVT_GRID_CELL_CHANGED
wx.grid.wxEVT_GRID_SELECT_CELL
wx.grid.wxEVT_GRID_EDITOR_SHOWN
wx.grid.wxEVT_GRID_EDITOR_HIDDEN
wx.grid.wxEVT_GRID_EDITOR_CREATED
wx.grid.wxEVT_GRID_CELL_BEGIN_DRAG
wx.grid.wxEVT_GRID_COL_MOVE
wx.grid.wxEVT_GRID_COL_SORT
wx.grid.wxEVT_GRID_TABBING
def test_grid40(self):
wx.grid.EVT_GRID_CELL_LEFT_CLICK
wx.grid.EVT_GRID_CELL_RIGHT_CLICK
wx.grid.EVT_GRID_CELL_LEFT_DCLICK
wx.grid.EVT_GRID_CELL_RIGHT_DCLICK
wx.grid.EVT_GRID_LABEL_LEFT_CLICK
wx.grid.EVT_GRID_LABEL_RIGHT_CLICK
wx.grid.EVT_GRID_LABEL_LEFT_DCLICK
wx.grid.EVT_GRID_LABEL_RIGHT_DCLICK
wx.grid.EVT_GRID_ROW_SIZE
wx.grid.EVT_GRID_COL_SIZE
wx.grid.EVT_GRID_RANGE_SELECT
wx.grid.EVT_GRID_CELL_CHANGING
wx.grid.EVT_GRID_CELL_CHANGED
wx.grid.EVT_GRID_SELECT_CELL
wx.grid.EVT_GRID_EDITOR_SHOWN
wx.grid.EVT_GRID_EDITOR_HIDDEN
wx.grid.EVT_GRID_EDITOR_CREATED
wx.grid.EVT_GRID_CELL_BEGIN_DRAG
wx.grid.EVT_GRID_COL_MOVE
wx.grid.EVT_GRID_COL_SORT
wx.grid.EVT_GRID_TABBING
wx.grid.EVT_GRID_CMD_CELL_LEFT_CLICK
wx.grid.EVT_GRID_CMD_CELL_RIGHT_CLICK
wx.grid.EVT_GRID_CMD_CELL_LEFT_DCLICK
wx.grid.EVT_GRID_CMD_CELL_RIGHT_DCLICK
wx.grid.EVT_GRID_CMD_LABEL_LEFT_CLICK
wx.grid.EVT_GRID_CMD_LABEL_RIGHT_CLICK
wx.grid.EVT_GRID_CMD_LABEL_LEFT_DCLICK
wx.grid.EVT_GRID_CMD_LABEL_RIGHT_DCLICK
wx.grid.EVT_GRID_CMD_ROW_SIZE
wx.grid.EVT_GRID_CMD_COL_SIZE
wx.grid.EVT_GRID_CMD_RANGE_SELECT
wx.grid.EVT_GRID_CMD_CELL_CHANGING
wx.grid.EVT_GRID_CMD_CELL_CHANGED
wx.grid.EVT_GRID_CMD_SELECT_CELL
wx.grid.EVT_GRID_CMD_EDITOR_SHOWN
wx.grid.EVT_GRID_CMD_EDITOR_HIDDEN
wx.grid.EVT_GRID_CMD_EDITOR_CREATED
wx.grid.EVT_GRID_CMD_CELL_BEGIN_DRAG
wx.grid.EVT_GRID_CMD_COL_MOVE
wx.grid.EVT_GRID_CMD_COL_SORT
wx.grid.EVT_GRID_CMD_TABBING
#---------------------------------------------------------------------------
if __name__ == '__main__':