-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsettings.py
59 lines (50 loc) · 2.47 KB
/
settings.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
"""
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
import os
from qgis.PyQt import uic
from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
NOMURL = 'https://nominatim.openstreetmap.org'
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'settings.ui'))
class SettingsWidget(QDialog, FORM_CLASS):
def __init__(self, parent):
super(SettingsWidget, self).__init__(parent)
self.setupUi(self)
self.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked.connect(self.restore)
settings = QSettings()
self.nominatimURL = settings.value('/BulkNominatim/URL', NOMURL)
self.maxAddress = int(settings.value('/BulkNominatim/maxAddress', 100))
self.levelOfDetail = int(settings.value('/BulkNominatim/levelOfDetail', 18))
self.nomServiceLineEdit.setText(self.nominatimURL)
self.maxRequestSpinBox.setValue(self.maxAddress)
def accept(self):
'''Accept the settings and save them for next time.'''
settings = QSettings()
self.nominatimURL = self.nomServiceLineEdit.text().strip()
settings.setValue('/BulkNominatim/URL', self.nominatimURL)
try:
self.maxAddress = self.maxRequestSpinBox.value()
except:
self.maxAddress = 100
self.maxRequestSpinBox.setValue(self.maxAddress)
settings.setValue('/BulkNominatim/maxAddress', self.maxAddress)
self.levelOfDetail = self.detailSpinBox.value()
settings.setValue('/BulkNominatim/levelOfDetail', self.levelOfDetail)
self.close()
def restore(self):
self.nomServiceLineEdit.setText(NOMURL)
self.maxRequestSpinBox.setValue(100)
self.detailSpinBox.setValue(18)
def searchURL(self):
return self.nominatimURL + '/search.php'
def reverseURL(self):
return self.nominatimURL + '/reverse.php'