Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from python_toolkit.bhom_tkinter.widgets.figure_container import FigureContainer
from python_toolkit.bhom_tkinter.widgets._widgets_base import BHoMBaseWidget
from python_toolkit.bhom_tkinter.widgets._packing_options import PackingOptions
from python_toolkit.plot import palettes

from python_toolkit.bhom.analytics import CONSOLE_LOGGER
from python_toolkit.bhom_tkinter.theming.scaling import scale_pad
Expand All @@ -27,48 +28,6 @@ class CmapSelector(BHoMBaseWidget):
* `List[str]`: a list of colour strings (hex codes or named colours) that is auto-converted to a `ListedColormap`.
"""

CATEGORICAL_CMAPS = [
"Accent",
"Dark2",
"Paired",
"Pastel1",
"Pastel2",
"Set1",
"Set2",
"Set3",
"tab10",
"tab20",
"tab20b",
"tab20c",
]

CONTINUOUS_CMAPS = [
"viridis",
"plasma",
"inferno",
"magma",
"cividis",
"turbo",
"Blues",
"Greens",
"Greys",
"Oranges",
"Purples",
"Reds",
"YlGn",
"YlGnBu",
"YlOrBr",
"YlOrRd",
"coolwarm",
"seismic",
"Spectral",
"RdYlBu",
"RdYlGn",
"twilight",
"twilight_shifted",
"hsv",
]

def __init__(
self,
parent: ttk.Frame,
Expand All @@ -90,7 +49,8 @@ def __init__(
`List[str]` of colour strings. When provided the preset
`cmap_set` selection is ignored.
cmap_set: Preset colormap set used when `colormaps` is `None`.
Allowed values: "all", "continuous", "categorical".
Allowed values: "all", "continuous", "categorical", "colourblind"
(see `python_toolkit.plot.palettes`).
cmap_bins: Number of discrete gradient bands in the preview swatch.
default_cmap: Optional default colormap to pre-select. Accepts
the same input types as items in `colormaps`.
Expand All @@ -113,12 +73,7 @@ def __init__(
self.cmap_frame.pack(side="top", fill="both", expand=True, anchor=self._pack_anchor)

self.colormap_var = tk.StringVar(value="viridis")
self._all_colormaps = self._get_all_colormaps()
self._preset_map: Dict[str, List[str]] = {
"all": self._all_colormaps,
"continuous": self._filter_available(self.CONTINUOUS_CMAPS),
"categorical": self._filter_available(self.CATEGORICAL_CMAPS),
}
self._all_colormaps = palettes.names()
self._uses_explicit_colormaps = colormaps is not None

self.cmap_frame.columnconfigure(0, weight=1)
Expand Down Expand Up @@ -172,35 +127,6 @@ def __init__(
self._default_label = self._resolve_default_label(default_cmap, current_colormaps)
self._select_default_cmap(current_colormaps)

def _get_all_colormaps(self) -> List[str]:
"""Return all registered colormap names, including reversed variants.

Returns:
List[str]: Sorted list of available colormap names.
"""
# Base names available in this matplotlib build
base_names = set(mpl.colormaps())

# Include reversed variants (name_r) next to each base map
all_names = set(base_names)
for name in list(base_names):
if not name.endswith("_r"):
all_names.add(f"{name}_r")

return sorted(all_names)

def _filter_available(self, names: List[str]) -> List[str]:
"""Filter a candidate list to names available in the current matplotlib build.

Args:
names: Candidate colormap names.

Returns:
List[str]: Candidate names available in the current environment.
"""
available = set(self._all_colormaps)
return [name for name in names if name in available]

def _with_reversed(self, names: List[str]) -> List[str]:
"""Return colormap names with reversed variants next to base maps.

Expand Down Expand Up @@ -231,7 +157,7 @@ def _preset_colormaps(self, cmap_set: str) -> List[str]:
List[str]: Colormap names for the requested preset.
"""
key = (cmap_set or "all").lower()
return self._with_reversed(self._preset_map.get(key, self._preset_map["all"]))
return self._with_reversed(palettes.names(key if key in palettes.KINDS else None))

def _resolve_colormaps(self, colormaps: List[CmapInput]) -> tuple[List[str], Dict[str, Colormap]]:
"""Normalise a mixed list of colormap inputs into display labels and a custom-cmap registry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tkinter import ttk
from typing import Optional, Callable, List, Literal

from python_toolkit.bhom.logging import CONSOLE_LOGGER
from python_toolkit.bhom_tkinter.widgets._widgets_base import BHoMBaseWidget

class DropDownSelection(BHoMBaseWidget):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from python_toolkit.bhom_tkinter.bhom_base_child_window import BHoMBaseChildWindow
from .colour_scale_builder import ColourScaleBuilder
from .directory_file_selector import DirectoryFileSelector
from .landing_page import LandingPage
from .modal_window import BHoMModalWindow
Expand All @@ -8,6 +9,7 @@
__all__ = [
"BHoMBaseChildWindow",
"BHoMModalWindow",
"ColourScaleBuilder",
"DirectoryFileSelector",
"LandingPage",
"ProcessingWindow",
Expand Down
Loading
Loading