Commit b7bddfe2 authored by Benjamin Jakimow's avatar Benjamin Jakimow

smaller fixes to run under QGIS 3.18

Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent 04a0b0af
......@@ -986,7 +986,7 @@ def showLayerPropertiesDialog(layer: QgsMapLayer,
if useQGISDialog and isinstance(iface, QgisInterface):
# try to use the QGIS vector layer properties dialog
try:
root = iface.layerTreeView().model().rootGroup()
root = iface.layerTreeView().layerTreeModel().rootGroup()
assert isinstance(root, QgsLayerTreeGroup)
temporaryGroup = None
lastActiveLayer = iface.activeLayer()
......
......@@ -25,7 +25,15 @@
"""
# noinspection PyPep8Naming
import re
import typing
class QGISMetadataFileWriter(object):
"""
A class to store and write the QGIS plugin metadata.txt
For details see:
https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/plugins/plugins.html#plugin-metadata-table
"""
def __init__(self):
self.mName = ''
......@@ -41,9 +49,11 @@ class QGISMetadataFileWriter(object):
self.mTracker = ''
self.mRepository = ''
self.mIsExperimental = ''
self.mTags = []
self.mCategory = ''
self.mChangelog = ''
self.mHasProcessingProvider: bool = False
self.mTags: typing.List[str] = []
self.mCategory: str = ''
self.mChangelog: str = ''
self.mPlugin_dependencies: typing.List[str] = []
def validate(self) -> bool:
......@@ -68,7 +78,10 @@ class QGISMetadataFileWriter(object):
lines.append('tags={}'.format(', '.join(self.mTags)))
lines.append('category={}'.format(self.mRepository))
if self.mHasProcessingProvider:
lines.append(f'hasProcessingProvider=yes')
else:
lines.append(f'hasProcessingProvider=no')
lines.append('homepage={}'.format(self.mHomepage))
if self.mTracker:
lines.append('tracker={}'.format(self.mTracker))
......@@ -77,12 +90,14 @@ class QGISMetadataFileWriter(object):
if isinstance(self.mIsExperimental, bool):
lines.append('experimental={}'.format(self.mIsExperimental))
#lines.append('deprecated={}'.format(self.mIsDeprecated))
if len(self.mPlugin_dependencies) > 0:
lines.append(f'plugin_dependencies={",".join(self.mPlugin_dependencies)}')
# lines.append('deprecated={}'.format(self.mIsDeprecated))
lines.append('')
lines.append('changelog={}'.format(self.mChangelog))
return '\n'.join(lines)
"""
[general]
name=dummy
......@@ -103,8 +118,6 @@ class QGISMetadataFileWriter(object):
category=Raster
"""
def writeMetadataTxt(self, path:str):
def writeMetadataTxt(self, path: str):
with open(path, 'w', encoding='utf-8') as f:
f.write(self.metadataString())
......@@ -14,7 +14,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
*
This program 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
......@@ -41,6 +41,7 @@ from qgis.PyQt.QtXml import *
from .utils import file_search, findUpwardPath
REGEX_FILEXTENSION_IMAGE = re.compile(r'\.([^.]+)$')
REGEX_QGIS_IMAGES_QRC = re.compile(r'.*QGIS[^\/]*[\/]images[\/]images\.qrc$')
def getDOMAttributes(elem):
......@@ -53,9 +54,14 @@ def getDOMAttributes(elem):
return values
def compileResourceFiles(dirRoot: str, targetDir: str = None, suffix: str = '_rc.py'):
def compileResourceFiles(dirRoot: str,
targetDir: str = None,
suffix: str = '_rc.py',
skip_qgis_images: bool = True):
"""
Searches for *.ui files and compiles the *.qrc files they use.
:param skip_qgis_images:
:type skip_qgis_images: bool, if True (default), qrc paths to the qgis images.qrc will be skipped
:param dirRoot: str, root directory, in which to search for *.qrc files or a list of *.ui file paths.
:param targetDir: str, output directory to write the compiled *.py files to.
Defaults to the *.qrc's directory
......@@ -82,6 +88,8 @@ def compileResourceFiles(dirRoot: str, targetDir: str = None, suffix: str = '_rc
location = attr['location']
qrc_path = (qrc_dir / pathlib.Path(location)).resolve()
if not qrc_path.exists():
if REGEX_QGIS_IMAGES_QRC.match(qrc_path.as_posix()) and skip_qgis_images:
continue
info = ['Broken *.qrc location in {}'.format(ui_file),
' `location="{}"`'.format(location)]
print('\n'.join(info), file=sys.stderr)
......@@ -221,8 +229,8 @@ def compileQGISResourceFiles(qgis_repo: str, target: str = None):
target = pathlib.Path(target)
os.makedirs(target, exist_ok=True)
compileResourceFiles(qgis_repo / 'src', targetDir=target)
compileResourceFiles(qgis_repo / 'images', targetDir=target)
compileResourceFiles(qgis_repo / 'src', targetDir=target, skip_qgis_images=False)
compileResourceFiles(qgis_repo / 'images', targetDir=target, skip_qgis_images=False)
def initQtResources(roots: list = []):
......@@ -310,7 +318,7 @@ def findQGISResourceFiles():
return results
def scanResources(path=':') -> str:
def scanResources(path=':') -> typing.Generator[str, None, None]:
"""Recursively returns file paths in directory"""
D = QDirIterator(path)
while D.hasNext():
......@@ -533,4 +541,3 @@ def showResources() -> ResourceBrowser:
if needQApp:
QApplication.instance().exec_()
return browser
......@@ -32,6 +32,7 @@ import re
import fnmatch
import io
import zipfile
import itertools
import pathlib
import warnings
import collections
......@@ -446,7 +447,7 @@ convertDateUnit = UnitLookup.convertDateUnit
METRIC_EXPONENTS = UnitLookup.METRIC_EXPONENTS
# contains the wavelenghts
# contains the wavelengths
LUT_WAVELENGTH = dict({'B': 480,
'G': 570,
'R': 660,
......@@ -549,7 +550,7 @@ def qgisLayerTreeLayers() -> list:
"""
iface = qgisAppQgisInterface()
if isinstance(iface, QgisInterface):
return [ln.layer() for ln in iface.layerTreeView().model().rootGroup().findLayers()
return [ln.layer() for ln in iface.layerTreeView().layerTreeModel().rootGroup().findLayers()
if isinstance(ln.layer(), QgsMapLayer)]
else:
return []
......@@ -779,8 +780,7 @@ def optimize_block_size(ds: gdal.Dataset,
def fid2pixelindices(raster: gdal.Dataset,
vector: ogr.DataSource,
layer: typing.Union[int, str] = None,
all_touched: bool = True) -> typing.Tuple[
np.ndarray, int]:
all_touched: bool = True) -> typing.Tuple[np.ndarray, int]:
"""
Returns vector feature pixel positions.
......@@ -1566,7 +1566,7 @@ def checkWavelength(key: str, values: str, expected: int = 1) -> np.ndarray:
else:
sep = ','
try:
wl = np.asarray(values.split(sep), dtype=np.float)
wl = np.asarray(values.split(sep), dtype=float)
if len(wl) != expected:
wl = None
# wl = np.fromstring(values, count=expected, sep=sep)
......@@ -1735,6 +1735,19 @@ def qgisAppQgisInterface() -> QgisInterface:
return None
def chunks(iterable, size=10):
"""
Returns list or generator output as chunks
Example taken from: https://stackoverflow.com/a/24527424
:param iterable:
:param size:
:return:
"""
iterator = iter(iterable)
for first in iterator:
yield itertools.chain([first], itertools.islice(iterator, size - 1))
def getDOMAttributes(elem) -> dict:
assert isinstance(elem, QDomElement)
values = dict()
......
......@@ -860,7 +860,7 @@ class MapViewLayerTreeViewMenuProvider(QgsLayerTreeViewMenuProvider):
return self.layerTreeModel().rootGroup()
def layerTreeModel(self) -> QgsLayerTreeModel:
return self.layerTreeView().model()
return self.layerTreeView().layerTreeModel()
def onRemoveLayers(self):
selected = self.layerTreeView().selectedLayers()
......
......@@ -28,7 +28,8 @@ def create_runtests():
::
@echo off
set CI=True
set PYTHONPATH=%~dp0/..;%PYTHONPATH%
set PYTHONPATH
WHERE python3 >nul 2>&1 && (
echo Found "python3" command
set PYTHON=python3
......
......@@ -95,6 +95,14 @@ class TestTimeSeries(EOTSVTestCase):
tsRel.loadFromFile(pathTSFileAbs, runAsync=False)
self.assertTrue(len(tsRel) == len(files))
def test_load_csv(self):
p = r'J:\diss_bj\QGISProjects\timeseries\mosaic_BOA_2014.txt'
if os.path.isfile(p):
ts = TimeSeries()
ts.loadFromFile(p, runAsync=False)
def test_TimeSeriesFindOverlapTask(self):
import example
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment