167
167
#include " qgsdbsourceselect.h"
168
168
#endif
169
169
170
- #ifdef HAVE_PYTHON
171
170
#include " qgspythondialog.h"
172
171
#include " qgspythonutils.h"
172
+ #ifdef HAVE_PYTHON
173
+ #include " qgspythonutilsimpl.h"
173
174
#endif
174
175
175
176
#ifndef WIN32
@@ -304,7 +305,8 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
304
305
// constructor starts here
305
306
QgisApp::QgisApp (QSplashScreen *splash, QWidget * parent, Qt::WFlags fl)
306
307
: QMainWindow(parent,fl),
307
- mSplash(splash)
308
+ mSplash(splash),
309
+ mPythonUtils(NULL ), mPythonConsole(NULL )
308
310
{
309
311
// setupUi(this);
310
312
resize (640 , 480 );
@@ -361,11 +363,14 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
361
363
#ifdef HAVE_PYTHON
362
364
mSplash ->showMessage (tr (" Starting Python" ), Qt::AlignHCenter | Qt::AlignBottom);
363
365
qApp->processEvents ();
364
- QgsPythonUtils::instance ()->initPython (mQgisInterface );
366
+
367
+ mPythonUtils = QgsPythonUtilsImpl::instance ();
368
+
369
+ mPythonUtils ->initPython (mQgisInterface );
370
+ #endif
365
371
366
- if (!QgsPythonUtils::instance () ->isEnabled ())
372
+ if (!mPythonUtils || ! mPythonUtils ->isEnabled ())
367
373
mActionShowPythonDialog ->setEnabled (false );
368
- #endif
369
374
370
375
// Create the plugin registry and load plugins
371
376
// load any plugins that were running in the last session
@@ -439,9 +444,8 @@ QgisApp::~QgisApp()
439
444
delete mMapTools .mAddRing ;
440
445
delete mMapTools .mAddIsland ;
441
446
442
- #ifdef HAVE_PYTHON
443
447
delete mPythonConsole ;
444
- # endif
448
+ delete mPythonUtils ;
445
449
446
450
// delete map layer registry and provider registry
447
451
QgsApplication::exitQgis ();
@@ -858,20 +862,18 @@ void QgisApp::createActions()
858
862
connect ( mActionMapTips , SIGNAL ( triggered () ), this , SLOT ( toggleMapTips () ) );
859
863
mActionMapTips ->setCheckable (true );
860
864
861
- #ifdef HAVE_PYTHON
862
865
mActionShowPythonDialog = new QAction (tr (" Python console" ), this );
863
866
connect (mActionShowPythonDialog , SIGNAL (triggered ()), this , SLOT (showPythonDialog ()));
864
- mPythonConsole = NULL ;
865
- #endif
866
867
}
867
868
868
869
void QgisApp::showPythonDialog ()
869
870
{
870
- #ifdef HAVE_PYTHON
871
+ if (!mPythonUtils || !mPythonUtils ->isEnabled ())
872
+ return ;
873
+
871
874
if (mPythonConsole == NULL )
872
- mPythonConsole = new QgsPythonDialog (mQgisInterface );
875
+ mPythonConsole = new QgsPythonDialog (mQgisInterface , mPythonUtils );
873
876
mPythonConsole ->show ();
874
- #endif
875
877
}
876
878
877
879
void QgisApp::createActionGroups ()
@@ -992,9 +994,7 @@ void QgisApp::createMenus()
992
994
// Plugins Menu
993
995
mPluginMenu = menuBar ()->addMenu (tr (" &Plugins" ));
994
996
mPluginMenu ->addAction (mActionShowPluginManager );
995
- #ifdef HAVE_PYTHON
996
997
mPluginMenu ->addAction (mActionShowPythonDialog );
997
- #endif
998
998
mPluginMenu ->addSeparator ();
999
999
1000
1000
// Add the plugin manager action to it
@@ -1705,33 +1705,30 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
1705
1705
delete myLib;
1706
1706
}
1707
1707
1708
- #ifdef HAVE_PYTHON
1709
1708
QString pluginName, description, version;
1710
1709
1711
- QgsPythonUtils* pythonUtils = QgsPythonUtils::instance ();
1712
-
1713
- if (pythonUtils->isEnabled ())
1710
+ if (mPythonUtils && mPythonUtils ->isEnabled ())
1714
1711
{
1715
1712
1716
1713
// check for python plugins system-wide
1717
- QStringList pluginList = pythonUtils ->pluginList ();
1714
+ QStringList pluginList = mPythonUtils ->pluginList ();
1718
1715
1719
1716
for (int i = 0 ; i < pluginList.size (); i++)
1720
1717
{
1721
1718
QString packageName = pluginList[i];
1722
1719
1723
1720
// import plugin's package
1724
- if (!pythonUtils ->loadPlugin (packageName))
1721
+ if (!mPythonUtils ->loadPlugin (packageName))
1725
1722
continue ;
1726
1723
1727
1724
// get information from the plugin
1728
1725
// if there are some problems, don't continue with metadata retreival
1729
- pluginName = pythonUtils ->getPluginMetadata (packageName, " name" );
1726
+ pluginName = mPythonUtils ->getPluginMetadata (packageName, " name" );
1730
1727
if (pluginName != " __error__" )
1731
1728
{
1732
- description = pythonUtils ->getPluginMetadata (packageName, " description" );
1729
+ description = mPythonUtils ->getPluginMetadata (packageName, " description" );
1733
1730
if (description != " __error__" )
1734
- version = pythonUtils ->getPluginMetadata (packageName, " version" );
1731
+ version = mPythonUtils ->getPluginMetadata (packageName, " version" );
1735
1732
}
1736
1733
1737
1734
if (pluginName == " __error__" || description == " __error__" || version == " __error__" )
@@ -1746,7 +1743,7 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
1746
1743
}
1747
1744
}
1748
1745
}
1749
- # endif
1746
+
1750
1747
QgsDebugMsg (" Loading plugins completed" );
1751
1748
QgsDebugMsg (" *************************************************\n\n " );
1752
1749
}
@@ -3857,7 +3854,7 @@ void QgisApp::zoomToLayerExtent()
3857
3854
3858
3855
void QgisApp::showPluginManager ()
3859
3856
{
3860
- QgsPluginManager *pm = new QgsPluginManager (this );
3857
+ QgsPluginManager *pm = new QgsPluginManager (mPythonUtils , this );
3861
3858
pm->resizeColumnsToContents ();
3862
3859
if (pm->exec ())
3863
3860
{
@@ -3882,11 +3879,11 @@ void QgisApp::showPluginManager()
3882
3879
3883
3880
void QgisApp::loadPythonPlugin (QString packageName, QString pluginName)
3884
3881
{
3885
- #ifdef HAVE_PYTHON
3886
- QgsPythonUtils* pythonUtils = QgsPythonUtils::instance ();
3887
-
3888
- if (!pythonUtils->isEnabled ())
3882
+ if (!mPythonUtils || !mPythonUtils ->isEnabled ())
3883
+ {
3884
+ QgsDebugMsg (" Python is not enabled in QGIS." );
3889
3885
return ;
3886
+ }
3890
3887
3891
3888
QgsDebugMsg (" I should load python plugin: " + pluginName + " (package: " + packageName + " )" );
3892
3889
@@ -3895,8 +3892,8 @@ void QgisApp::loadPythonPlugin(QString packageName, QString pluginName)
3895
3892
// is loaded already?
3896
3893
if (pRegistry->library (pluginName).isEmpty ())
3897
3894
{
3898
- pythonUtils ->loadPlugin (packageName);
3899
- pythonUtils ->startPlugin (packageName);
3895
+ mPythonUtils ->loadPlugin (packageName);
3896
+ mPythonUtils ->startPlugin (packageName);
3900
3897
3901
3898
// TODO: test success
3902
3899
@@ -3907,11 +3904,6 @@ void QgisApp::loadPythonPlugin(QString packageName, QString pluginName)
3907
3904
QSettings settings;
3908
3905
settings.writeEntry (" /PythonPlugins/" + packageName, true );
3909
3906
}
3910
-
3911
-
3912
- #else
3913
- QgsDebugMsg (" Python is not enabled in QGIS." );
3914
- #endif
3915
3907
}
3916
3908
3917
3909
void QgisApp::loadPlugin (QString name, QString description, QString theFullPathName)
0 commit comments