-
Notifications
You must be signed in to change notification settings - Fork 12
/
gazetteersearchdialog.py
74 lines (62 loc) · 2.66 KB
/
gazetteersearchdialog.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
gazetteerSearchDialog
A QGIS plugin
Gazetteer
Search plugin
-------------------
begin : 2012-07-21
copyright : (C) 2012 by Nathan Woodrow
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from PyQt4 import QtCore, QtGui
from ui_gazetteersearch import Ui_gazetteerSearch
import resources_rc
class gazetteerSearchDialog(QtGui.QDialog):
runSearch = QtCore.pyqtSignal(str, str)
zoomRequested = QtCore.pyqtSignal(str)
def __init__(self):
QtGui.QDialog.__init__(self)
self.ui = Ui_gazetteerSearch()
self.ui.setupUi(self)
self.ui.goButton.pressed.connect(self._doSearch)
self.ui.resultsList.itemActivated.connect(self._zoomTo)
def addGazetter(self, gazetter):
self.ui.gazzetterCombo.addItem(gazetter)
def selectedGazetteer(self):
return self.ui.gazzetterCombo.currentText()
def addResult(self, name):
self.hasErrors = False
item = QtGui.QListWidgetItem(name)
self.ui.resultsList.addItem(item)
def clearResults(self):
self.hasErrors = False
self.ui.resultsList.clear()
def hideGazetteers(self):
self.ui.gazzetterCombo.hide()
self.ui.label_2.hide()
def _doSearch(self):
self.clearResults()
self.runSearch.emit(self.ui.searchEdit.text(), self.selectedGazetteer())
def _zoomTo(self, item):
if self.hasErrors:
return
else:
self.zoomRequested.emit(item.text())
def addError(self, text):
self.hasErrors = True
item = QtGui.QListWidgetItem(text)
item.setIcon(QtGui.QIcon(":/plugins/gazetteersearch/warning.png"))
item.setTextAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter )
item.setForeground(QtCore.Qt.red)
self.ui.resultsList.addItem(item)