21
21
#include " qgspythonutils.h"
22
22
23
23
#include " qgsapplication.h"
24
+ #include " qgslogger.h"
24
25
25
26
#include < QMessageBox>
26
27
28
+
27
29
QString QgsPythonUtils::mPluginsPath ;
28
30
PyObject* QgsPythonUtils::mMainModule ;
29
31
PyObject* QgsPythonUtils::mMainDict ;
@@ -167,6 +169,33 @@ bool QgsPythonUtils::runString(const QString& command)
167
169
}
168
170
169
171
172
+ QString QgsPythonUtils::getTypeAsString (PyObject* obj)
173
+ {
174
+ if (obj == NULL )
175
+ return NULL ;
176
+
177
+ if (PyClass_Check (obj))
178
+ {
179
+ QgsDebugMsg (" got class" );
180
+ return QString (PyString_AsString (((PyClassObject*)obj)->cl_name ));
181
+ }
182
+ else if (PyType_Check (obj))
183
+ {
184
+ QgsDebugMsg (" got type" );
185
+ return QString (((PyTypeObject*)obj)->tp_name );
186
+ }
187
+ else
188
+ {
189
+ QgsDebugMsg (" got object" );
190
+ PyObject* s = PyObject_Str (obj);
191
+ QString str;
192
+ if (s && PyString_Check (s))
193
+ str = QString (PyString_AsString (s));
194
+ Py_XDECREF (s);
195
+ return str;
196
+ }
197
+ }
198
+
170
199
bool QgsPythonUtils::getError (QString& errorClassName, QString& errorText)
171
200
{
172
201
if (!PyErr_Occurred ())
@@ -179,9 +208,9 @@ bool QgsPythonUtils::getError(QString& errorClassName, QString& errorText)
179
208
180
209
// get the exception information
181
210
PyErr_Fetch (&err_type, &err_value, &err_tb);
182
-
211
+
183
212
// get exception's class name
184
- errorClassName = PyString_AS_STRING (((PyClassObject*) err_type)-> cl_name );
213
+ errorClassName = getTypeAsString ( err_type);
185
214
186
215
// get exception's text
187
216
if (err_value != NULL && err_value != Py_None)
0 commit comments