Skip to content
Snippets Groups Projects
timeseriesviewerplugin.py 2.28 KiB
Newer Older
  • Learn to ignore specific revisions
  • from __future__ import absolute_import
    import inspect
    import os
    import six
    import traceback
    import sys
    import importlib
    import re
    import site
    
    from qgis.gui import *
    from qgis.core import *
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    
    
    DIR_REPO = os.path.normpath(os.path.split(inspect.getfile(inspect.currentframe()))[0])
    DIR_SITE_PACKAGES = None
    
    
        def __init__(self, iface):
            self.iface = iface
            self.tsv = None
    
            import console.console as CONSOLE
            if CONSOLE._console is None:
                CONSOLE._console = CONSOLE.PythonConsole(iface.mainWindow())
                QTimer.singleShot(0, CONSOLE._console.activate)
    
    
    
        def initGui(self):
            self.toolbarActions = []
            syspaths = [os.path.normpath(p) for p in sys.path]
            if DIR_REPO not in syspaths: sys.path.append(DIR_REPO)
    
    
            import timeseriesviewer.ui.resources_py2
            timeseriesviewer.ui.resources_py2.qInitResources()
    
            # add platform independent site-packages
            if DIR_SITE_PACKAGES:
                site.addsitedir(DIR_SITE_PACKAGES)
    
    
            import timeseriesviewer
            # init main UI
            from timeseriesviewer import dprint, DIR_UI, jp
            icon = QIcon(jp(DIR_UI, *['icons', 'icon.png']))
            action = QAction(icon, 'SenseCarbon Time Series Viewer', self.iface)
    
            action.triggered.connect(self.run)
            self.toolbarActions.append(action)
    
    
            for action in self.toolbarActions:
    
                self.iface.addToolBarIcon(action)
    
        def run(self):
            from timeseriesviewer.main import TimeSeriesViewer
            # open QGIS python console. this is required to allow for print() statements in the source code.
    
    
            self.tsv = TimeSeriesViewer(self.iface)
    
            self.tsv.run()
    
        def unload(self):
            from timeseriesviewer import dprint
            from timeseriesviewer.main import TimeSeriesViewer
            dprint('UNLOAD SenseCarbon TimeSeriesViewer Plugin')
    
            for action in self.toolbarActions:
                print(action)
                self.iface.removeToolBarIcon(action)
    
            if isinstance(self.tsv, TimeSeriesViewer):
    
            return QCoreApplication.translate('TimeSeriesViewerPlugin', message)