|
25 | 25 | # Initialize Qt resources from file resources_rc.py
|
26 | 26 | import resources_rc
|
27 | 27 |
|
28 |
| -# Import required modules and if missing show the right module's name |
29 |
| -req_mods = { "osgeo": "osgeo [python-gdal]" } |
| 28 | +# are all dependecies satisfied? |
| 29 | +valid = True |
30 | 30 |
|
| 31 | +# Import required modules |
| 32 | +req_mods = { "osgeo": "osgeo [python-gdal]" } |
31 | 33 | try:
|
32 | 34 | from osgeo import gdal
|
33 | 35 | from osgeo import ogr
|
34 | 36 | except ImportError, e:
|
35 |
| - error_str = e.args[0] |
36 |
| - error_mod = error_str.replace( "No module named ", "" ) |
37 |
| - if req_mods.has_key( error_mod ): |
38 |
| - error_str = error_str.replace( error_mod, req_mods[error_mod] ) |
39 |
| - raise ImportError( error_str ) |
| 37 | + valid = False |
| 38 | + |
| 39 | + # if the plugin is shipped with QGis catch the exception and |
| 40 | + # display an error message |
| 41 | + import os.path |
| 42 | + qgisUserPluginPath = os.path.abspath( os.path.join( str( QgsApplication.qgisSettingsDirPath() ), "python") ) |
| 43 | + if not os.path.dirname(__file__).startswith( qgisUserPluginPath ): |
| 44 | + title = QCoreApplication.translate( "GdalTools", "Plugin error" ) |
| 45 | + message = QCoreApplication.translate( "GdalTools", u'Unable to load %1 plugin. \nThe required "%2" module is missing. \nInstall it and try again.' ) |
| 46 | + import qgis.utils |
| 47 | + QMessageBox.warning( qgis.utils.iface.mainWindow(), title, message.arg( "GdalTools" ).arg( req_mods["osgeo"] ) ) |
| 48 | + else: |
| 49 | + # if a module is missing show a more friendly module's name |
| 50 | + error_str = e.args[0] |
| 51 | + error_mod = error_str.replace( "No module named ", "" ) |
| 52 | + if req_mods.has_key( error_mod ): |
| 53 | + error_str = error_str.replace( error_mod, req_mods[error_mod] ) |
| 54 | + raise ImportError( error_str ) |
40 | 55 |
|
41 | 56 |
|
42 | 57 | class GdalTools:
|
43 | 58 |
|
44 | 59 | def __init__( self, iface ):
|
| 60 | + if not valid: return |
| 61 | + |
45 | 62 | # Save reference to the QGIS interface
|
46 | 63 | self.iface = iface
|
47 | 64 | try:
|
@@ -72,6 +89,7 @@ def __init__( self, iface ):
|
72 | 89 | QCoreApplication.installTranslator( self.translator )
|
73 | 90 |
|
74 | 91 | def initGui( self ):
|
| 92 | + if not valid: return |
75 | 93 | if int( self.QgisVersion ) < 1:
|
76 | 94 | QMessageBox.warning( self.iface.getMainWindow(), "Gdal Tools",
|
77 | 95 | QCoreApplication.translate( "GdalTools", "Quantum GIS version detected: " ) +unicode( self.QgisVersion )+".xx\n"
|
@@ -258,6 +276,7 @@ def initGui( self ):
|
258 | 276 | menu_bar.insertMenu( lastAction, self.menu )
|
259 | 277 |
|
260 | 278 | def unload( self ):
|
| 279 | + if not valid: return |
261 | 280 | pass
|
262 | 281 |
|
263 | 282 | def doBuildVRT( self ):
|
|
0 commit comments