Added wrappers for the wx.grid.GridBlockCoords, wx.grid.GridBlocks, and wx.grid.GridBlockDiffResult classes

This commit is contained in:
Robin Dunn
2020-04-17 16:35:37 -07:00
parent 4784eec157
commit e1b0435f8e
3 changed files with 118 additions and 0 deletions

View File

@@ -1434,6 +1434,9 @@
"GraphicsRenderer":"wx.",
"Grid":"wx.grid.",
"GridBagSizer":"wx.",
"GridBlockCoords":"wx.grid.",
"GridBlockDiffResult":"wx.grid.",
"GridBlocks":"wx.grid.",
"GridCellAttr":"wx.grid.",
"GridCellAttrProvider":"wx.grid.",
"GridCellAttrPtr":"wx.grid.",
@@ -7003,6 +7006,7 @@
"__DECLARE_EVT2":"wx.",
"byte":"wx.",
"date2pydate":"wx.",
"iterator":"wx.grid.GridBlocks.",
"operator!=":"wx.",
"operator*":"wx.",
"operator+":"wx.",

View File

@@ -19,6 +19,10 @@ DOCSTRING = ""
# this script.
ITEMS = [ 'wxGridCellCoords',
'wxGridBlockCoords',
'wxGridBlockDiffResult',
'wxGridBlocks',
'wxGridCellRenderer',
'wxGridCellStringRenderer',
'wxGridCellAutoWrapStringRenderer',
@@ -133,6 +137,101 @@ def run():
getItemCopy=True))
#-----------------------------------------------------------------
c = module.find('wxGridBlockCoords')
tools.addAutoProperties(c)
c.find('operator!').ignore()
c.addCppMethod('int', '__bool__', '()', "return self->operator!();")
c.addCppMethod('PyObject*', 'Get', '()', """\
wxPyThreadBlocker blocker;
return sipBuildResult(0, "(iiii)", self->GetTopRow(), self->GetLeftCol(), self->GetBottomRow(), self->GetRightCol());
""",
pyArgsString="() -> (topRow, leftCol, bottomRow, rightCol)",
briefDoc="Return the block coordinants as a tuple.")
c.addPyMethod('__str__', '(self)', 'return str(self.Get())')
c.addPyMethod('__repr__', '(self)', 'return "GridBlockCoords"+str(self.Get())')
#-----------------------------------------------------------------
c = module.find('wxGridBlockDiffResult')
c.find('m_parts').ignore()
c.addCppMethod('PyObject*', '_getParts', '()',
"""\
wxPyThreadBlocker blocker;
PyObject* ret = PyTuple_New(4);
if (ret) {
PyTuple_SET_ITEM(ret, 0, wxPyConstructObject(&self->m_parts[0], "wxGridBlockCoords", false));
PyTuple_SET_ITEM(ret, 1, wxPyConstructObject(&self->m_parts[1], "wxGridBlockCoords", false));
PyTuple_SET_ITEM(ret, 2, wxPyConstructObject(&self->m_parts[2], "wxGridBlockCoords", false));
PyTuple_SET_ITEM(ret, 3, wxPyConstructObject(&self->m_parts[3], "wxGridBlockCoords", false));
}
return ret;
""")
c.addProperty('m_parts', '_getParts')
#-----------------------------------------------------------------
c = module.find('wxGridBlocks')
c.addPrivateDefaultCtor()
c.addPyMethod('__iter__', '(self)',
'return PyGridBlocksIterator(self)',
"Returns a Python iterator for acessing the collection of grid blocks.")
# This class is the Python iterator that knows how to fetch blocks from the
# wxGridBlocks object
c.addPyCode("""\
class PyGridBlocksIterator(object):
"A Python iterator for GridBlocks objects"
def __init__(self, blocks):
self._blocks = blocks
self._iterator = self._blocks.begin()
def __next__(self):
if self._iterator == self._blocks.end():
raise StopIteration
obj = self._iterator._get()
self._iterator = self._iterator._next()
return obj
""")
# c.find('iterator').addCppMethod('wxGridBlocks::iterator', '_next', '()',
# "return self->operator++();")
# c.find('iterator').addCppMethod('const wxGridBlockCoords&', '_get', '()',
# "return self->operator*();")
# TODO: Doing these the normal way (above) breaks because it tries to use just
# "iterator" for the self param type, instead of wxGridBlocks::iterator.
# That should be fixable, but until then just add these methods the manual
# sip way.
c.find('iterator').addItem(etgtools.WigCode("""\
iterator& _next();
%MethodCode
PyErr_Clear();
Py_BEGIN_ALLOW_THREADS
sipRes = &sipCpp->operator++();
Py_END_ALLOW_THREADS
if (PyErr_Occurred()) return 0;
%End
const wxGridBlockCoords& _get() const;
%MethodCode
PyErr_Clear();
Py_BEGIN_ALLOW_THREADS
sipRes = new ::wxGridBlockCoords(sipCpp->operator*());
Py_END_ALLOW_THREADS
if (PyErr_Occurred()) return 0;
%End
bool __eq__(const iterator& it) const;
bool __ne__(const iterator& it) const;
"""))
#-----------------------------------------------------------------
c = module.find('wxGridSizesInfo')
c.find('m_customSizes').ignore() # TODO: Add support for wxUnsignedToIntHashMap??

View File

@@ -355,6 +355,21 @@ class grid_Tests(wtc.WidgetTestCase):
assert tl.Get() == (1,1)
assert br.Get() == (5,5)
def test_grid46(self):
g = wx.grid.Grid(self.frame)
g.CreateGrid(10,10)
g.SelectBlock((1,1), (5,5))
g.SelectBlock((6,5), (7,9), addToSelected=True)
blocks = g.GetSelectedBlocks()
assert isinstance(blocks, wx.grid.GridBlocks)
count = 0
for block in blocks:
count += 1
assert isinstance(block, wx.grid.GridBlockCoords)
assert count == 2
#---------------------------------------------------------------------------