Skip to content

Commit 10abd6f

Browse files
authored
Merge pull request #42 from Loop3D/docstring/numpy-style
Docstring/numpy style
2 parents 46b0c0f + 7783eeb commit 10abd6f

File tree

21 files changed

+470
-240
lines changed

21 files changed

+470
-240
lines changed

loopstructural/__about__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#! python3
22

3-
"""Metadata about the package to easily retrieve informations about it.
4-
See: https://packaging.python.org/guides/single-sourcing-package-version/
3+
"""Package metadata.
4+
5+
Contains package metadata constants used by the plugin (title, icon, etc.).
56
"""
67

78
# ############################################################################
@@ -36,13 +37,17 @@
3637
# ########## Functions #############
3738
# ##################################
3839
def plugin_metadata_as_dict() -> dict:
39-
"""Read plugin metadata.txt and returns it as a Python dict.
40+
"""Read plugin metadata.txt and return it as a Python dict.
4041
41-
Raises:
42-
IOError: if metadata.txt is not found
42+
Raises
43+
------
44+
IOError
45+
If metadata.txt is not found.
4346
44-
Returns:
45-
dict: dict of dicts.
47+
Returns
48+
-------
49+
dict
50+
Metadata sections as nested dictionaries.
4651
4752
"""
4853
config = ConfigParser()

loopstructural/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#! python3
22

3+
"""LoopStructural QGIS plugin package.
4+
5+
Utilities and metadata for the LoopStructural QGIS plugin.
6+
"""
7+
38
# ----------------------------------------------------------
49
# Copyright (C) 2015 Martin Dobias
510
# ----------------------------------------------------------
@@ -15,8 +20,15 @@
1520
def classFactory(iface):
1621
"""Load the plugin class.
1722
18-
:param iface: A QGIS interface instance.
19-
:type iface: QgsInterface
23+
Parameters
24+
----------
25+
iface : QgsInterface
26+
A QGIS interface instance provided by QGIS when loading plugins.
27+
28+
Returns
29+
-------
30+
LoopstructuralPlugin
31+
An instance of the plugin class initialized with `iface`.
2032
"""
2133
from .plugin_main import LoopstructuralPlugin
2234

loopstructural/gui/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! python3
2+
"""GUI package for the LoopStructural QGIS plugin.
3+
4+
Contains widgets, dialogs and visualisation helpers used by the plugin UI.
5+
"""
6+
7+
# Re-export commonly used GUI classes if needed

loopstructural/gui/dlg_settings.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ def __init__(self, parent):
8080
self.load_settings()
8181

8282
def apply(self):
83-
"""Called to permanently apply the settings shown in the options page (e.g. \
84-
save them to QgsSettings objects). This is usually called when the options \
85-
dialog is accepted.
86-
"""
83+
"""Apply settings from the form and persist them to QgsSettings."""
8784
settings = self.plg_settings.get_plg_settings()
8885

8986
# misc
@@ -104,7 +101,7 @@ def apply(self):
104101
)
105102

106103
def load_settings(self):
107-
"""Load options from QgsSettings into UI form."""
104+
"""Load options from QgsSettings into the UI form."""
108105
settings = self.plg_settings.get_plg_settings()
109106

110107
# global
@@ -117,7 +114,7 @@ def load_settings(self):
117114
self.npw_spin_box.setValue(settings.interpolator_npw)
118115

119116
def reset_settings(self):
120-
"""Reset settings to default values (set in preferences.py module)."""
117+
"""Reset settings in the UI and persisted settings to plugin defaults."""
121118
default_settings = PlgSettingsStructure()
122119

123120
# dump default settings into QgsSettings
@@ -130,41 +127,57 @@ def reset_settings(self):
130127
class PlgOptionsFactory(QgsOptionsWidgetFactory):
131128
"""Factory for options widget."""
132129

133-
def __init__(self):
134-
"""Constructor."""
130+
def __init__(self, *args, **kwargs):
131+
"""Initialize the options factory.
132+
133+
Parameters
134+
----------
135+
*args, **kwargs
136+
Forwarded to base factory initializer.
137+
"""
135138
super().__init__()
136139

