From d9f802f3849a78fdde1f4b48b83f74e36f118e2f Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 12 Feb 2013 05:12:59 +0000 Subject: [PATCH] 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 --- etg/grid.py | 63 ++++++++++++++++++++++++++++++++++++++++-- samples/grid/simple.py | 15 ++++++++++ unittests/test_grid.py | 28 ++++++------------- 3 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 samples/grid/simple.py diff --git a/etg/grid.py b/etg/grid.py index 402652f0..a90156f4 100644 --- a/etg/grid.py +++ b/etg/grid.py @@ -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,9 +176,66 @@ 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(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') c.addPrivateCopyCtor() c.find('~wxGridCellEditor').ignore(False) diff --git a/samples/grid/simple.py b/samples/grid/simple.py new file mode 100644 index 00000000..42db565a --- /dev/null +++ b/samples/grid/simple.py @@ -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() + diff --git a/unittests/test_grid.py b/unittests/test_grid.py index 4b132eae..45ba189f 100644 --- a/unittests/test_grid.py +++ b/unittests/test_grid.py @@ -80,29 +80,17 @@ 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):