Fix EndEdit to use the newvalue/None as the return value instead of bool and a parameter pass-through.

Add first grid sample.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73502 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2013-02-12 05:12:59 +00:00
parent 31a7a477b3
commit d9f802f384
3 changed files with 83 additions and 23 deletions

View File

@@ -166,7 +166,7 @@ def run():
('BeginEdit', "virtual void BeginEdit(int row, int col, wxGrid* grid);"),
('Clone', "virtual wxGridCellEditor* Clone() const;"),
('Create', "virtual void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler);"),
('EndEdit', "virtual bool EndEdit(int row, int col, const wxGrid* grid, const wxString& oldval, wxString* newval);"),
#('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;"),
@@ -176,7 +176,64 @@ def run():
klass.addItem(etgtools.WigCode(code))
# TODO: Fix up EndEdit so it returns newVal on success or None on failure
# Fix up EndEdit so it returns newval on success or None on failure
pureVirtual = False
if klass.findItem('EndEdit'):
klass.find('EndEdit').ignore()
pureVirtual = True
klass.addCppMethod('PyObject*', 'EndEdit', '(int row, int col, const wxGrid* grid, const wxString& oldval)',
cppSignature='bool (int row, int col, const wxGrid* grid, const wxString& oldval, wxString* newval)',
pyArgsString='(row, col, grid, oldval)',
isVirtual=True,
isPureVirtual=pureVirtual,
doc="""\
End editing the cell.
This function must check if the current value of the editing cell
is valid and different from the original value in its string
form. If not then simply return None. If it has changed then
this method should save the new value so that ApplyEdit can
apply it later and the string representation of the new value
should be returned.
Notice that this method shoiuld not modify the grid as the
change could still be vetoed.
""",
# Code for Python --> C++ calls. Make it return newval or None.
body="""\
bool rv;
wxString newval;
rv = self->EndEdit(row, col, grid, *oldval, &newval);
if (rv) {
return wx2PyString(newval);
}
else {
Py_INCREF(Py_None);
return Py_None;
}
""",
# Code for C++ --> Python calls. This is used when a C++ method
# call needs to be reflected to a call to the overridden Python
# method, so we need to translate between the real C++ siganture
# and the Python signature.
virtualCatcherCode="""\
// VirtualCatcherCode for wx.grid.GridCellEditor.EndEdit
PyObject *result;
result = sipCallMethod(0, sipMethod, "iiDN", row, col,
const_cast<wxGrid *>(grid),sipType_wxGrid,NULL);
if (result == Py_None) {
sipRes = false;
}
else {
sipRes = true;
*newval = Py2wxString(result);
}
Py_DECREF(result);
""" if pureVirtual else "", # only used with the base class
)
c = module.find('wxGridCellEditor')

15
samples/grid/simple.py Normal file
View File

@@ -0,0 +1,15 @@
import wx
import wx.grid
class TestFrame(wx.Frame):
def __init__(self, *args, **kw):
wx.Frame.__init__(self, *args, **kw)
self.grid = wx.grid.Grid(self)
self.grid.CreateGrid(25, 25)
app = wx.App()
frm = TestFrame(None, title="Simple Test Grid")
frm.Show()
app.MainLoop()

View File

@@ -80,31 +80,19 @@ class grid_Tests(wtc.WidgetTestCase):
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 ""
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()