Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
class TSVPlugin:
def __init__(self, iface):
self.iface = iface
self.tsv = None
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)
# add platform independent site-packages
if DIR_SITE_PACKAGES:
site.addsitedir(DIR_SITE_PACKAGES)
from timeseriesviewer.main import TimeSeriesViewer
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
icon = TimeSeriesViewer.icon()
action = QAction(icon, self.tr(u'SenseCarbon Time Series Viewer'), self.iface.mainWindow())
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.
if isinstance(self.iface, QgisInterface):
import console
c = console.show_console()
c.setVisible(True)
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):
self.tsv.dlg.close()
self.tsv = None
def tr(self, message):
return QCoreApplication.translate('EnMAPBoxPlugin', message)