diff --git a/Python_Engine/Python/src/python_toolkit/bhom/decorators/_bhom_callable_decorator.py b/Python_Engine/Python/src/python_toolkit/bhom/decorators/_bhom_callable_decorator.py index 436ebcb9..14e52c5f 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom/decorators/_bhom_callable_decorator.py +++ b/Python_Engine/Python/src/python_toolkit/bhom/decorators/_bhom_callable_decorator.py @@ -1,4 +1,26 @@ -import json +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +import json from typing import Any, Callable, Union, Dict from functools import wraps from ..bhom_object import CONSOLE_LOGGER, BHoMJSONDecoder, BHoMJSONEncoder, BHoMObject, IObject @@ -14,6 +36,8 @@ def bhom_callable(self, identifier: str, argument_types:Dict[str, type] = {}, en when __input_json__ is set, this will cause the method to always output BHoM style json (using the encoder_cls provided to this decorator) Args: + identifier (str): The unique name C# uses to call the method through run_wrapped. + argument_types (dict[str, type]): this is a dictionary that is used to map the argument names to types (specifically BHoMObject types) to subclasses of BHoMObjects. For example, if you have a class that is a subclass of BHoMObject, the default serialiser will only deserialise json to a BHoMObject. To go the extra step to get your class, you must provide the type in this dictionary to allow the wrapper to convert the BHoMObject type to your desired type. diff --git a/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/figure_container.py b/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/figure_container.py index 2cf03d89..76f872f0 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/figure_container.py +++ b/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/figure_container.py @@ -1,4 +1,26 @@ -"""Container widget for embedding matplotlib figures or image content.""" +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +"""Container widget for embedding matplotlib figures or image content.""" import tkinter as tk from tkinter import ttk @@ -131,7 +153,7 @@ def embed_image(self, image: tk.PhotoImage) -> None: """Embed a Tk image in the figure container. Args: - image: Tk PhotoImage object to embed + image: Tk PhotoImage object to embed. """ self._close_held_figure() self._clear_children() @@ -144,7 +166,7 @@ def embed_image_file(self, file_path: str) -> None: """Load and embed an image file, scaled to fit the container. Args: - file_path: Path to image file + file_path: Path to image file. """ self.image_file = file_path try: diff --git a/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/searchable_list_box.py b/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/searchable_list_box.py index 2bab2b1e..c23a9824 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/searchable_list_box.py +++ b/Python_Engine/Python/src/python_toolkit/bhom_tkinter/widgets/searchable_list_box.py @@ -1,3 +1,25 @@ +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + """Scrollable listbox with a search filter that keeps selections while items are filtered out.""" from __future__ import annotations @@ -51,6 +73,9 @@ def fuzzy_scorer(query: str, text: str, min_score: float = 75) -> Optional[float text: The item being tested. min_score: Similarity (0-100) an item needs to be shown. To use a different value, bind it with `functools.partial(fuzzy_scorer, min_score=...)` and pass that as `scorer`. + + Returns: + The match score (0-100), or None if it is below `min_score`. """ compute, bhom_scorer = _load_bhom_search() query = _NON_ALNUM.sub(" ", query.lower()).strip() @@ -70,6 +95,10 @@ def default_scorer(query: str, text: str, min_score: float = 75) -> Optional[flo query: The text typed into the filter. text: The item being tested. min_score: Similarity (0-100) a fuzzy match needs to be shown. + + Returns: + A score (higher is better) if the item matches, or None to hide it. Items containing the query score + 200, above any fuzzy score (0-100). """ words = _NON_ALNUM.sub(" ", query.lower()).split() if not words: diff --git a/Python_Engine/Python/src/python_toolkit/helpers/decay_rate.py b/Python_Engine/Python/src/python_toolkit/helpers/decay_rate.py index 99f2e657..93815bf9 100644 --- a/Python_Engine/Python/src/python_toolkit/helpers/decay_rate.py +++ b/Python_Engine/Python/src/python_toolkit/helpers/decay_rate.py @@ -1,4 +1,26 @@ -import re +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +import re from enum import Enum, auto import numpy as np @@ -61,7 +83,7 @@ def decay_rate_smoother( Args: series (pd.Series): - The series to modify + The series to modify. difference_threshold (float, optional): The difference between current/previous values which class as a "transition". Defaults to -10. diff --git a/Python_Engine/Python/src/python_toolkit/helpers/helpers.py b/Python_Engine/Python/src/python_toolkit/helpers/helpers.py index 7f8cad97..13be7f90 100644 --- a/Python_Engine/Python/src/python_toolkit/helpers/helpers.py +++ b/Python_Engine/Python/src/python_toolkit/helpers/helpers.py @@ -1,4 +1,26 @@ -import re +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +import re from datetime import timedelta from typing import Any @@ -55,7 +77,7 @@ def decay_rate_smoother( Args: series (pd.Series): - The series to modify + The series to modify. difference_threshold (float, optional): The difference between current/previous values which class as a "transition". Defaults to -10. diff --git a/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py b/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py index 9b1d0e3b..e8088aa7 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py +++ b/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py @@ -1,3 +1,25 @@ +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + from matplotlib import pyplot as plt from matplotlib.colors import Colormap, Normalize from matplotlib.figure import Figure @@ -17,12 +39,12 @@ def cmap_sample_plot( Generate a sample plot for a given colormap. Args: - cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object - bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1) - figsize: Figure size as (width, height). If None, defaults to (9, 1) + cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object. + bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1). + figsize: Figure size as (width, height). If None, defaults to (9, 1). bins: Number of discrete bins for the gradient. Defaults to 256. Returns: - Matplotlib Figure object + Matplotlib Figure object. """ figsize = figsize or (9, 1) diff --git a/Python_Engine/Python/src/python_toolkit/plot/spatial_heatmap.py b/Python_Engine/Python/src/python_toolkit/plot/spatial_heatmap.py index 8861ffaa..35028fee 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/spatial_heatmap.py +++ b/Python_Engine/Python/src/python_toolkit/plot/spatial_heatmap.py @@ -1,4 +1,26 @@ -"""Methods for plotting spatial heatmaps.""" +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +"""Methods for plotting spatial heatmaps.""" import matplotlib.pyplot as plt import numpy as np @@ -69,7 +91,7 @@ def spatial_heatmap( clabels (bool, optional): A flag to show contour labels. Defaults to False. style_context (string, optional): - The matplotlib style to use. Defaults to python_toolkit.bhom + The matplotlib style to use. Defaults to python_toolkit.bhom. Returns: Figure: A matplotlib Figure object. diff --git a/Python_Engine/Python/src/python_toolkit/plot/utilities.py b/Python_Engine/Python/src/python_toolkit/plot/utilities.py index fd71cc9d..068dc4f4 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/utilities.py +++ b/Python_Engine/Python/src/python_toolkit/plot/utilities.py @@ -1,4 +1,26 @@ -"""Text and colour utility methods for plotting""" +# +# This file is part of the Buildings and Habitats object Model (BHoM) +# Copyright (c) 2015 - 2026, the respective contributors. All rights reserved. +# +# Each contributor holds copyright over their respective contributions. +# The project versioning (Git) records all such contribution source information. +# +# +# The BHoM is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3.0 of the License, or +# (at your option) any later version. +# +# The BHoM 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 +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this code. If not, see . +# + +"""Text and colour utility methods for plotting""" import base64 import colorsys @@ -369,6 +391,8 @@ def figure_to_base64(figure: plt.Figure, html: bool = False, transparent: bool = A matplotlib figure object. html (bool, optional): Set to True to include the HTML preamble for a base64 encoded image. Default is False. + transparent (bool, optional): + Set to True to save the figure with a transparent background. Default is True. Returns: str: