diff --git a/src/geosearch_dk/Makefile b/src/geosearch_dk/Makefile index 9302d76..cfb8125 100644 --- a/src/geosearch_dk/Makefile +++ b/src/geosearch_dk/Makefile @@ -31,7 +31,7 @@ LOCALES = en # If locales are enabled, set the name of the lrelease binary on your system. If # you have trouble compiling the translations, you may have to specify the full path to # lrelease -LRELEASE = lrelease +LRELEASE = /usr/local/Cellar/qt/5.10.0_1/bin/lrelease #LRELEASE = lrelease-qt4 @@ -64,7 +64,7 @@ UI_FILES = \ EXTRAS = icon.png metadata.txt -COMPILED_RESOURCE_FILES = resources_rc.py +COMPILED_RESOURCE_FILES = PEP8EXCLUDE=pydev,resources_rc.py,conf.py,third_party,ui diff --git a/src/geosearch_dk/__init__.py b/src/geosearch_dk/__init__.py index a20482d..d0ec7eb 100644 --- a/src/geosearch_dk/__init__.py +++ b/src/geosearch_dk/__init__.py @@ -17,8 +17,9 @@ * * ***************************************************************************/ """ +from __future__ import absolute_import -import pluginmetadata +from . import pluginmetadata def name(): return pluginmetadata.metadata['name'] @@ -46,5 +47,5 @@ def email(): return pluginmetadata.metadata['email'] def classFactory(iface): - from septimageosearch import SeptimaGeoSearch + from .septimageosearch import SeptimaGeoSearch return SeptimaGeoSearch(iface) diff --git a/src/geosearch_dk/autosuggest.py b/src/geosearch_dk/autosuggest.py index 0019fba..26d4ab9 100644 --- a/src/geosearch_dk/autosuggest.py +++ b/src/geosearch_dk/autosuggest.py @@ -19,17 +19,13 @@ """ import sys -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from PyQt4.QtNetwork import * -from PyQt4.uic import loadUi -#import microjson - +from qgis.PyQt.QtCore import QObject, Qt, QEvent, QTimer, QPoint +from qgis.PyQt.QtWidgets import QTreeWidget, QTreeWidgetItem, QFrame, QApplication +from qgis.PyQt.QtGui import QPalette, QKeyEvent +from qgis.PyQt.QtNetwork import QNetworkReply, QNetworkRequest, QNetworkAccessManager +from qgis.PyQt.uic import loadUi from qgis.core import QgsMessageLog -#PLUGINNAME = "Septima Geo Search" - - # TODO: Add events to completer? http://www.valuedlessons.com/2008/04/events-in-python.html class AutoSuggest(QObject): @@ -131,7 +127,7 @@ def showCompletion(self, rows): item.setText(0, row[0]) #item.setText(1, hit['type']) item.setTextAlignment(1, Qt.AlignRight) - item.setTextColor(1, color) + item.setForeground(1, color) item.setData(2, Qt.UserRole, (row[1],)) # Try immutable py obj #http://stackoverflow.com/questions/9257422/how-to-get-the-original-python-data-from-qvariant self.popup.setCurrentItem(self.popup.topLevelItem(0)) @@ -179,8 +175,9 @@ def handleNetworkData(self, networkReply): #print "received url:", url.toString() if not networkReply.error(): response = networkReply.readAll() + pystring = str(response, 'utf-8') #print "Response: ", response - rows = self.parseresult_func( response ) + rows = self.parseresult_func( pystring ) self.showCompletion( rows ) networkReply.deleteLater() diff --git a/src/geosearch_dk/i18n/en.qm b/src/geosearch_dk/i18n/en.qm index 1426f20..212b75e 100644 Binary files a/src/geosearch_dk/i18n/en.qm and b/src/geosearch_dk/i18n/en.qm differ diff --git a/src/geosearch_dk/i18n/en.ts b/src/geosearch_dk/i18n/en.ts index cd7b587..5a82736 100644 --- a/src/geosearch_dk/i18n/en.ts +++ b/src/geosearch_dk/i18n/en.ts @@ -45,7 +45,7 @@ Filter - + Filter @@ -96,12 +96,12 @@ Geosearch DK - + &Indstillinger Settings - + &Om pluginet About @@ -109,18 +109,18 @@ SearchBox - + Geosearch DK lader brugeren zoome til navngivne steder i Danmark.<br />Pluginet benytter tjenesten 'geosearch' fra <a href="http://kortforsyningen.dk/">kortforsyningen.dk</a> og kræver derfor et gyldigt login til denne tjeneste.<br />Pluginets webside: <a href="http://github.com/Septima/qgis-geosearch">github.com/Septima/qgis-geosearch</a><br />Udviklet af: Septima<br />Mail: <a href="mailto:kontakt@septima.dk">kontakt@septima.dk</a><br />Web: <a href="http://www.septima.dk">www.septima.dk</a> Geosearch DK lets the user zoom to named places in Denmark.<br />The plugin uses the web service 'geosearch' by <a href="http://kortforsyningen.dk/">kortforsyningen.dk</a>. A valid login for this service is therefore needed.<br />Plugin web site: <a href="http://github.com/Septima/qgis-geosearch">github.com/Septima/qgis-geosearch</a><br />Made by: Septima<br />Mail: <a href="mailto:kontakt@septima.dk">kontakt@septima.dk</a><br />Web: <a href="http://www.septima.dk">www.septima.dk</a> - + Bruger afvist af Kortforsyningen User rejected by Kortforsyningen - + Manglende eller ukorrekt brugernavn og password til Kortforsyningen. Kortforsyningen svarede: @@ -131,12 +131,12 @@ Kortforsyningen responded: - + Søg adresse, stednavn, postnummer, matrikel m.m. Search Danish addresses, road names, place names, postal codes, land registry etc. - + Ingen resultater No results diff --git a/src/geosearch_dk/metadata.txt b/src/geosearch_dk/metadata.txt index 1a51740..010418b 100644 --- a/src/geosearch_dk/metadata.txt +++ b/src/geosearch_dk/metadata.txt @@ -10,11 +10,11 @@ [general] name=Geosearch DK -qgisMinimumVersion=2.8 -qgisMaximumVersion=2.99 +qgisMinimumVersion=3.0 +qgisMaximumVersion=3.98 description=Search and zoom to named places in Denmark about= Uses Kortforsyningen services for searching addresses, road names, place names, land registry and a lot more. Developed by Septima. -version=0.2.7 +version=1.0.0 author=Asger Skovbo Petersen, Septima email=asger@septima.dk @@ -23,7 +23,7 @@ email=asger@septima.dk # Optional items: # Uncomment the following line and add your changelog entries: -changelog= +changelog=2018-02-12 1.0.0 Migrate to QGIS3 2016-09-15 0.2.7 Make marker symbology customizable through QGIS global settings. 2016-04-21 0.2.6 Fix bug storing settings on some QGIS configurations. User needs to set municipality filter again after installing this version. 2016-01-25 0.2.5 Added the possibility to limit the search to adresses/placenames/cadstral numbers/etc. in the searchbox by using keywords or by specifying the resulttype in the settingsdialog. This work was funded by Ballerup Kommune. diff --git a/src/geosearch_dk/microjson.py b/src/geosearch_dk/microjson.py deleted file mode 100644 index 7bc3aad..0000000 --- a/src/geosearch_dk/microjson.py +++ /dev/null @@ -1,373 +0,0 @@ - -# microjson - Minimal JSON parser/emitter for use in standalone scripts. -# No warranty. Free to use/modify as you see fit. Trades speed for compactness. -# Send ideas, bugs, simplifications to http://github.com/phensley -# Copyright (c) 2010 Patrick Hensley - -# std -import math -import StringIO -import types - - -# the '_from_json_number' function returns either float or long. -__pychecker__ = 'no-returnvalues' - -# character classes -WS = set([' ','\t','\r','\n','\b','\f']) -DIGITS = set([str(i) for i in range(0, 10)]) -NUMSTART = DIGITS.union(['.','-','+']) -NUMCHARS = NUMSTART.union(['e','E']) -ESC_MAP = {'n':'\n','t':'\t','r':'\r','b':'\b','f':'\f'} -REV_ESC_MAP = dict([(_v,_k) for _k,_v in ESC_MAP.items()] + [('"','"')]) - -# error messages -E_BYTES = 'input string must be type str containing ASCII or UTF-8 bytes' -E_MALF = 'malformed JSON data' -E_TRUNC = 'truncated JSON data' -E_BOOL = 'expected boolean' -E_NULL = 'expected null' -E_LITEM = 'expected list item' -E_DKEY = 'expected key' -E_COLON = 'missing colon after key' -E_EMPTY = 'found empty string, not valid JSON data' -E_BADESC = 'bad escape character found' -E_UNSUPP = 'unsupported type "%s" cannot be JSON-encoded' -E_BADFLOAT = 'cannot emit floating point value "%s"' - - -class JSONError(Exception): - def __init__(self, msg, stm=None, pos=0): - if stm: - msg += ' at position %d, "%s"' % (pos, repr(stm.substr(pos, 32))) - Exception.__init__(self, msg) - - -class JSONStream(object): - - # no longer inherit directly from StringIO, since we only want to - # expose the methods below and not allow direct access to the - # underlying stream. - - def __init__(self, data): - self._stm = StringIO.StringIO(data) - - @property - def pos(self): - return self._stm.pos - - @property - def len(self): - return self._stm.len - - def getvalue(self): - return self._stm.getvalue() - - def skipspaces(self): - "post-cond: read pointer will be over first non-WS char" - self._skip(lambda c: c not in WS) - - def _skip(self, stopcond): - while True: - c = self.peek() - if stopcond(c) or c == '': - break - self.next() - - def next(self, size=1): - return self._stm.read(size) - - def next_ord(self): - return ord(self.next()) - - def peek(self): - if self.pos == self.len: - return '' - return self.getvalue()[self.pos] - - def substr(self, pos, length): - return self.getvalue()[pos:pos+length] - - -def _decode_utf8(c0, stm): - c0 = ord(c0) - r = 0xFFFD # unicode replacement character - nc = stm.next_ord - - # 110yyyyy 10zzzzzz - if (c0 & 0xE0) == 0xC0: - r = ((c0 & 0x1F) << 6) + (nc() & 0x3F) - - # 1110xxxx 10yyyyyy 10zzzzzz - elif (c0 & 0xF0) == 0xE0: - r = ((c0 & 0x0F) << 12) + ((nc() & 0x3F) << 6) + (nc() & 0x3F) - - # 11110www 10xxxxxx 10yyyyyy 10zzzzzz - elif (c0 & 0xF8) == 0xF0: - r = ((c0 & 0x07) << 18) + ((nc() & 0x3F) << 12) + \ - ((nc() & 0x3F) << 6) + (nc() & 0x3F) - return unichr(r) - - -def decode_escape(c, stm): - # whitespace - v = ESC_MAP.get(c, None) - if v is not None: - return v - - # plain character - elif c != 'u': - return c - - # decode unicode escape \u1234 - sv = 12 - r = 0 - for _ in range(0, 4): - r |= int(stm.next(), 16) << sv - sv -= 4 - return unichr(r) - - -def _from_json_string(stm): - # skip over '"' - stm.next() - r = [] - while True: - c = stm.next() - if c == '': - raise JSONError(E_TRUNC, stm, stm.pos - 1) - elif c == '\\': - c = stm.next() - r.append(decode_escape(c, stm)) - elif c == '"': - return ''.join(r) - elif c > '\x7f': - r.append(_decode_utf8(c, stm)) - else: - r.append(c) - - -def _from_json_fixed(stm, expected, value, errmsg): - off = len(expected) - pos = stm.pos - if stm.substr(pos, off) == expected: - stm.next(off) - return value - raise JSONError(errmsg, stm, pos) - - -def _from_json_number(stm): - # Per rfc 4627 section 2.4 '0' and '0.1' are valid, but '01' and - # '01.1' are not, presumably since this would be confused with an - # octal number. This rule is not enforced. - is_float = 0 - saw_exp = 0 - pos = stm.pos - while True: - c = stm.peek() - - if c not in NUMCHARS: - break - elif c == '-' and not saw_exp: - pass - elif c in ('.','e','E'): - is_float = 1 - if c in ('e','E'): - saw_exp = 1 - stm.next() - - s = stm.substr(pos, stm.pos - pos) - if is_float: - return float(s) - return long(s) - - -def _from_json_list(stm): - # skip over '[' - stm.next() - result = [] - pos = stm.pos - while True: - stm.skipspaces() - c = stm.peek() - if c == '': - raise JSONError(E_TRUNC, stm, pos) - - elif c == ']': - stm.next() - return result - - elif c == ',': - stm.next() - result.append(_from_json_raw(stm)) - continue - - elif not result: - # first item - result.append(_from_json_raw(stm)) - continue - - else: - raise JSONError(E_MALF, stm, stm.pos) - - -def _from_json_dict(stm): - # skip over '{' - stm.next() - result = {} - expect_key = 0 - pos = stm.pos - while True: - stm.skipspaces() - c = stm.peek() - if c == '': - raise JSONError(E_TRUNC, stm, pos) - - # end of dictionary, or next item - if c in ('}',','): - stm.next() - if expect_key: - raise JSONError(E_DKEY, stm, stm.pos) - if c == '}': - return result - expect_key = 1 - continue - - # parse out a key/value pair - elif c == '"': - key = _from_json_string(stm) - stm.skipspaces() - c = stm.next() - if c != ':': - raise JSONError(E_COLON, stm, stm.pos) - - stm.skipspaces() - val = _from_json_raw(stm) - result[key] = val - expect_key = 0 - continue - - # unexpected character in middle of dict - raise JSONError(E_MALF, stm, stm.pos) - - -def _from_json_raw(stm): - while True: - stm.skipspaces() - c = stm.peek() - if c == '"': - return _from_json_string(stm) - elif c == '{': - return _from_json_dict(stm) - elif c == '[': - return _from_json_list(stm) - elif c == 't': - return _from_json_fixed(stm, 'true', True, E_BOOL) - elif c == 'f': - return _from_json_fixed(stm, 'false', False, E_BOOL) - elif c == 'n': - return _from_json_fixed(stm, 'null', None, E_NULL) - elif c in NUMSTART: - return _from_json_number(stm) - - raise JSONError(E_MALF, stm, stm.pos) - - -def from_json(data): - """ - Converts 'data' which is UTF-8 (or the 7-bit pure ASCII subset) into - a Python representation. You must pass bytes to this in a str type, - not unicode. - """ - if not isinstance(data, str): - raise JSONError(E_BYTES) - if not data: - return None - stm = JSONStream(data) - return _from_json_raw(stm) - - -# JSON emitter - -def _to_json_list(stm, lst): - seen = 0 - stm.write('[') - for elem in lst: - if seen: - stm.write(',') - seen = 1 - _to_json_object(stm, elem) - stm.write(']') - - -def _to_json_string(stm, buf): - stm.write('"') - for c in buf: - nc = REV_ESC_MAP.get(c, None) - if nc: - stm.write('\\' + nc) - elif ord(c) <= 0x7F: - # force ascii - stm.write(str(c)) - else: - stm.write('\\u%04x' % ord(c)) - stm.write('"') - - -def _to_json_dict(stm, dct): - seen = 0 - stm.write('{') - for key in dct.keys(): - if seen: - stm.write(',') - seen = 1 - val = dct[key] - if not type(key) in (types.StringType, types.UnicodeType): - key = str(key) - _to_json_string(stm, key) - stm.write(':') - _to_json_object(stm, val) - stm.write('}') - - -def _to_json_object(stm, obj): - if isinstance(obj, (types.ListType, types.TupleType)): - _to_json_list(stm, obj) - elif isinstance(obj, types.BooleanType): - if obj: - stm.write('true') - else: - stm.write('false') - elif isinstance(obj, types.FloatType): - if math.isnan(obj) or math.isinf(obj): - raise JSONError(E_BADFLOAT % obj) - stm.write("%s" % obj) - elif isinstance(obj, (types.IntType, types.LongType)): - stm.write("%d" % obj) - elif isinstance(obj, types.NoneType): - stm.write('null') - elif isinstance(obj, (types.StringType, types.UnicodeType)): - _to_json_string(stm, obj) - elif hasattr(obj, 'keys') and hasattr(obj, '__getitem__'): - _to_json_dict(stm, obj) - # fall back to implicit string conversion. - elif hasattr(obj, '__unicode__'): - _to_json_string(stm, obj.__unicode__()) - elif hasattr(obj, '__str__'): - _to_json_string(stm, obj.__str__()) - else: - raise JSONError(E_UNSUPP % type(obj)) - - -def to_json(obj): - """ - Converts 'obj' to an ASCII JSON string representation. - """ - stm = StringIO.StringIO('') - _to_json_object(stm, obj) - return stm.getvalue() - - -decode = from_json -encode = to_json - diff --git a/src/geosearch_dk/pluginmetadata.py b/src/geosearch_dk/pluginmetadata.py index ae23535..51bb548 100644 --- a/src/geosearch_dk/pluginmetadata.py +++ b/src/geosearch_dk/pluginmetadata.py @@ -17,8 +17,11 @@ * * ***************************************************************************/ """ +from __future__ import print_function -import ConfigParser +from future import standard_library +standard_library.install_aliases() +import configparser import codecs import os @@ -27,7 +30,7 @@ def plugin_metadata(): global metadata if metadata is None: - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.readfp(codecs.open( os.path.dirname( __file__ ).replace("\\", "/") + '/metadata.txt', 'r', 'utf8')) metadata = dict( config.items('general') ) return metadata @@ -35,7 +38,8 @@ def plugin_metadata(): metadata = plugin_metadata() def main(): - print plugin_metadata() + # fix_print_with_import + print(plugin_metadata()) if __name__ == '__main__': main() \ No newline at end of file diff --git a/src/geosearch_dk/resources_rc.py b/src/geosearch_dk/resources_rc.py deleted file mode 100644 index af12621..0000000 --- a/src/geosearch_dk/resources_rc.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- - -# Resource object code -# -# Created: Fri Oct 16 15:47:47 2015 -# by: The Resource Compiler for PyQt (Qt v4.8.6) -# -# WARNING! All changes made in this file will be lost! - -from PyQt4 import QtCore - -qt_resource_data = "\ -\x00\x00\x01\x30\ -\x89\ -\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ -\x00\x00\x18\x00\x00\x00\x18\x08\x06\x00\x00\x00\xe0\x77\x3d\xf8\ -\x00\x00\x00\x01\x73\x52\x47\x42\x00\xae\xce\x1c\xe9\x00\x00\x00\ -\xea\x49\x44\x41\x54\x48\x0d\xed\x54\xb1\x0e\x82\x30\x10\x7d\x95\ -\x12\xc0\x04\x17\x37\xc5\xc5\x5f\x31\xfe\x95\x0b\x83\xb3\xd1\xc4\ -\xbf\xd0\xe8\xe8\xa4\x8b\x5f\xa0\x8b\xf1\x4b\x20\x48\x2b\x90\x90\ -\x86\xe4\xa0\x90\xc0\xd6\x2e\xbd\xbb\xf7\x72\x0f\x5e\xdb\x63\xc9\ -\x7c\x29\x41\xad\x34\x05\x82\x39\xf8\xfd\x06\xf8\x3e\x44\xb8\x85\ -\x38\x1c\x01\xcf\xa3\xd8\xb5\xb5\x51\x2d\x52\x02\xb4\x7c\x89\x6a\ -\x77\xbd\x80\xb6\x45\x33\xc1\x08\x34\xfb\x93\xa1\xc6\x22\xad\x45\ -\x1c\x51\x44\x93\xf2\x87\x16\xc7\x0a\x4b\x7e\x28\xb8\x8c\xa9\x5a\ -\x8b\x88\x89\xd3\x85\x7e\x4a\x32\x2b\x8f\x3d\xb0\xf5\x0a\xb0\x6d\ -\xc8\xd7\x1b\xf8\x7c\x01\xcb\x6a\xd1\x56\x51\x98\xcc\x96\x4a\xfb\ -\x8f\x06\xbf\x45\x5c\x9e\xaf\xf4\x67\xf7\x65\x51\x32\x9d\xd1\x16\ -\xe5\x87\xbc\x08\xc0\x9f\x0f\x60\x92\x4d\xd3\x4d\x08\xb1\xdb\x77\ -\x9e\xa6\x1c\xae\x4b\xff\x41\x2e\xe0\x38\x0a\xb3\x39\x0a\x6e\x1d\ -\x5f\x31\x2b\xd1\xe0\x67\x60\x04\x2a\x7e\x53\x89\xb1\x88\x72\xa5\ -\x52\xd3\x5b\xd4\x6d\x78\x56\x9a\xe7\xc9\x1f\xb6\x2b\x39\x47\x38\ -\xd2\x12\x4c\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82\ -" - -qt_resource_name = "\ -\x00\x07\ -\x07\x3b\xe0\xb3\ -\x00\x70\ -\x00\x6c\x00\x75\x00\x67\x00\x69\x00\x6e\x00\x73\ -\x00\x0c\ -\x05\x31\x36\xcb\ -\x00\x67\ -\x00\x65\x00\x6f\x00\x73\x00\x65\x00\x61\x00\x72\x00\x63\x00\x68\x00\x5f\x00\x64\x00\x6b\ -\x00\x08\ -\x0a\x61\x5a\xa7\ -\x00\x69\ -\x00\x63\x00\x6f\x00\x6e\x00\x2e\x00\x70\x00\x6e\x00\x67\ -" - -qt_resource_struct = "\ -\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ -\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ -\x00\x00\x00\x14\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\ -\x00\x00\x00\x32\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ -" - -def qInitResources(): - QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) - -def qCleanupResources(): - QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) - -qInitResources() diff --git a/src/geosearch_dk/scripts/update-strings.sh b/src/geosearch_dk/scripts/update-strings.sh index 8c960a5..ece5a25 100755 --- a/src/geosearch_dk/scripts/update-strings.sh +++ b/src/geosearch_dk/scripts/update-strings.sh @@ -48,7 +48,7 @@ then echo "i18n/"${LOCALE}".ts" # Note we don't use pylupdate with qt .pro file approach as it is flakey # about what is made available. - pylupdate4 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts + pylupdate5 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts done else echo "No need to edit any translation files (.ts) because no python files" diff --git a/src/geosearch_dk/searchbox.py b/src/geosearch_dk/searchbox.py index 4427c6a..7297140 100644 --- a/src/geosearch_dk/searchbox.py +++ b/src/geosearch_dk/searchbox.py @@ -17,6 +17,9 @@ * * ***************************************************************************/ """ +from __future__ import absolute_import +from builtins import map +from builtins import str BASEURL = "http://kortforsyningen.kms.dk/Geosearch?service=GEO&resources={resources}&area={area}&limit={limit}&login={login}&password={password}&callback={callback}&search=" RESOURCES = "Adresser,Stednavne_v2,Postdistrikter,Matrikelnumre,Kommuner,Opstillingskredse,Politikredse,Regioner,Retskredse" @@ -31,21 +34,22 @@ 'reg': {'id':'Regioner', 'titel':'Regioner', 'checkbox':'regCheckbox'} } -from PyQt4.QtGui import * -from PyQt4.QtCore import * -from PyQt4 import uic +from qgis.PyQt.QtWidgets import QFrame, QMessageBox +from qgis.PyQt.QtGui import QColor +from qgis.PyQt.QtCore import QSettings, QUrl +from qgis.PyQt import uic -from qgis.core import * -from qgis.gui import * +from qgis.core import QgsWkbTypes, QgsGeometry, QgsCoordinateReferenceSystem, QgsCoordinateTransform, QgsProject, QgsApplication +from qgis.gui import QgsVertexMarker, QgsRubberBand -import microjson +import json import os import re -import qgisutils -from autosuggest import AutoSuggest +from . import qgisutils +from .autosuggest import AutoSuggest # from ui_search import Ui_searchForm -import settingsdialog +from . import settingsdialog FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui_search.ui') @@ -74,11 +78,12 @@ def __init__(self, qgisIface): self.searchEdit.returnPressed.connect(self.doSearch) self.searchEdit.cleared.connect( self.clearMarkerGeom ) if hasattr(self.searchEdit, 'setPlaceholderText'): - self.searchEdit.setPlaceholderText(self.trUtf8(u"Søg adresse, stednavn, postnummer, matrikel m.m.")) + self.searchEdit.setPlaceholderText(self.tr(u"Søg adresse, stednavn, postnummer, matrikel m.m.")) # Listen to crs changes self.qgisIface.mapCanvas().destinationCrsChanged.connect(self.setupCrsTransform) - self.qgisIface.mapCanvas().hasCrsTransformEnabledChanged.connect(self.setupCrsTransform) + # From 3 CRS transform is always enabled + # self.qgisIface.mapCanvas().hasCrsTransformEnabledChanged.connect(self.setupCrsTransform) self.adjustSize() self.resize(50, self.height()) @@ -90,7 +95,7 @@ def readconfig(self): # Handle old muncodes storage, where it was stored as a list muncodes = s.value(k + "/muncodes", "") - if not isinstance(muncodes, basestring): + if not isinstance(muncodes, str): muncodes = "" muncodes = re.findall(r'\d+', muncodes) @@ -134,7 +139,7 @@ def geturl(self, searchterm): split = searchterm.split(':') if len(split)>1: first3letters_lowerCase = split[0][0:3].lower() - if first3letters_lowerCase in RESOURCESdic.keys(): + if first3letters_lowerCase in list(RESOURCESdic.keys()): req_resources = RESOURCESdic[first3letters_lowerCase]['id'] searchterm = split[1].lstrip() if not searchterm: @@ -156,41 +161,40 @@ def geturl(self, searchterm): def parseresponse(self, response): # Trim callback - result = str(response)[len(self.config['callback']) + 1: -1] - # print result + result = response[len(self.config['callback']) + 1: -1] try: - obj = microjson.from_json(result) - except microjson.JSONError: - QgsMessageLog.logMessage( + obj = json.loads(result) + except: + QgsApplication.messageLog().logMessage( 'Invalid JSON response from server: ' + result, __package__ ) # Check if we have an auth error - if 'User not found' in response or \ - 'User not authenticated' in response: - title = self.trUtf8(u'Bruger afvist af Kortforsyningen') - msg = self.trUtf8(u'Manglende eller ukorrekt brugernavn og password til Kortforsyningen.\n\nKortforsyningen svarede:\n') - QMessageBox.warning( None, title, msg + str(response)) + if 'User not found' in strresponse or \ + 'User not authenticated' in strresponse: + title = self.tr(u'Bruger afvist af Kortforsyningen') + msg = self.tr(u'Manglende eller ukorrekt brugernavn og password til Kortforsyningen.\n\nKortforsyningen svarede:\n') + QMessageBox.warning( None, title, msg + strresponse) # Now show settings dialog self.show_settings_dialog() return None if 'status' not in obj: - QgsMessageLog.logMessage( + QgsApplication.messageLog().logMessage( 'Unexpected result from server: ' + result, __package__ ) return None if not obj['status'] == 'OK': - QgsMessageLog.logMessage( + QgsApplication.messageLog().logMessage( 'Server reported an error: ' + obj['message'], __package__ ) return None - if not obj.has_key("data"): + if "data" not in obj: return None data = obj['data'] if not data: - return [(self.trUtf8("Ingen resultater"),None)] + return [(self.tr("Ingen resultater"),None)] # Make tuple with ("text", object) for each result return [(e['presentationString'], e) for e in data] @@ -201,7 +205,7 @@ def setupCrsTransform(self): 25832, QgsCoordinateReferenceSystem.EpsgCrsId ) dstCrs = qgisutils.getCurrentCrs(self.qgisIface) - self.crsTransform = QgsCoordinateTransform(srcCrs, dstCrs) + self.crsTransform = QgsCoordinateTransform(srcCrs, dstCrs, QgsProject.instance()) def setMarkerGeom(self, geom): # Show geometry @@ -214,9 +218,9 @@ def _setMarkerGeom(self, geom): for g in geometries: self._setMarkerGeom(g) else: - if geom.wkbType() == QGis.WKBPoint: + if QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PointGeometry: m = self._setPointMarker(geom) - elif geom.wkbType() in (QGis.WKBLineString, QGis.WKBPolygon): + elif QgsWkbTypes.geometryType(geom.wkbType()) in (QgsWkbTypes.LineGeometry, QgsWkbTypes.PolygonGeometry): m = self._setRubberBandMarker(geom) self.markers.append( m ) @@ -231,12 +235,12 @@ def _setPointMarker(self, pointgeom): def _setRubberBandMarker(self, geom): m = QgsRubberBand(self.qgisIface.mapCanvas(), False) # not polygon - if geom.wkbType() == QGis.WKBLineString: + if QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.LineGeometry: linegeom = geom - elif geom.wkbType() == QGis.WKBPolygon: - linegeom = QgsGeometry.fromPolyline(geom.asPolygon()[0]) + elif QgsWkbTypes.geometryType(geom.wkbType()) == QgsWkbTypes.PolygonGeometry: + linegeom = QgsGeometry.fromPolylineXY(geom.asPolygon()[0]) m.setToGeometry(linegeom, None) - m.setBorderColor(QColor(self.config['rubber_color'])) + m.setColor(QColor(self.config['rubber_color'])) m.setWidth(self.config['rubber_width']) return m @@ -296,7 +300,7 @@ def show_settings_dialog(self): dlg.loginLineEdit.setText(self.config['username']) dlg.passwordLineEdit.setText(self.config['password']) dlg.kommunekoderLineEdit.setText(','.join(map(str, self.config['muncodes']))) - for dic in RESOURCESdic.values(): + for dic in list(RESOURCESdic.values()): cb = getattr(dlg,dic['checkbox']) if dic['id'] in self.config['resources']: cb.setCheckState(2) @@ -312,7 +316,7 @@ def show_settings_dialog(self): self.config['password'] = str(dlg.passwordLineEdit.text()) self.config['muncodes'] = [k for k in dlg.kommunekoderLineEdit.text().split(',') if not k.strip() == ''] resources_list = [] - for dic in sorted(RESOURCESdic.values()): + for dic in RESOURCESdic.values(): cb = getattr(dlg,dic['checkbox']) if cb.isChecked(): resources_list.append(dic['id']) @@ -321,7 +325,7 @@ def show_settings_dialog(self): self.updateconfig() def show_about_dialog(self): - infoString = self.trUtf8( + infoString = self.tr( u"Geosearch DK lader brugeren zoome til navngivne steder i Danmark.
" u"Pluginet benytter tjenesten 'geosearch' fra kortforsyningen.dk" u" og kræver derfor et gyldigt login til denne tjeneste.
" diff --git a/src/geosearch_dk/septimageosearch.py b/src/geosearch_dk/septimageosearch.py index 597bf81..adce423 100644 --- a/src/geosearch_dk/septimageosearch.py +++ b/src/geosearch_dk/septimageosearch.py @@ -17,26 +17,29 @@ * * ***************************************************************************/ """ +from __future__ import absolute_import # Import the PyQt and QGIS libraries -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from qgis.core import * +from builtins import object +from qgis.PyQt.QtCore import QFileInfo, QSettings, QTranslator, qVersion, Qt +from qgis.PyQt.QtWidgets import QDockWidget, QAction +from qgis.PyQt.QtGui import QIcon +from qgis.core import QgsApplication, QCoreApplication # Initialize Qt resources from file resources.py -import resources_rc +# from . import resources_rc # Import the code for the dialog -from searchbox import SearchBox +from .searchbox import SearchBox -class SeptimaGeoSearch: +class SeptimaGeoSearch(object): def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface # initialize plugin directory - self.plugin_dir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/" + __package__ + self.plugin_dir = QFileInfo(QgsApplication.qgisUserDatabaseFilePath()).path() + "/python/plugins/" + __package__ # config self.config = QSettings() diff --git a/src/geosearch_dk/settingsdialog.py b/src/geosearch_dk/settingsdialog.py index 75bc2da..655e455 100644 --- a/src/geosearch_dk/settingsdialog.py +++ b/src/geosearch_dk/settingsdialog.py @@ -18,9 +18,10 @@ ***************************************************************************/ """ import os -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from PyQt4 import uic +from qgis.PyQt.QtCore import QRegExp, Qt +from qgis.PyQt.QtWidgets import QDialog +from qgis.PyQt.QtGui import QRegExpValidator +from qgis.PyQt import uic FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui_settings.ui'))