Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black ruff
pip install black "ruff==0.15.22"
- name: Autoformat with black
run: |
black .
Expand Down
4 changes: 2 additions & 2 deletions loopstructural/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def plugin_metadata_as_dict() -> dict:
config.read(PLG_METADATA_FILE.resolve(), encoding="UTF-8")
return {s: dict(config.items(s)) for s in config.sections()}
else:
raise IOError("Plugin metadata.txt not found at: %s" % PLG_METADATA_FILE)
raise OSError("Plugin metadata.txt not found at: %s" % PLG_METADATA_FILE)


# ############################################################################
Expand All @@ -66,7 +66,7 @@ def plugin_metadata_as_dict() -> dict:
__plugin_md__: dict = plugin_metadata_as_dict()

__author__: str = __plugin_md__.get("general").get("author")
__copyright__: str = "2024 - {0}, {1}".format(date.today().year, __author__)
__copyright__: str = f"2024 - {date.today().year}, {__author__}"
__email__: str = __plugin_md__.get("general").get("email")
__icon_path__: Path = DIR_PLUGIN_ROOT.resolve() / __plugin_md__.get("general").get("icon")
__keywords__: list = [
Expand Down
4 changes: 2 additions & 2 deletions loopstructural/debug_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ def log_params(self, context_label: str, params: Any):
"""
try:
self.plugin.log(
message=f"[map2loop] {context_label} parameters: {str(params)}",
message=f"[map2loop] {context_label} parameters: {params!s}",
log_level=0,
)
except Exception as err:
self.plugin.log(
message=(
f"[map2loop] {context_label} parameters (stringified due to {err}): {str(params)}"
f"[map2loop] {context_label} parameters (stringified due to {err}): {params!s}"
),
log_level=0,
)
Expand Down
20 changes: 20 additions & 0 deletions loopstructural/gui/compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# compat.py
from qgis.PyQt.QtCore import QVariant

try:
from qgis.PyQt.QtCore import QMetaType

# We create a proxy class to mimic the old QVariant.Type behavior
class QVariantProxy:
Type = QMetaType.Type
# Add common types here if needed
Int = QMetaType.Type.Int
Double = QMetaType.Type.Double
String = QMetaType.Type.QString
Bool = QMetaType.Type.Bool

# In QGIS 4, we use our proxy
QVariantCompat = QVariantProxy
except (ImportError, AttributeError):
# In QGIS 3, QVariant already has .Type
QVariantCompat = QVariant
3 changes: 2 additions & 1 deletion loopstructural/gui/data_conversion/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Iterable, MutableMapping
from copy import deepcopy
from typing import Any, Dict, Iterable, MutableMapping
from typing import Any, Dict


class Config:
Expand Down
11 changes: 6 additions & 5 deletions loopstructural/gui/data_conversion/data_conversion_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import os
import re
from collections.abc import Iterable, Mapping
from dataclasses import dataclass
from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple

from LoopDataConverter import Datatype, InputData, LoopConverter, SurveyName
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import (
from qgis.core import QgsMapLayerProxyModel, QgsProject, QgsVectorLayer
from qgis.gui import QgsMapLayerComboBox
from qgis.PyQt.QtCore import Qt, QTimer
from qgis.PyQt.QtWidgets import (
QComboBox,
QDialog,
QDialogButtonBox,
Expand All @@ -21,8 +24,6 @@
QVBoxLayout,
QWidget,
)
from qgis.core import QgsMapLayerProxyModel, QgsProject, QgsVectorLayer
from qgis.gui import QgsMapLayerComboBox

from ...main.helpers import ColumnMatcher
from ...main.vectorLayerWrapper import QgsLayerFromDataFrame, QgsLayerFromGeoDataFrame
Expand Down
6 changes: 3 additions & 3 deletions loopstructural/gui/dlg_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from qgis.core import Qgis, QgsApplication
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
from qgis.PyQt import uic
from qgis.PyQt.Qt import QUrl
from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QDesktopServices, QIcon

# project
Expand All @@ -30,7 +30,7 @@
# ########## Globals ###############
# ##################################

FORM_CLASS, _ = uic.loadUiType(Path(__file__).parent / "{}.ui".format(Path(__file__).stem))
FORM_CLASS, _ = uic.loadUiType(Path(__file__).parent / f"{Path(__file__).stem}.ui")


# ############################################################################
Expand All @@ -48,7 +48,7 @@ def __init__(self, parent):

# load UI and set objectName
self.setupUi(self)
self.setObjectName("mOptionsPage{}".format(__title__))
self.setObjectName(f"mOptionsPage{__title__}")

_report_context_message = quote(
"> Reported from plugin settings\n\n"
Expand Down
2 changes: 1 addition & 1 deletion loopstructural/gui/loop_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface for interacting with LoopStructural features inside QGIS.
"""

from PyQt5.QtWidgets import QTabWidget, QVBoxLayout, QWidget
from qgis.PyQt.QtWidgets import QTabWidget, QVBoxLayout, QWidget

from .modelling.modelling_widget import ModellingWidget
from .visualisation.visualisation_widget import VisualisationWidget
Expand Down
10 changes: 5 additions & 5 deletions loopstructural/gui/map2loop_tools/basal_contacts_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import os

from PyQt5.QtWidgets import QMessageBox, QWidget
from qgis.core import QgsProject, QgsVectorFileWriter
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QMessageBox, QWidget

from ...main.helpers import ColumnMatcher, get_layer_names
from ...main.m2l_api import extract_basal_contacts
Expand Down Expand Up @@ -277,11 +277,11 @@ def set_parameters(self, params):
params : dict
Dictionary of parameters to set.
"""
if 'geology_layer' in params and params['geology_layer']:
if params.get('geology_layer'):
self.geologyLayerComboBox.setLayer(params['geology_layer'])
if 'faults_layer' in params and params['faults_layer']:
if params.get('faults_layer'):
self.faultsLayerComboBox.setLayer(params['faults_layer'])
if 'ignore_units' in params and params['ignore_units']:
if params.get('ignore_units'):
self.ignoreUnitsLineEdit.setText(', '.join(params['ignore_units']))
if 'all_contacts' in params:
self.allContactsCheckBox.setChecked(params['all_contacts'])
Expand Down Expand Up @@ -310,7 +310,7 @@ def _is_null_like(v):
if v is None:
return True
# PyQGIS QVariant null check
if hasattr(v, "isNull") and callable(getattr(v, "isNull")) and v.isNull():
if hasattr(v, "isNull") and callable(v.isNull) and v.isNull():
return True
# Empty strings or literal "NULL" (case-insensitive)
if isinstance(v, str):
Expand Down
6 changes: 4 additions & 2 deletions loopstructural/gui/map2loop_tools/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
instead of QGIS processing algorithms.
"""

from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout


class SamplerDialog(QDialog):
Expand All @@ -23,7 +23,9 @@ def setup_ui(self):
from .sampler_widget import SamplerWidget

layout = QVBoxLayout(self)
self.widget = SamplerWidget(self, data_manager=self.data_manager, debug_manager=self.debug_manager)
self.widget = SamplerWidget(
self, data_manager=self.data_manager, debug_manager=self.debug_manager
)
layout.addWidget(self.widget)

# Replace the run button with dialog buttons
Expand Down
2 changes: 1 addition & 1 deletion loopstructural/gui/map2loop_tools/fault_topology_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os

import geopandas as gpd
from PyQt5.QtWidgets import QDialog, QMessageBox
from qgis.core import QgsMapLayerProxyModel
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog, QMessageBox


class FaultTopologyWidget(QDialog):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import os

from PyQt5.QtWidgets import QMessageBox, QWidget
from qgis.core import QgsMapLayerProxyModel
from qgis.PyQt import uic

from qgis.PyQt.QtWidgets import QMessageBox, QWidget

from ...main.m2l_api import paint_stratigraphic_order

Expand Down Expand Up @@ -41,7 +40,6 @@ def __init__(self, parent=None, data_manager=None, debug_manager=None):
try:
self.geologyLayerComboBox.setFilters(QgsMapLayerProxyModel.PolygonLayer)
# stratigraphic column layer removed from UI
pass
except Exception:
# If QGIS isn't available, skip filter setup
pass
Expand All @@ -61,7 +59,6 @@ def __init__(self, parent=None, data_manager=None, debug_manager=None):
if self._debug.is_debug():
raise e
# if QGIS unavailable, leave empty
pass

# Default: no duplication
try:
Expand Down Expand Up @@ -133,7 +130,6 @@ def _setup_field_combo_boxes(self):
"""Set up field combo boxes based on current layers."""
self._on_geology_layer_changed()
# stratigraphic column layer removed from UI
pass

def _on_geology_layer_changed(self):
"""Update unit name field combo box when geology layer changes."""
Expand Down Expand Up @@ -185,7 +181,6 @@ def _run_painter(self):

# Step 1: create a memory copy of the geology layer and copy attributes/geometry
try:
from PyQt5.QtCore import QVariant
from qgis.core import (
QgsFeature,
QgsField,
Expand All @@ -198,6 +193,8 @@ def _run_painter(self):
QgsWkbTypes,
)

from loopstructural.gui.compatibility import QVariantCompat

geom_type = QgsWkbTypes.displayString(geology_layer.wkbType())
crs_auth = (
geology_layer.crs().authid() if hasattr(geology_layer, 'crs') else None
Expand Down Expand Up @@ -240,7 +237,7 @@ def _run_painter(self):
try:
if field_name not in [f.name() for f in mem_layer.fields()]:
mem_layer.startEditing()
mem_dp.addAttributes([QgsField(field_name, QVariant.Int)])
mem_dp.addAttributes([QgsField(field_name, QVariantCompat.Int)])
mem_layer.updateFields()
mem_layer.commitChanges()

Expand Down
21 changes: 10 additions & 11 deletions loopstructural/gui/map2loop_tools/sampler_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import os

from PyQt5.QtWidgets import QMessageBox, QWidget
from qgis.core import QgsProject, QgsWkbTypes
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QMessageBox, QWidget

from loopstructural.toolbelt.preferences import PlgOptionsManager

Expand Down Expand Up @@ -190,7 +190,6 @@ def _on_spatial_layer_changed(self):
self.samplerTypeComboBox.setCurrentIndex(idx)
except Exception as e:
print(e)
pass
self.samplerTypeComboBox.setEnabled(False)
self.runButton.setEnabled(True)
elif geom_type == QgsWkbTypes.LineGeometry:
Expand All @@ -200,7 +199,6 @@ def _on_spatial_layer_changed(self):
self.samplerTypeComboBox.setCurrentIndex(idx)
except Exception as e:
print(e)
pass
self.samplerTypeComboBox.setEnabled(False)
self.runButton.setEnabled(False)
else:
Expand All @@ -226,7 +224,8 @@ def _run_sampler(self):
QgsPointXY,
QgsVectorLayer,
)
from qgis.PyQt.QtCore import QVariant

from loopstructural.gui.compatibility import QVariantCompat

from ...main.m2l_api import sample_contacts

Expand Down Expand Up @@ -293,11 +292,11 @@ def _run_sampler(self):
dtype_str = str(dtype)

if dtype_str in ['float16', 'float32', 'float64']:
field_type = QVariant.Double
field_type = QVariantCompat.Double
elif dtype_str in ['int8', 'int16', 'int32', 'int64']:
field_type = QVariant.Int
field_type = QVariantCompat.Int
else:
field_type = QVariant.String
field_type = QVariantCompat.String

fields.append(QgsField(column_name, field_type))

Expand Down Expand Up @@ -371,7 +370,7 @@ def _run_sampler(self):
)
if PlgOptionsManager.get_debug_mode():
raise e
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
QMessageBox.critical(self, "Error", f"An error occurred: {e!s}")
return False

