Instead of passing sipIsErr into custom functions made for CppMethodDefs and etc. just check PyErr_Occurred after the function returns and then set sipIsErr there.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@69400 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2011-10-13 04:58:46 +00:00
parent d1bdbd0155
commit a87c196def
7 changed files with 26 additions and 30 deletions

View File

@@ -50,7 +50,6 @@ def run():
self->SetColour(wxColour(wxMacCreateCGColorFromHITheme(macThemeBrushID))); self->SetColour(wxColour(wxMacCreateCGColorFromHITheme(macThemeBrushID)));
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
_isErr = 1;
#endif #endif
""") """)

View File

@@ -42,7 +42,6 @@ def run():
return new wxColour(wxMacCreateCGColorFromHITheme(themeBrushID)); return new wxColour(wxMacCreateCGColorFromHITheme(themeBrushID));
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
_isErr = 1;
return NULL; return NULL;
#endif #endif
""", factory=True) """, factory=True)
@@ -148,9 +147,9 @@ def run():
alpha = self->Alpha(); alpha = self->Alpha();
} }
if (includeAlpha) if (includeAlpha)
return sipBuildResult(&_isErr, "(iiii)", red, green, blue, alpha); return sipBuildResult(0, "(iiii)", red, green, blue, alpha);
else else
return sipBuildResult(&_isErr, "(iii)", red, green, blue); return sipBuildResult(0, "(iii)", red, green, blue);
""", briefDoc="""\ """, briefDoc="""\
Get(includeAlpha=False) -> (r,g,b) or (r,g,b,a)\n Get(includeAlpha=False) -> (r,g,b) or (r,g,b,a)\n
Returns the RGB intensity values as a tuple, optionally the alpha value as well.""") Returns the RGB intensity values as a tuple, optionally the alpha value as well.""")

View File

@@ -156,7 +156,6 @@ def run():
return (long)((wxMSWDCImpl*)self->GetImpl())->GetHDC(); return (long)((wxMSWDCImpl*)self->GetImpl())->GetHDC();
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
_isErr = 1;
return 0; return 0;
#endif""") #endif""")
c.addCppMethod('void*', 'GetCGContext', '()', """\ c.addCppMethod('void*', 'GetCGContext', '()', """\
@@ -169,7 +168,6 @@ def run():
return cgctx; return cgctx;
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
_isErr = 1;
return NULL; return NULL;
#endif""") #endif""")
c.addCppMethod('void*', 'GetGdkDrawable', '()', """\ c.addCppMethod('void*', 'GetGdkDrawable', '()', """\
@@ -180,7 +178,6 @@ def run():
return ((wxGTKDCImpl*)self->GetImpl())->GetGDKWindow(); return ((wxGTKDCImpl*)self->GetImpl())->GetGDKWindow();
#else #else
wxPyRaiseNotImplemented(); wxPyRaiseNotImplemented();
_isErr = 1;
return NULL; return NULL;
#endif""") #endif""")

View File

@@ -128,7 +128,6 @@ def run():
&wxPyCallback::EventThunker); &wxPyCallback::EventThunker);
} }
else { else {
_isErr = 1;
PyErr_SetString(PyExc_TypeError, "Expected callable object or None."); PyErr_SetString(PyExc_TypeError, "Expected callable object or None.");
} }
""") """)
@@ -354,7 +353,6 @@ def run():
if (!list) { if (!list) {
PyErr_SetString(PyExc_MemoryError, "Can't allocate list of files!"); PyErr_SetString(PyExc_MemoryError, "Can't allocate list of files!");
wxPyEndBlockThreads(blocked); wxPyEndBlockThreads(blocked);
_isErr = 1;
return NULL; return NULL;
} }
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {

View File

@@ -103,7 +103,7 @@ def run():
c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxPoint') c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxPoint')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(ii)", self->x, self->y); return sipBuildResult(0, "(ii)", self->x, self->y);
""", briefDoc="""\ """, briefDoc="""\
Get() -> (x,y)\n Get() -> (x,y)\n
Return the x and y properties as a tuple.""") Return the x and y properties as a tuple.""")
@@ -161,7 +161,7 @@ def run():
c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxSize') c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxSize')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(ii)", self->GetWidth(), self->GetHeight()); return sipBuildResult(0, "(ii)", self->GetWidth(), self->GetHeight());
""", briefDoc="""\ """, briefDoc="""\
Get() -> (width, height)\n Get() -> (width, height)\n
Return the width and height properties as a tuple.""") Return the width and height properties as a tuple.""")
@@ -233,7 +233,7 @@ def run():
c.convertFromPyObject = tools.convertFourIntegersTemplate('wxRect') c.convertFromPyObject = tools.convertFourIntegersTemplate('wxRect')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(iiii)", return sipBuildResult(0, "(iiii)",
self->x, self->y, self->width, self->height); self->x, self->y, self->width, self->height);
""", briefDoc="""\ """, briefDoc="""\
Get() -> (x, y, width, height)\n Get() -> (x, y, width, height)\n
@@ -282,7 +282,7 @@ def run():
c.convertFromPyObject = tools.convertTwoDoublesTemplate('wxRealPoint') c.convertFromPyObject = tools.convertTwoDoublesTemplate('wxRealPoint')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(dd)", self->x, self->y); return sipBuildResult(0, "(dd)", self->x, self->y);
""", briefDoc="""\ """, briefDoc="""\
Get() -> (x, y, width, height)\n Get() -> (x, y, width, height)\n
Return the rectangle's properties as a tuple.""") Return the rectangle's properties as a tuple.""")

View File

@@ -60,8 +60,9 @@ def run():
c.convertFromPyObject = tools.convertTwoDoublesTemplate('wxPoint2DDouble') c.convertFromPyObject = tools.convertTwoDoublesTemplate('wxPoint2DDouble')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(dd)", self->m_x, self->m_y); return sipBuildResult(0, "(dd)", self->m_x, self->m_y);
""", briefDoc="""\ """,
briefDoc="""\
Get() -> (x,y)\n Get() -> (x,y)\n
Return the x and y properties as a tuple.""") Return the x and y properties as a tuple.""")
@@ -103,9 +104,10 @@ def run():
c.convertFromPyObject = tools.convertFourDoublesTemplate('wxRect2DDouble') c.convertFromPyObject = tools.convertFourDoublesTemplate('wxRect2DDouble')
c.addCppMethod('PyObject*', 'Get', '()', """\ c.addCppMethod('PyObject*', 'Get', '()', """\
return sipBuildResult(&_isErr, "(dddd)", return sipBuildResult(0, "(dddd)",
self->m_x, self->m_y, self->m_width, self->m_height); self->m_x, self->m_y, self->m_width, self->m_height);
""", briefDoc="""\ """,
briefDoc="""\
Get() -> (x, y, width, height)\n Get() -> (x, y, width, height)\n
Return the rectangle's properties as a tuple.""") Return the rectangle's properties as a tuple.""")

