Added a typemap that converts strings to wxColour objects either using
the colour name or a string of the format #RRGGBB Started the wxStyledTextCtrl Python demos Other assorted tweaks and fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7214 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -928,6 +928,39 @@ bool wxRect_helper(PyObject* source, wxRect** obj) {
|
||||
|
||||
|
||||
|
||||
bool wxColour_helper(PyObject* source, wxColour** obj) {
|
||||
|
||||
// If source is an object instance then it may already be the right type
|
||||
if (PyInstance_Check(source)) {
|
||||
wxColour* ptr;
|
||||
if (SWIG_GetPtrObj(source, (void **)&ptr, "_wxColour_p"))
|
||||
goto error;
|
||||
*obj = ptr;
|
||||
return TRUE;
|
||||
}
|
||||
// otherwise a string is expected
|
||||
else if (PyString_Check(source)) {
|
||||
wxString spec = PyString_AS_STRING(source);
|
||||
if (spec[0] == '#' && spec.Length() == 7) { // It's #RRGGBB
|
||||
char* junk;
|
||||
int red = strtol(spec.Mid(1,2), &junk, 16);
|
||||
int green = strtol(spec.Mid(3,2), &junk, 16);
|
||||
int blue = strtol(spec.Mid(5,2), &junk, 16);
|
||||
**obj = wxColour(red, green, blue);
|
||||
return TRUE;
|
||||
}
|
||||
else { // it's a colour name
|
||||
**obj = wxColour(spec);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
PyErr_SetString(PyExc_TypeError, "Expected a wxColour object or a string containing a colour name or #RRGGBB.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user