diff --git a/demo/GridCustTable.py b/demo/GridCustTable.py index b3082993..c96918f1 100644 --- a/demo/GridCustTable.py +++ b/demo/GridCustTable.py @@ -141,7 +141,7 @@ class TestFrame(wx.Frame): p = wx.Panel(self, -1, style=0) grid = CustTableGrid(p, log) - b = wx.Button(p, -1, "Another Control...") + b = wx.Button(p, -1, "Testing with another control...") b.SetDefault() self.Bind(wx.EVT_BUTTON, self.OnButton, b) b.Bind(wx.EVT_SET_FOCUS, self.OnButtonFocus) diff --git a/etg/grid.py b/etg/grid.py index f698cfc0..9f523991 100644 --- a/etg/grid.py +++ b/etg/grid.py @@ -313,6 +313,82 @@ def run(): module.addPyCode("PyGridTableBase = wx.deprecated(GridTableBase, 'Use GridTableBase instead.')") + # Make the GetValue methods easier to use from Python. For example, + # instead of needing to always return a string, the GetValue in the derived + # class can return any type (as long as the renderer and editor knows how + # to deal with it, and the value can be converted to a string for display). + m = c.find('GetValue') + m.type = 'PyObject*' + m.cppSignature = 'wxString (int row, int col)' + m.setCppCode("return wx2PyString(self->GetValue(row, col));") + m.virtualCatcherCode = """\ + // virtualCatcherCode for GridTableBase.GetValue + PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "ii", row, col); + if (result == Py_None) { + sipRes = ""; + } + else { + if (!PyBytes_Check(result) && !PyUnicode_Check(result)) { + PyObject* old = result; + result = PyObject_Str(result); + Py_DECREF(old); + } + sipRes = Py2wxString(result); + } + Py_XDECREF(result); + """ + + # SetValue is okay as-is... + + + # Replace these virtuals in the base class with Python methods, they just + # need to call GetValue or SetValue directly since they must already be + # implemented in the derived Python class because they are pure virtual. + c.addPyMethod('GetValueAsLong', '(self, row, col)', + body="""\ + val = self.GetValue(row, col) + try: + return int(val) + except ValueError: + return 0 + """, docsIgnored=True) + + c.addPyMethod('GetValueAsDouble', '(self, row, col)', + body="""\ + val = self.GetValue(row, col) + try: + return float(val) + except ValueError: + return 0.0 + """, docsIgnored=True) + + c.addPyMethod('GetValueAsBool', '(self, row, col)', + body="""\ + val = self.GetValue(row, col) + try: + return bool(val) + except ValueError: + return False + """, docsIgnored=True) + + c.addPyMethod('SetValueAsLong', '(self, row, col, value)', + body="self.SetValue(row, col, int(value))", docsIgnored=True) + + c.addPyMethod('SetValueAsDouble', '(self, row, col, value)', + body="self.SetValue(row, col, float(value))", docsIgnored=True) + + c.addPyMethod('SetValueAsBool', '(self, row, col, value)', + body="self.SetValue(row, col, bool(value))", docsIgnored=True) + + + # Should we add support for using generic PyObjects in the *AsCustom + # methods? I don't think it is necessary due to the GetValue + # modifications above, so for now, at least, let.s just ignore them. + c.find('GetValueAsCustom').ignore() + c.find('SetValueAsCustom').ignore() + + + #----------------------------------------------------------------- c = module.find('wxGridTableMessage') c.addPrivateCopyCtor() diff --git a/wx/tools/img2py.py b/wx/tools/img2py.py index 8c301634..aba32ffa 100644 --- a/wx/tools/img2py.py +++ b/wx/tools/img2py.py @@ -56,7 +56,7 @@ Options: -n Normally generic names (getBitmap, etc.) are used for the image access functions. If you use this option you can specify a name that should be used to customize the access - fucntions, (getNameBitmap, etc.) + functions, (getNameBitmap, etc.) -c Maintain a catalog of names that can be used to reference images. Catalog can be accessed via catalog and @@ -73,7 +73,7 @@ Options: -i Also output a function to return the image as a wxIcon. -f Generate code compatible with the old function interface. - (This option is ON by default in 2.8, use -F to turn off.) + (This option is ON by default in 2.8, use -f to turn off.) You can also import this module from your Python scripts, and use its img2py() function. See its docstring for more info.