View File

@@ -520,8 +520,6 @@ from %s import *
name = re.split(r'[ \*\&]+', name)[-1] name = re.split(r'[ \*\&]+', name)[-1]
pnames[idx] = name pnames[idx] = name
pnames = ', '.join(pnames) pnames = ', '.join(pnames)
if pnames:
pnames = ', ' + pnames
typ = method.type typ = method.type
if not skipDeclaration: if not skipDeclaration:
@@ -553,11 +551,9 @@ from %s import *
arg = arg.replace('&', '*') # SIP will always want to use pointers for parameters arg = arg.replace('&', '*') # SIP will always want to use pointers for parameters
fargs[idx] = arg fargs[idx] = arg
fargs = ', '.join(fargs) fargs = ', '.join(fargs)
if fargs:
fargs = ', ' + fargs
if method.isCtor: if method.isCtor:
fname = '_%s_newCtor' % klass.name fname = '_%s_newCtor' % klass.name
fargs = '(int& _isErr%s)' % fargs fargs = '(%s)' % fargs
fstream.write('%s%%TypeCode\n' % indent) fstream.write('%s%%TypeCode\n' % indent)
typ = klass.name typ = klass.name
if method.useDerivedName: if method.useDerivedName:
@@ -574,13 +570,15 @@ from %s import *
if method.isStatic: if method.isStatic:
# If the method is static then there is no sipCpp to send to # If the method is static then there is no sipCpp to send to
# the new function, so it should not have a self parameter. # the new function, so it should not have a self parameter.
fargs = '(int& _isErr%s)' % fargs fargs = '(%s)' % fargs
else: else:
fargs = '(%s* self, int& _isErr%s)' % (klass.name, fargs) if fargs:
fargs = ', ' + fargs
fargs = '(%s* self%s)' % (klass.name, fargs)
fstream.write('%s%%TypeCode\n' % indent) fstream.write('%s%%TypeCode\n' % indent)
else: else:
fname = '_%s_function' % method.name fname = '_%s_function' % method.name
fargs = '(int& _isErr%s)' % fargs fargs = '(%s)' % fargs
fstream.write('%s%%ModuleCode\n' % indent) fstream.write('%s%%ModuleCode\n' % indent)
# If the return type is in the forcePtrTypes list then make sure # If the return type is in the forcePtrTypes list then make sure
@@ -603,7 +601,7 @@ from %s import *
stream.write('%s%%MethodCode\n' % indent) stream.write('%s%%MethodCode\n' % indent)
stream.write(indent+' '*4) stream.write(indent+' '*4)
if method.isCtor: if method.isCtor:
stream.write('sipCpp = %s(sipIsErr%s);\n' % (fname, pnames)) stream.write('sipCpp = %s(%s);\n' % (fname, pnames))
else: else:
if method.type != 'void': if method.type != 'void':
stream.write('sipRes = ') stream.write('sipRes = ')
@@ -611,11 +609,15 @@ from %s import *
if method.isStatic: if method.isStatic:
# If the method is static then there is no sipCpp to send to # If the method is static then there is no sipCpp to send to
# the new function, so it should not have a self parameter. # the new function, so it should not have a self parameter.
stream.write('%s(sipIsErr%s);\n' % (fname, pnames)) stream.write('%s(%s);\n' % (fname, pnames))
else: else:
stream.write('%s(sipCpp, sipIsErr%s);\n' % (fname, pnames)) if pnames:
pnames = ', ' + pnames
stream.write('%s(sipCpp%s);\n' % (fname, pnames))
else: else:
stream.write('%s(sipIsErr%s);\n' % (fname, pnames)) stream.write('%s(%s);\n' % (fname, pnames))
stream.write(indent+' '*4)
stream.write('if (PyErr_Occurred()) sipIsErr = 1;\n')
stream.write('%s%%End\n' % indent) stream.write('%s%%End\n' % indent)
# and finally, add the new function itself # and finally, add the new function itself
@@ -640,7 +642,6 @@ from %s import *
stream.write('%s%%MethodCode\n' % indent) stream.write('%s%%MethodCode\n' % indent)
stream.write(nci(method.body, len(indent)+4)) stream.write(nci(method.body, len(indent)+4))
stream.write('%s%%End\n\n' % indent) stream.write('%s%%End\n\n' % indent)
# TODO: add the %Docstring...