137-
def icon(self) -> QIcon:
138-
"""Returns plugin icon, used to as tab icon in QGIS options tab widget.
140+
def icon(self):
141+
"""Return the icon used for the options page.
139142
140-
:return: _description_
141-
:rtype: QIcon
143+
Returns
144+
-------
145+
QIcon
146+
Icon for the options page.
142147
"""
143148
return QIcon(str(__icon_path__))
144149

145150
def createWidget(self, parent) -> ConfigOptionsPage:
146151
"""Create settings widget.
147152
148-
:param parent: Qt parent where to include the options page.
149-
:type parent: QObject
153+
Parameters
154+
----------
155+
parent : QObject
156+
Qt parent where to include the options page.
150157
151-
:return: options page for tab widget
152-
:rtype: ConfigOptionsPage
158+
Returns
159+
-------
160+
ConfigOptionsPage
161+
Instantiated options page.
153162
"""
154163
return ConfigOptionsPage(parent)
155164

156165
def title(self) -> str:
157-
"""Returns plugin title, used to name the tab in QGIS options tab widget.
166+
"""Plugin title used to name options tab.
158167
159-
:return: plugin title from about module
160-
:rtype: str
168+
Returns
169+
-------
170+
str
171+
Plugin title string.
161172
"""
162173
return __title__
163174

164175
def helpId(self) -> str:
165-
"""Returns plugin help URL.
176+
"""Plugin help URL.
166177
167-
:return: plugin homepage url from about module
168-
:rtype: str
178+
Returns
179+
-------
180+
str
181+
URL of the plugin homepage.
169182
"""
170183
return __uri_homepage__

loopstructural/gui/loop_widget.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1+
#! python3
2+
"""Main Loop widget used in the plugin dock.
3+
4+
This module exposes `LoopWidget` which provides the primary user
5+
interface for interacting with LoopStructural features inside QGIS.
6+
"""
7+
18
from PyQt5.QtWidgets import QTabWidget, QVBoxLayout, QWidget
29
from .modelling.modelling_widget import ModellingWidget
310
from .visualisation.visualisation_widget import VisualisationWidget
411

512

613
class LoopWidget(QWidget):
14+
"""Main dock widget that contains modelling and visualisation tools.
15+
16+
The widget composes multiple tabs and controls used to construct and
17+
inspect geological models.
18+
"""
19+
720
def __init__(
821
self, parent=None, *, mapCanvas=None, logger=None, data_manager=None, model_manager=None
922
):
23+
"""Initialize the Loop widget.
24+
25+
Parameters
26+
----------
27+
*args, **kwargs
28+
Forwarded to the parent widget constructor.
29+
"""
1030
super().__init__(parent)
1131
self.mapCanvas = mapCanvas
1232
self.logger = logger

loopstructural/gui/modelling/model_definition/bounding_box.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ def __init__(self, parent=None, data_manager=None):
2424
self.data_manager.set_bounding_box_update_callback(self.set_bounding_box)
2525

2626
def set_bounding_box(self, bounding_box):
27-
"""
28-
Set the bounding box values in the UI.
29-
:param bounding_box: BoundingBox object with xmin, xmax, ymin, ymax, zmin, zmax attributes.
27+
"""Populate UI controls with values from a BoundingBox object.
28+
29+
Parameters
30+
----------
31+
bounding_box : object
32+
BoundingBox-like object with `origin` and `maximum` sequences of length 3.
3033
"""
3134
self.originXSpinBox.setValue(bounding_box.origin[0])
3235
self.maxXSpinBox.setValue(bounding_box.maximum[0])
@@ -36,10 +39,7 @@ def set_bounding_box(self, bounding_box):
3639
self.maxZSpinBox.setValue(bounding_box.maximum[2])
3740

3841
def useCurrentViewExtent(self):
39-
"""
40-
Use the current view extent from the map canvas.
41-
This method should be connected to a button or action in the UI.
42-
"""
42+
"""Set bounding box values from the current map canvas view extent."""
4343
if self.data_manager.map_canvas:
4444
extent = self.data_manager.map_canvas.extent()
4545
self.originXSpinBox.setValue(extent.xMinimum())
@@ -50,10 +50,7 @@ def useCurrentViewExtent(self):
5050
self.maxZSpinBox.setValue(1000)
5151

5252
def selectFromCurrentLayer(self):
53-
"""
54-
Select the bounding box from the current layer.
55-
This method should be connected to a button or action in the UI.
56-
"""
53+
"""Set bounding box values from the currently selected layer's 3D extent."""
5754
layer = self.data_manager.map_canvas.currentLayer()
5855
if layer:
5956
extent = layer.extent3D()

loopstructural/gui/modelling/stratigraphic_column/stratigraphic_column.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@
1414

1515

1616
class StratColumnWidget(QWidget):
17-
"""In control of building the stratigraphic column
18-
19-
:param QWidget: _description_
20-
:type QWidget: _type_
17+
"""Widget that controls building the stratigraphic column.
18+
19+
Parameters
20+
----------
21+
parent : QWidget, optional
22+
Parent widget, by default None.
23+
data_manager : object
24+
Data manager instance used to manage the stratigraphic column. Must be provided.
25+
26+
Notes
27+
-----
28+
The widget updates its display based on the data_manager's stratigraphic column
29+
and registers a callback via data_manager.set_stratigraphic_column_callback.
2130
"""
2231

2332
def __init__(self, parent=None, data_manager=None):

loopstructural/gui/modelling/stratigraphic_column/stratigraphic_unit.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ def name(self, value: str):
4040
self._name = str(value)
4141

4242
def set_thickness(self, thickness: float):
43-
"""
44-
Set the thickness of the stratigraphic unit.
45-
:param thickness: The thickness value to set.
43+
"""Set the thickness of the stratigraphic unit.
44+
45+
Parameters
46+
----------
47+
thickness : float
48+
The thickness value to set.
4649
"""
4750
self.thickness = thickness
4851
self.spinBoxThickness.setValue(thickness)
4952
self.validateFields()
5053

