-
Notifications
You must be signed in to change notification settings - Fork 5
/
PostNAS_Search.py
137 lines (112 loc) · 5.82 KB
/
PostNAS_Search.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import QAction, QDockWidget
# Initialize Qt resources from file resources.py
from . import resources_rc
# Import the code for the dialog
from .PostNAS_SearchDialog import PostNAS_SearchDialog
from .PostNAS_ConfDialog import PostNAS_ConfDialog
from .PostNAS_CreateFulltextindex import PostNAS_CreateFulltextindex
import os.path
class PostNAS_Search:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(self.plugin_dir,'i18n','PostNAS_Search_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.dlg = PostNAS_SearchDialog(iface=self.iface)
self.conf = PostNAS_ConfDialog(iface=self.iface)
# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&PostNAS_Search')
self.searchDockWidget = None
self.searchDockWidgetArea = Qt.LeftDockWidgetArea
# noinspection PyMethodMayBeStatic
def tr(self, message):
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('PostNAS_Search', message)
def initGui(self):
# Create Conf-Action and Menuentry
self.confAction = QAction("Einstellungen", self.iface.mainWindow())
self.confAction.setWhatsThis("Konfiguration der PostNAS-Suche")
self.confAction.setStatusTip("Konfiguration der PostNAS-Suche")
self.confAction.triggered.connect(self.showConf)
if hasattr(self.iface, "addPluginToDatabaseMenu"):
self.iface.addPluginToDatabaseMenu("&PostNAS-Suche", self.confAction)
else:
self.iface.addPluginToMenu("&PostNAS-Suche", self.confAction)
self.toggleSearchAction = QAction(u"Flurstücksuche", self.iface.mainWindow())
self.toggleSearchAction.setWhatsThis(u"Starten/Schliessen der Flurstücksuche")
self.toggleSearchAction.setStatusTip(u"Starten/Schliessen der Flurstücksuche")
self.toggleSearchAction.triggered.connect(self.toggleWidget)
if hasattr(self.iface, "addPluginToDatabaseMenu"):
self.iface.addPluginToDatabaseMenu("&PostNAS-Suche", self.toggleSearchAction)
else:
self.iface.addPluginToMenu("&PostNAS-Suche", self.toggleSearchAction)
self.fulltextindex = QAction(u"Volltextindex erstellen", self.iface.mainWindow())
self.fulltextindex.setWhatsThis(u"Erzeugt einen Volltextindex in der Datenbank um die Suche zu beschleunigen")
self.fulltextindex.setStatusTip(u"Erzeugt einen Volltextindex in der Datenbank um die Suche zu beschleunigen")
self.fulltextindex.triggered.connect(self.createFulltextindex)
if hasattr(self.iface, "addPluginToDatabaseMenu"):
self.iface.addPluginToDatabaseMenu("&PostNAS-Suche", self.fulltextindex)
else:
self.iface.addPluginToMenu("&PostNAS-Suche", self.fulltextindex)
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/PostNAS_Search/search_24x24.png"),u"Flurstücksuche", self.iface.mainWindow())
self.action.setCheckable(True)
# connect the action to the run method
self.action.triggered.connect(self.toggleWidget)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
def toggleWidget(self, event):
if self.searchDockWidget == None:
self.searchDockWidget = QDockWidget(self.iface.mainWindow())
self.searchDockWidget.setWindowTitle(self.tr(u'Suche'))
self.searchDockWidget.setWidget(self.dlg)
self.searchDockWidget.closeEvent = self.toggleWidget
self.iface.addDockWidget(self.searchDockWidgetArea, self.searchDockWidget)
self.action.setChecked(True)
else:
self.searchDockWidgetArea = self.iface.mainWindow().dockWidgetArea(self.searchDockWidget)
self.iface.removeDockWidget(self.searchDockWidget)
self.searchDockWidget = None
self.action.setChecked(False)
def showConf(self):
dlg = PostNAS_ConfDialog(self)
dlg.exec_()
def createFulltextindex(self):
dlg = PostNAS_CreateFulltextindex(self)
dlg.exec_()
def unload(self):
# Remove the Toolbar Icon
self.iface.removeToolBarIcon(self.action)
# Remove DockWidget
if self.searchDockWidget != None:
self.iface.removeDockWidget(self.searchDockWidget)
if hasattr(self.iface, "removePluginDatabaseMenu"):
self.iface.removePluginDatabaseMenu("&PostNAS-Suche", self.confAction)
self.iface.removePluginDatabaseMenu("&PostNAS-Suche", self.toggleSearchAction)
self.iface.removePluginDatabaseMenu("&PostNAS-Suche", self.fulltextindex)
else:
self.iface.removePluginMenu("&PostNAS-Suche", self.confAction)
self.iface.removePluginMenu("&PostNAS-Suche", self.toggleSearchAction)
self.iface.removePluginMenu("&PostNAS-Suche", self.fulltextindex)
if self.confAction:
self.confAction.deleteLater()
self.confAction = None
if self.toggleSearchAction:
self.toggleSearchAction.deleteLater()
self.toggleSearchAction = None
if self.fulltextindex:
self.fulltextindex.deleteLater()
self.fulltextindex = None