Skip to content
Snippets Groups Projects
timeseriesviewerplugin.py 4.19 KiB
Newer Older
"""
/***************************************************************************
                              -------------------
        begin                : 2017-08-04
        git sha              : $Format:%H$
        copyright            : (C) 2017 by HU-Berlin
        email                : benjamin.jakimow@geo.hu-berlin.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
"""
# noinspection PyPep8Naming
from qgis.gui import *
from qgis.core import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
        dirPlugin = os.path.dirname(__file__)
        site.addsitedir(dirPlugin)

Benjamin Jakimow's avatar
Benjamin Jakimow committed

        # run a dependency check
        self.initialDependencyCheck()

Benjamin Jakimow's avatar
Benjamin Jakimow committed
        # initialize required settings
        eotimeseriesviewer.initAll()
Benjamin Jakimow's avatar
Benjamin Jakimow committed

Benjamin Jakimow's avatar
Benjamin Jakimow committed

        from eotimeseriesviewer import DIR_UI, jp, TITLE
        icon = eotimeseriesviewer.icon()
benjamin.jakimow@geo.hu-berlin.de's avatar
benjamin.jakimow@geo.hu-berlin.de committed
        action = QAction(icon, TITLE, self.iface)
        action.triggered.connect(self.run)
        self.mToolbarActions.append(action)
        for action in self.mToolbarActions:
            self.iface.addToolBarIcon(action)

    def initialDependencyCheck(self):
        """
        Runs a check for availability of package dependencies and give an readible error message
        :return:
        """

        missing = []
        from eotimeseriesviewer import DEPENDENCIES, messageLog
        for package in DEPENDENCIES:
            try:
                __import__(package)

            except Exception as ex:
                missing.append(package)
        if len(missing) > 0:

            n = len(missing)

            longText = ['Unable to import the following package(s):']
            longText.append('<b>{}</b>'.format(', '.join(missing)))
            longText.append('<p>Please run your local package manager(s) with root rights to install them.')
            #longText.append('More information is available under:')
            #longText.append('<a href="http://enmap-box.readthedocs.io/en/latest/Installation.html">http://enmap-box.readthedocs.io/en/latest/Installation.html</a> </p>')

            longText.append('This Python:')
            longText.append('Executable: {}'.format(sys.executable))
            longText.append('ENVIRON:')
            for k in sorted(os.environ.keys()):
                longText.append('\t{} ={}'.format(k, os.environ[k]))

            longText = '<br/>\n'.join(longText)
            messageLog(longText)
            raise Exception(longText)



        from eotimeseriesviewer.main import TimeSeriesViewer
        self.mEOTSV = TimeSeriesViewer()
        self.mEOTSV.ui.sigAboutToBeClosed.connect(self.onUiClosed)
        self.mEOTSV.show()
    def onUiClosed(self):
        self.mEOTSV = None
        from eotimeseriesviewer.main import TimeSeriesViewer
        TimeSeriesViewer._instance = None

        from eotimeseriesviewer.main import TimeSeriesViewer
            self.iface.removeToolBarIcon(action)

        return QCoreApplication.translate('EOTimeSeriesViewerPlugin', message)