5154
def onColourSelectClicked(self):
52-
"""
53-
Open a color dialog to select a color for the stratigraphic unit.
54-
"""
55+
"""Open a color dialog to select a color for the stratigraphic unit."""
5556
from PyQt5.QtWidgets import QColorDialog
5657

5758
color = QColorDialog.getColor()
@@ -60,19 +61,19 @@ def onColourSelectClicked(self):
6061
self.buttonColor.setStyleSheet(f"background-color: {self.colour};")
6162

6263
def onThicknessChanged(self, thickness: float):
63-
"""
64-
Update the thickness of the stratigraphic unit.
65-
:param thickness: The new thickness value.
64+
"""Handle changes to the thickness spinbox.
65+
66+
Parameters
67+
----------
68+
thickness : float
69+
The new thickness value.
6670
"""
6771
self.thickness = thickness
6872
self.validateFields()
6973
self.thicknessChanged.emit(thickness)
7074

7175
def onNameChanged(self):
72-
"""
73-
Update the name of the stratigraphic unit.
74-
:param name: The new name value.
75-
"""
76+
"""Handle name edit completion and emit nameChanged if modified."""
7677
name = self.lineEditName.text().strip()
7778
if name != self.name:
7879
self.name = name
@@ -84,9 +85,7 @@ def request_delete(self):
8485
self.deleteRequested.emit(self)
8586

8687
def validateFields(self):
87-
"""
88-
Validate the fields and update the widget's appearance.
89-
"""
88+
"""Validate the widget fields and update UI hints."""
9089
# Reset all styles first
9190
self.lineEditName.setStyleSheet("")
9291
self.spinBoxThickness.setStyleSheet("")
@@ -101,9 +100,12 @@ def validateFields(self):
101100
self.spinBoxThickness.setToolTip("Thickness must be greater than zero.")
102101

103102
def setData(self, data: Optional[dict] = None):
104-
"""
105-
Set the data for the stratigraphic unit widget.
106-
:param data: A dictionary containing 'name' and 'colour' keys.
103+
"""Set the data for the stratigraphic unit widget.
104+
105+
Parameters
106+
----------
107+
data : dict or None
108+
Dictionary containing 'name' and 'colour' keys. If None, defaults are used.
107109
"""
108110
if data:
109111
self.name = str(data.get("name", ""))
@@ -119,9 +121,12 @@ def setData(self, data: Optional[dict] = None):
119121
self.validateFields()
120122

121123
def getData(self) -> dict:
122-
"""
123-
Get the data from the stratigraphic unit widget.
124-
:return: A dictionary containing 'name', 'colour', and 'thickness'.
124+
"""Return the widget data as a dictionary.
125+
126+
Returns
127+
-------
128+
dict
129+
Dictionary containing 'uuid', 'name', 'colour', and 'thickness'.
125130
"""
126131
return {
127132
"uuid": self.uuid,

loopstructural/gui/modelling/stratigraphic_column/unconformity.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ def request_delete(self):
2929
self.deleteRequested.emit(self)
3030

3131
def setData(self, data: Optional[dict] = None):
32-
"""
33-
Set the data for the unconformity widget.
34-
:param data: A dictionary containing 'unconformity_type' key.
32+
"""Set the data for the unconformity widget.
33+
34+
Parameters
35+
----------
36+
data : dict or None
37+
Dictionary containing 'unconformity_type' key. If None, defaults are used.
3538
"""
3639
if data:
3740
self.unconformity_type = data.get("unconformity_type", "")

loopstructural/gui/visualisation/feature_list_widget.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ def _get_vector_scale(self, scale: Optional[Union[float, int]] = None) -> float:
5757
return scale
5858

5959
def add_feature(self, feature):
60-
"""Add a feature to the feature list.
60+
"""Add a feature to the feature list widget.
6161
62-
:param feature: The feature to add.
63-
:type feature: Feature
62+
Parameters
63+
----------
64+
feature : Feature
65+
The feature object to add to the list.
6466
"""
6567
featureItem = QTreeWidgetItem(self.treeWidget)
6668
featureItem.setText(0, feature.name)

0 commit comments

Comments
 (0)