Skip to content

Commit

Permalink
Fix exception when libraries are not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltoncj committed May 1, 2023
1 parent 327a26d commit 3956944
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
17 changes: 9 additions & 8 deletions earthsunmoon.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
try:
from timezonefinder import TimezoneFinder
from skyfield.api import wgs84
from jplephem.spk import SPK
libraries_found = True
from .provider import EarthSunMoonProvider
except Exception:
Expand Down Expand Up @@ -94,17 +95,17 @@ def initGui(self):
self.solarInfoAction.triggered.connect(self.solarInfo)
self.iface.addPluginToMenu("Earth, sun, moon && planets", self.solarInfoAction)
self.toolbar.addAction(self.solarInfoAction)

# Selected ephemeris information
icon = QIcon(os.path.dirname(__file__) + "/icons/ephem.svg")
self.ephemAction = QAction(icon, "Ephemeris information", self.iface.mainWindow())
self.ephemAction.triggered.connect(self.ephemInfo)
self.iface.addPluginToMenu('Earth, sun, moon && planets', self.ephemAction)
else:
icon = QIcon(":images/themes/default/mIndicatorBadLayer.svg")
self.requirementsActions = QAction(icon, "Required python libraries not installed", self.iface.mainWindow())
self.requirementsActions.triggered.connect(self.requirements)
self.iface.addPluginToMenu("Earth, sun, moon && planets", self.requirementsActions)

# Selected ephemeris information
icon = QIcon(os.path.dirname(__file__) + "/icons/ephem.svg")
self.ephemAction = QAction(icon, "Ephemeris information", self.iface.mainWindow())
self.ephemAction.triggered.connect(self.ephemInfo)
self.iface.addPluginToMenu('Earth, sun, moon && planets', self.ephemAction)

# Settings
icon = QIcon(':/images/themes/default/mActionOptions.svg')
Expand Down Expand Up @@ -136,21 +137,21 @@ def unload(self):
self.iface.removeToolBarIcon(self.planetsAction)
self.iface.removePluginMenu('Earth, sun, moon && planets', self.solarInfoAction)
self.iface.removeToolBarIcon(self.solarInfoAction)
self.iface.removePluginMenu('Earth, sun, moon && planets', self.ephemAction)
if self.solarInfoDialog:
self.iface.removeDockWidget(self.solarInfoDialog)
self.solarInfoDialog = None
QgsApplication.processingRegistry().removeProvider(self.provider)
else:
self.iface.removePluginMenu('Earth, sun, moon && planets', self.requirementsActions)

self.iface.removePluginMenu('Earth, sun, moon && planets', self.ephemAction)
self.iface.removePluginMenu('Earth, sun, moon && planets', self.settingsAction)
self.iface.removePluginMenu('Earth, sun, moon && planets', self.helpAction)

def requirements(self):
message = '''
<p>This plugin requires <a href="https://timezonefinder.readthedocs.io/en/latest/">TimeZoneFinder</a> and <a href="https://rhodesmill.org/skyfield/">Skyfiled</a> libraries.<br/><br/>
These libraries can be installed by running the OSGeo4W shell as system administrator and running 'pip install skyfield timezonefinder' or whatever method you use to install python packages.<p>
These libraries can be installed by running the OSGeo4W shell and running 'pip install skyfield timezonefinder' or whatever method you use to install python packages.<p>
<p>Once the libraries are installed, please restart QGIS.</p>
'''
QMessageBox.information(self.iface.mainWindow(), 'Plugin Requirements not Satisfied', message)
Expand Down
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name=Earth, Sun, Moon, and Planets
qgisMinimumVersion=3.14
description=Tools to calculate the positions of the sun, moon, and planets when viewed from directly overhead for a particular date and time. It displays solar and lunar information for a coordinate at the specified date and time. (Note the Python library dependencies.)
version=3.0.0
version=3.0.1
author=C Hamilton
[email protected]
about=
Expand All @@ -18,4 +18,5 @@ icon=icon.png
experimental=False
deprecated=False
changelog=
3.0.1 - Fix exception when libraries are not installed
3.0.0 - First release
7 changes: 4 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from qgis.core import Qgis, QgsCoordinateReferenceSystem, QgsSettings, QgsApplication
from qgis.PyQt.QtWidgets import QDialog
from datetime import date
from jplephem.spk import SPK
from shutil import copyfile
import traceback
try:
from jplephem.spk import SPK
except Exception:
pass

epsg4326 = QgsCoordinateReferenceSystem('EPSG:4326')

Expand Down Expand Up @@ -78,7 +80,6 @@ def ephemInfo(self):
msg = '{}\n{}'.format(self.ephemPath(), str(spk))
spk.close()
except Exception:
traceback.print_exc()
msg = ''
return(msg)

Expand Down

0 comments on commit 3956944

Please sign in to comment.