18
18
// otherwise issues some warnings
19
19
#include < Python.h>
20
20
21
- #include " qgspythonutils .h"
21
+ #include " qgspythonutilsimpl .h"
22
22
23
23
#include " qgsapplication.h"
24
24
#include " qgslogger.h"
28
28
#include < QStringList>
29
29
#include < QDir>
30
30
31
- QgsPythonUtils* QgsPythonUtils ::mInstance = NULL ;
31
+ QgsPythonUtilsImpl* QgsPythonUtilsImpl ::mInstance = NULL ;
32
32
33
- QgsPythonUtils::QgsPythonUtils ()
33
+ QgsPythonUtilsImpl::QgsPythonUtilsImpl ()
34
34
{
35
35
mMainModule = NULL ;
36
36
mMainDict = NULL ;
37
37
mPythonEnabled = false ;
38
38
}
39
39
40
- QgsPythonUtils ::~QgsPythonUtils ()
40
+ QgsPythonUtilsImpl ::~QgsPythonUtilsImpl ()
41
41
{
42
42
}
43
43
44
- QgsPythonUtils* QgsPythonUtils ::instance ()
44
+ QgsPythonUtilsImpl* QgsPythonUtilsImpl ::instance ()
45
45
{
46
46
if (mInstance == NULL )
47
- mInstance = new QgsPythonUtils ();
47
+ mInstance = new QgsPythonUtilsImpl ();
48
48
return mInstance ;
49
49
}
50
50
51
51
52
- void QgsPythonUtils ::initPython (QgisInterface* interface)
52
+ void QgsPythonUtilsImpl ::initPython (QgisInterface* interface)
53
53
{
54
54
// initialize python
55
55
Py_Initialize ();
@@ -137,7 +137,7 @@ void QgsPythonUtils::initPython(QgisInterface* interface)
137
137
138
138
}
139
139
140
- void QgsPythonUtils ::exitPython ()
140
+ void QgsPythonUtilsImpl ::exitPython ()
141
141
{
142
142
Py_Finalize ();
143
143
mMainModule = NULL ;
@@ -146,38 +146,38 @@ void QgsPythonUtils::exitPython()
146
146
}
147
147
148
148
149
- bool QgsPythonUtils ::isEnabled ()
149
+ bool QgsPythonUtilsImpl ::isEnabled ()
150
150
{
151
151
return mPythonEnabled ;
152
152
}
153
153
154
- void QgsPythonUtils ::installErrorHook ()
154
+ void QgsPythonUtilsImpl ::installErrorHook ()
155
155
{
156
156
runString (" sys.excepthook = qgis_except_hook" );
157
157
}
158
158
159
- void QgsPythonUtils ::installConsoleHooks ()
159
+ void QgsPythonUtilsImpl ::installConsoleHooks ()
160
160
{
161
161
runString (" sys.displayhook = console_display_hook\n " );
162
162
163
163
runString (" _old_stdout = sys.stdout\n " );
164
164
runString (" sys.stdout = QgisOutputCatcher()\n " );
165
165
}
166
166
167
- void QgsPythonUtils ::uninstallConsoleHooks ()
167
+ void QgsPythonUtilsImpl ::uninstallConsoleHooks ()
168
168
{
169
169
runString (" sys.displayhook = sys.__displayhook__" );
170
170
runString (" sys.stdout = _old_stdout" );
171
171
}
172
172
173
173
174
- bool QgsPythonUtils ::runStringUnsafe (const QString& command)
174
+ bool QgsPythonUtilsImpl ::runStringUnsafe (const QString& command)
175
175
{
176
176
PyRun_String (command.toLocal8Bit ().data (), Py_single_input, mMainDict , mMainDict );
177
177
return (PyErr_Occurred () == 0 );
178
178
}
179
179
180
- bool QgsPythonUtils ::runString (const QString& command, QString msgOnError)
180
+ bool QgsPythonUtilsImpl ::runString (const QString& command, QString msgOnError)
181
181
{
182
182
bool res = runStringUnsafe (command);
183
183
if (res)
@@ -208,7 +208,7 @@ bool QgsPythonUtils::runString(const QString& command, QString msgOnError)
208
208
}
209
209
210
210
211
- QString QgsPythonUtils ::getTraceback ()
211
+ QString QgsPythonUtilsImpl ::getTraceback ()
212
212
{
213
213
#define TRACEBACK_FETCH_ERROR (what ) {errMsg = what; goto done;}
214
214
@@ -280,7 +280,7 @@ QString QgsPythonUtils::getTraceback()
280
280
return result;
281
281
}
282
282
283
- QString QgsPythonUtils ::getTypeAsString (PyObject* obj)
283
+ QString QgsPythonUtilsImpl ::getTypeAsString (PyObject* obj)
284
284
{
285
285
if (obj == NULL )
286
286
return NULL ;
@@ -307,7 +307,7 @@ QString QgsPythonUtils::getTypeAsString(PyObject* obj)
307
307
}
308
308
}
309
309
310
- bool QgsPythonUtils ::getError (QString& errorClassName, QString& errorText)
310
+ bool QgsPythonUtilsImpl ::getError (QString& errorClassName, QString& errorText)
311
311
{
312
312
if (!PyErr_Occurred ())
313
313
return false ;
@@ -341,12 +341,12 @@ bool QgsPythonUtils::getError(QString& errorClassName, QString& errorText)
341
341
return true ;
342
342
}
343
343
344
- QString QgsPythonUtils ::getResult ()
344
+ QString QgsPythonUtilsImpl ::getResult ()
345
345
{
346
346
return getVariableFromMain (" __result" );
347
347
}
348
348
349
- QString QgsPythonUtils ::getVariableFromMain (QString name)
349
+ QString QgsPythonUtilsImpl ::getVariableFromMain (QString name)
350
350
{
351
351
PyObject* obj;
352
352
PyObject* obj_str;
@@ -372,7 +372,7 @@ QString QgsPythonUtils::getVariableFromMain(QString name)
372
372
return output;
373
373
}
374
374
375
- bool QgsPythonUtils ::evalString (const QString& command, QString& result)
375
+ bool QgsPythonUtilsImpl ::evalString (const QString& command, QString& result)
376
376
{
377
377
PyObject* res = PyRun_String (command.toLocal8Bit ().data (), Py_eval_input, mMainDict , mMainDict );
378
378
@@ -387,27 +387,27 @@ bool QgsPythonUtils::evalString(const QString& command, QString& result)
387
387
}
388
388
389
389
390
- QString QgsPythonUtils ::pythonPath ()
390
+ QString QgsPythonUtilsImpl ::pythonPath ()
391
391
{
392
392
return QgsApplication::pkgDataPath () + " /python" ;
393
393
}
394
394
395
- QString QgsPythonUtils ::pluginsPath ()
395
+ QString QgsPythonUtilsImpl ::pluginsPath ()
396
396
{
397
397
return pythonPath () + " /plugins" ;
398
398
}
399
399
400
- QString QgsPythonUtils ::homePluginsPath ()
400
+ QString QgsPythonUtilsImpl ::homePluginsPath ()
401
401
{
402
402
return QgsApplication::qgisSettingsDirPath () + " /python/plugins" ;
403
403
}
404
404
405
- QStringList QgsPythonUtils ::pluginList ()
405
+ QStringList QgsPythonUtilsImpl ::pluginList ()
406
406
{
407
- QDir pluginDir (QgsPythonUtils ::pluginsPath (), " *" ,
407
+ QDir pluginDir (QgsPythonUtilsImpl ::pluginsPath (), " *" ,
408
408
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
409
409
410
- QDir homePluginDir (QgsPythonUtils ::homePluginsPath (), " *" ,
410
+ QDir homePluginDir (QgsPythonUtilsImpl ::homePluginsPath (), " *" ,
411
411
QDir::Name | QDir::IgnoreCase, QDir::Dirs | QDir::NoDotAndDotDot);
412
412
413
413
QStringList pluginList = pluginDir.entryList ();
@@ -423,7 +423,7 @@ QStringList QgsPythonUtils::pluginList()
423
423
return pluginList;
424
424
}
425
425
426
- QString QgsPythonUtils ::getPluginMetadata (QString pluginName, QString function)
426
+ QString QgsPythonUtilsImpl ::getPluginMetadata (QString pluginName, QString function)
427
427
{
428
428
QString command = pluginName + " ." + function + " ()" ;
429
429
QString retval = " ???" ;
@@ -449,7 +449,7 @@ QString QgsPythonUtils::getPluginMetadata(QString pluginName, QString function)
449
449
}
450
450
451
451
452
- bool QgsPythonUtils ::loadPlugin (QString packageName)
452
+ bool QgsPythonUtilsImpl ::loadPlugin (QString packageName)
453
453
{
454
454
// load plugin's package and ensure that plugin is reloaded when changed
455
455
runString (
@@ -480,7 +480,7 @@ bool QgsPythonUtils::loadPlugin(QString packageName)
480
480
}
481
481
482
482
483
- bool QgsPythonUtils ::startPlugin (QString packageName)
483
+ bool QgsPythonUtilsImpl ::startPlugin (QString packageName)
484
484
{
485
485
QString pluginPythonVar = " plugins['" + packageName + " ']" ;
486
486
@@ -499,7 +499,7 @@ bool QgsPythonUtils::startPlugin(QString packageName)
499
499
}
500
500
501
501
502
- bool QgsPythonUtils ::unloadPlugin (QString packageName)
502
+ bool QgsPythonUtilsImpl ::unloadPlugin (QString packageName)
503
503
{
504
504
// unload and delete plugin!
505
505
QString varName = " plugins['" + packageName + " ']" ;
0 commit comments