Skip to content

Commit

Permalink
Black format all files
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Sep 29, 2024
1 parent 004e5b8 commit 268c7f5
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 35 deletions.
20 changes: 16 additions & 4 deletions geest/gui/indicator_config_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class IndicatorConfigWidget(QWidget):
"""
Widget for configuring indicators based on a dictionary.
"""

data_changed = pyqtSignal(dict)

def __init__(self, attributes_dict: dict) -> None:
super().__init__()
self.attributes_dict = attributes_dict
Expand All @@ -18,7 +20,9 @@ def __init__(self, attributes_dict: dict) -> None:
try:
self.create_radio_buttons(attributes_dict)
except Exception as e:
QgsMessageLog.logMessage(f"Error in create_radio_buttons: {e}", tag="Geest", level=Qgis.Critical)
QgsMessageLog.logMessage(
f"Error in create_radio_buttons: {e}", tag="Geest", level=Qgis.Critical
)

self.setLayout(self.layout)

Expand All @@ -29,12 +33,17 @@ def create_radio_buttons(self, attributes_dict: dict) -> None:
analysis_mode = attributes_dict.get("Analysis Mode", "")
for key, value in attributes_dict.items():
radio_button_widget = RadioButtonFactory.create_radio_button(
key, value, attributes_dict)
key, value, attributes_dict
)
if radio_button_widget:
if key == analysis_mode:
radio_button_widget.setChecked(True)
# Special case for "Don't Use" radio button
if key == "Layer Required" and value == 0 and analysis_mode == "Don't Use":
if (
key == "Layer Required"
and value == 0
and analysis_mode == "Don't Use"
):
radio_button_widget.setChecked(True)
self.button_group.addButton(radio_button_widget)
self.layout.addWidget(radio_button_widget.get_container())
Expand All @@ -48,4 +57,7 @@ def update_attributes(self, new_data: dict) -> None:
self.attributes_dict.update(new_data)
self.data_changed.emit(self.attributes_dict)
QgsMessageLog.logMessage(
f"Updated attributes dictionary: {self.attributes_dict}", "Geest", level=Qgis.Info)
f"Updated attributes dictionary: {self.attributes_dict}",
"Geest",
level=Qgis.Info,
)
33 changes: 20 additions & 13 deletions geest/gui/indicator_widget_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,37 @@ class RadioButtonFactory:
"""
Factory class for creating radio buttons based on key-value pairs.
"""

@staticmethod
def create_radio_button(key: str, value: int, attributes: dict) -> BaseIndicatorWidget:
def create_radio_button(
key: str, value: int, attributes: dict
) -> BaseIndicatorWidget:
"""
Factory method to create a radio button based on key-value pairs.
"""
QgsMessageLog.logMessage("Dialog widget factory called", tag="Geest", level=Qgis.Info)
QgsMessageLog.logMessage("----------------------------", tag="Geest", level=Qgis.Info)
QgsMessageLog.logMessage(
"Dialog widget factory called", tag="Geest", level=Qgis.Info
)
QgsMessageLog.logMessage(
"----------------------------", tag="Geest", level=Qgis.Info
)
QgsMessageLog.logMessage(f"Key: {key}", tag="Geest", level=Qgis.Info)
QgsMessageLog.logMessage(f"Value: {value}", tag="Geest", level=Qgis.Info)
QgsMessageLog.logMessage("----------------------------", tag="Geest", level=Qgis.Info)
QgsMessageLog.logMessage(
"----------------------------", tag="Geest", level=Qgis.Info
)

try:
if key == "Layer Required" and value == 0:
return DontUseRadioButton(
label_text="Don't Use",
attributes=attributes
)
return DontUseRadioButton(label_text="Don't Use", attributes=attributes)
if key == "Use Default Index Score" and value == 1:
return IndexScoreRadioButton(
label_text=key,
attributes=attributes
)
return IndexScoreRadioButton(label_text=key, attributes=attributes)
else:
QgsMessageLog.logMessage(f"Factory did not match any widgets", tag="Geest", level=Qgis.Critical)
QgsMessageLog.logMessage(
f"Factory did not match any widgets",
tag="Geest",
level=Qgis.Critical,
)
return None
except Exception as e:
QgsMessageLog.logMessage(f"Error in create_radio_button: {e}", "Geest")
Expand Down
19 changes: 13 additions & 6 deletions geest/gui/layer_detail_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from geest.utilities import resources_path
from .indicator_config_widget import IndicatorConfigWidget


class LayerDetailDialog(QDialog):
"""Dialog to show layer properties, with a Markdown editor and preview for the 'indicator' field."""

Expand Down Expand Up @@ -242,7 +243,7 @@ def get_widget_for_value(self, key, value):

def add_config_widgets(self, layout):
if not self.editing:

self.config_widget = IndicatorConfigWidget(self.layer_data)
if self.config_widget:
layout.addWidget(self.config_widget)
Expand All @@ -251,12 +252,18 @@ def add_config_widgets(self, layout):
else:
QgsMessageLog.logMessage(
"No configuration widgets were created for this layer.",
tag="Geest", level=Qgis.CRITICAL)
tag="Geest",
level=Qgis.CRITICAL,
)

def handle_config_change(self, new_config):
"""Optionally handle configuration changes."""
self.layer_data = new_config
QgsMessageLog.logMessage(f"LayerDetailDialog config set to: {new_config}", tag="Geest", level=Qgis.Critical)
QgsMessageLog.logMessage(
f"LayerDetailDialog config set to: {new_config}",
tag="Geest",
level=Qgis.Critical,
)

