forked from nextgis/qgis_qtiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtiles.py
101 lines (80 loc) · 4.11 KB
/
qtiles.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
#******************************************************************************
#
# QTiles
# ---------------------------------------------------------
# Generates tiles from QGIS project
#
# Copyright (C) 2012-2014 NextGIS (info@nextgis.org)
#
# This source 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.
#
# This code is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# A copy of the GNU General Public License is available on the World Wide Web
# at <http://www.gnu.org/licenses/>. You can also obtain it by writing
# to the Free Software Foundation, 51 Franklin Street, Suite 500 Boston,
# MA 02110-1335 USA.
#
#******************************************************************************
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import qtilesdialog
import aboutdialog
import resources_rc
class QTilesPlugin:
def __init__(self, iface):
self.iface = iface
self.qgsVersion = unicode(QGis.QGIS_VERSION_INT)
userPluginPath = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + '/python/plugins/qtiles'
systemPluginPath = QgsApplication.prefixPath() + '/python/plugins/qtiles'
overrideLocale = QSettings().value('locale/overrideFlag', False, type=bool)
if not overrideLocale:
localeFullName = QLocale.system().name()
else:
localeFullName = QSettings().value('locale/userLocale', '')
if QFileInfo(userPluginPath).exists():
translationPath = userPluginPath + '/i18n/qtiles_' + localeFullName + '.qm'
else:
translationPath = systemPluginPath + '/i18n/qtiles_' + localeFullName + '.qm'
self.localePath = translationPath
if QFileInfo(self.localePath).exists():
self.translator = QTranslator()
self.translator.load(self.localePath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
if int(self.qgsVersion) < 20000:
qgisVersion = self.qgsVersion[0] + '.' + self.qgsVersion[2] + '.' + self.qgsVersion[3]
QMessageBox.warning(self.iface.mainWindow(), QCoreApplication.translate('QTiles', 'Error'), QCoreApplication.translate('QTiles', 'QGIS %s detected.\n') % qgisVersion + QCoreApplication.translate('QTiles', 'This version of QTiles requires at least QGIS 2.0. Plugin will not be enabled.'))
return None
self.actionRun = QAction(QCoreApplication.translate('QTiles', 'QTiles'), self.iface.mainWindow())
self.iface.registerMainWindowAction(self.actionRun, 'Shift+T')
self.actionRun.setIcon(QIcon(':/icons/qtiles.png'))
self.actionRun.setWhatsThis('Generate tiles from current project')
self.actionAbout = QAction(QCoreApplication.translate('QTiles', 'About QTiles...'), self.iface.mainWindow())
self.actionAbout.setIcon(QIcon(':/icons/about.png'))
self.actionAbout.setWhatsThis('About QTiles')
self.iface.addPluginToMenu(QCoreApplication.translate('QTiles', 'QTiles'), self.actionRun)
self.iface.addPluginToMenu(QCoreApplication.translate('QTiles', 'QTiles'), self.actionAbout)
self.iface.addToolBarIcon(self.actionRun)
self.actionRun.triggered.connect(self.run)
self.actionAbout.triggered.connect(self.about)
def unload(self):
self.iface.unregisterMainWindowAction(self.actionRun)
self.iface.removeToolBarIcon(self.actionRun)
self.iface.removePluginMenu(QCoreApplication.translate('QTiles', 'QTiles'), self.actionRun)
self.iface.removePluginMenu(QCoreApplication.translate('QTiles', 'QTiles'), self.actionAbout)
def run(self):
d = qtilesdialog.QTilesDialog(self.iface)
d.show()
d.exec_()
def about(self):
d = aboutdialog.AboutDialog()
d.exec_()