def get_parameters(self):
Expand Down Expand Up @@ -401,11 +400,11 @@ def set_parameters(self, params):
"""
if 'sampler_type' in params:
self.samplerTypeComboBox.setCurrentIndex(params['sampler_type'])
if 'dtm_layer' in params and params['dtm_layer']:
if params.get('dtm_layer'):
self.dtmLayerComboBox.setLayer(params['dtm_layer'])
if 'geology_layer' in params and params['geology_layer']:
if params.get('geology_layer'):
self.geologyLayerComboBox.setLayer(params['geology_layer'])
if 'spatial_data_layer' in params and params['spatial_data_layer']:
if params.get('spatial_data_layer'):
self.spatialDataLayerComboBox.setLayer(params['spatial_data_layer'])
if 'decimation' in params:
self.decimationSpinBox.setValue(params['decimation'])
Expand Down
12 changes: 5 additions & 7 deletions loopstructural/gui/map2loop_tools/sorter_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import os

from PyQt5.QtWidgets import QMessageBox, QWidget
from qgis.core import QgsRasterLayer
from qgis.core import QgsMapLayerProxyModel

from qgis.core import QgsMapLayerProxyModel, QgsRasterLayer
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QMessageBox, QWidget

from loopstructural.main.helpers import get_layer_names
from loopstructural.main.m2l_api import PARAMETERS_DICTIONARY, SORTER_LIST
Expand Down Expand Up @@ -444,7 +442,7 @@ def _run_sorter(self):
)
if PlgOptionsManager.get_debug_mode():
raise e
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
QMessageBox.critical(self, "Error", f"An error occurred: {e!s}")
return False

def get_parameters(self):
Expand Down Expand Up @@ -486,7 +484,7 @@ def set_parameters(self, params):
"""
if 'sorting_algorithm' in params:
self.sortingAlgorithmComboBox.setCurrentIndex(params['sorting_algorithm'])
if 'geology_layer' in params and params['geology_layer']:
if params.get('geology_layer'):
self.geologyLayerComboBox.setLayer(params['geology_layer'])
if 'contacts_layer' in params and params['contacts_layer']:
if params.get('contacts_layer'):
self.contactsLayerComboBox.setLayer(params['contacts_layer'])
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os

import pandas as pd
from PyQt5.QtWidgets import QMessageBox, QWidget
from qgis.core import QgsMapLayerProxyModel
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QMessageBox, QWidget

from loopstructural.toolbelt.preferences import PlgOptionsManager

Expand Down Expand Up @@ -443,7 +443,7 @@ def _run_calculator(self):
)
if PlgOptionsManager.get_debug_mode():
raise e
QMessageBox.critical(self, "Error", f"An error occurred: {str(e)}")
QMessageBox.critical(self, "Error", f"An error occurred: {e!s}")
return False

def get_parameters(self):
Expand Down
Loading
Loading