def accept_changes(self):
"""Handle the OK button by applying changes and closing the dialog."""
Expand All @@ -268,9 +275,9 @@ def accept_changes(self):
updated_data = self.config_widget.attributes_dict

# Set 'Analysis Mode' based on the selected radio button
# Taken from IndicatorConfigWidget now
#selected_button = self.button_group.checkedButton()
#if selected_button:
# Taken from IndicatorConfigWidget now
# selected_button = self.button_group.checkedButton()
# if selected_button:
# updated_data["Analysis Mode"] = selected_button.text()

self.dataUpdated.emit(updated_data) # Emit the updated data as a dictionary
Expand Down
2 changes: 1 addition & 1 deletion geest/gui/tree_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def update_layer_data(updated_data):
# Check if the layer name has changed, and if so, update it in column 0
if updated_data.get("name", layer_name) != layer_name:
item.setData(0, updated_data.get("name", layer_name))

# Save the JSON data to the working directory
self.save_json_to_working_directory()

Expand Down
2 changes: 1 addition & 1 deletion geest/gui/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Widgets package initialization file
from .indicator_index_score_widget import IndexScoreRadioButton
from .dont_use_widget import DontUseRadioButton
from .dont_use_widget import DontUseRadioButton
13 changes: 8 additions & 5 deletions geest/gui/widgets/base_indicator_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class BaseIndicatorWidget(QRadioButton):
"""
Abstract base class for radio buttons with internal widgets.
"""

data_changed = pyqtSignal(dict)

def __init__(self, label_text: str, attributes: dict) -> None:
Expand All @@ -16,7 +17,7 @@ def __init__(self, label_text: str, attributes: dict) -> None:
self.container: QWidget = QWidget()
self.layout: QHBoxLayout = QHBoxLayout(self.container)
self.layout.addWidget(self)

# Log creation of widget
QgsMessageLog.logMessage(
"Creating Indicator Configuration Widget", tag="Geest", level=Qgis.Info
Expand All @@ -36,10 +37,10 @@ def __init__(self, label_text: str, attributes: dict) -> None:
self.add_internal_widgets()
except Exception as e:
QgsMessageLog.logMessage(f"Error in add_internal_widgets: {e}", "Geest")

# Connect toggled signal to enable/disable internal widgets
self.toggled.connect(self.on_toggled)

# Initially disable internal widgets if not checked
self.set_internal_widgets_enabled(self.isChecked())

Expand Down Expand Up @@ -79,7 +80,7 @@ def on_toggled(self, checked: bool) -> None:
Enables/disables internal widgets based on the radio button state.
"""
self.set_internal_widgets_enabled(checked)

# Emit data changed only if the radio button is checked
if checked:
self.update_data()
Expand All @@ -89,4 +90,6 @@ def set_internal_widgets_enabled(self, enabled: bool) -> None:
Enables or disables the internal widgets based on the radio button state.
To be implemented by subclasses to manage their internal widgets.
"""
raise NotImplementedError("Subclasses must implement set_internal_widgets_enabled.")
raise NotImplementedError(
"Subclasses must implement set_internal_widgets_enabled."
)
5 changes: 3 additions & 2 deletions geest/gui/widgets/dont_use_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class DontUseRadioButton(BaseIndicatorWidget):
"""
A specialized radio button with additional widgets for IndexScore.
"""

def add_internal_widgets(self) -> None:
"""
Adds internal widgets specific to Dont Use - in this case there are none.
"""
pass

def get_data(self) -> dict:
"""
Return the data as a dictionary, updating attributes with current value.
Expand All @@ -21,4 +22,4 @@ def set_internal_widgets_enabled(self, enabled: bool) -> None:
"""
Enables or disables the internal widgets based on the state of the radio button.
"""
pass
pass
11 changes: 9 additions & 2 deletions geest/gui/widgets/indicator_index_score_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class IndexScoreRadioButton(BaseIndicatorWidget):
"""
A specialized radio button with additional widgets for IndexScore.
"""

def add_internal_widgets(self) -> None:
"""
Adds internal widgets specific to IndexScore.
Expand All @@ -20,7 +21,9 @@ def add_internal_widgets(self) -> None:
# Connect the valueChanged signal to update data
self.index_input.valueChanged.connect(self.update_data)
except Exception as e:
QgsMessageLog.logMessage(f"Error in add_internal_widgets: {e}", "Geest", level=Qgis.Critical)
QgsMessageLog.logMessage(
f"Error in add_internal_widgets: {e}", "Geest", level=Qgis.Critical
)

def get_data(self) -> dict:
"""
Expand All @@ -38,4 +41,8 @@ def set_internal_widgets_enabled(self, enabled: bool) -> None:
self.info_label.setEnabled(enabled)
self.index_input.setEnabled(enabled)
except Exception as e:
QgsMessageLog.logMessage(f"Error in set_internal_widgets_enabled: {e}", "Geest", level=Qgis.Critical)
QgsMessageLog.logMessage(
f"Error in set_internal_widgets_enabled: {e}",
"Geest",
level=Qgis.Critical,
)
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ in pkgs.mkShell rec {
pythonPackages.numpy
pythonPackages.pip
pinnedPkgs.vim
pre-commit
git
qgis
qt5.full # so we get designer
Expand Down
4 changes: 3 additions & 1 deletion test/test_crs_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_no_conversion_needed(self):

# Check that the CRS remains the same
self.assertEqual(
reprojected_layer.crs().authid(), "EPSG:4326", "Layer CRS should remain unchanged!"
reprojected_layer.crs().authid(),
"EPSG:4326",
"Layer CRS should remain unchanged!",
)


Expand Down

0 comments on commit 268c7f5

Please sign in to comment.