Skip to content

Commit

Permalink
Some small Python fixes about Qt, Python and Processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Aug 20, 2024
1 parent b005947 commit 2674179
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions dynamic_layers/core/layer_datasource_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from qgis.core import (
QgsFeature,
QgsMapLayer,
QgsProcessingException,
QgsProject,
QgsReadWriteContext,
QgsVectorLayer,
)
from qgis.PyQt.QtXml import QDomDocument

from dynamic_layers.definitions import CustomProperty
from dynamic_layers.tools import string_substitution
from dynamic_layers.tools import string_substitution, tr


class LayerDataSourceModifier:
Expand Down Expand Up @@ -51,7 +52,9 @@ def compute_new_uri(self, search_and_replace_dictionary: dict = None):
)

if not new_uri:
raise Exception(f"New URI invalid : {new_uri}")
raise QgsProcessingException(tr(
"New URI is invalid. Was it a valid QGIS expression ?"
) + " " + str(new_uri))

# Set the layer datasource
self.set_data_source(new_uri)
Expand Down
10 changes: 5 additions & 5 deletions dynamic_layers/dynamic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from functools import partial
from pathlib import Path
from typing import Optional

from qgis import processing
from qgis.core import (
Expand Down Expand Up @@ -356,7 +357,7 @@ def populate_layer_table(self):
self.dlg.twLayers.setItem(tw_row_count, i, new_item)

@staticmethod
def get_layer_property(layer: QgsMapLayer, prop: str) -> str | None:
def get_layer_property(layer: QgsMapLayer, prop: str) -> Optional[str]:
"""
Get a layer property
"""
Expand Down Expand Up @@ -766,9 +767,9 @@ def on_copy_from_project_clicked(self):
self.project.writeEntry(WmsProjectProperty.Capabilities, "/", True)

self.dlg.inProjectTitle.setText(f"'{p_title}'" if self.is_expression else p_title)
self.dlg.inProjectAbstract.setText(f"'{p_abstract}'" if self.is_expression else p_abstract)
self.dlg.inProjectAbstract.setPlainText(f"'{p_abstract}'" if self.is_expression else p_abstract)

def on_project_property_changed(self, prop: str) -> str | None:
def on_project_property_changed(self, prop: str) -> Optional[str]:
"""
Save project dynamic property in the project
when the user changes the content
Expand Down Expand Up @@ -879,11 +880,10 @@ def on_apply_variables_clicked(self):
def generate_projects_clicked():
""" Open the Processing algorithm dialog. """
# noinspection PyUnresolvedReferences
dialog = processing.createAlgorithmDialog(
processing.execAlgorithmDialog(
"dynamic_layers:generate_projects",
{}
)
dialog.show()

def run(self):
"""Run method that performs all the real work"""
Expand Down

0 comments on commit 2674179

Please sign in to comment.