Skip to content
Merged
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
48 changes: 35 additions & 13 deletions leafmap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ipywidgets as widgets

from . import common
from . import vuetify_compat as vc


class Colorbar(widgets.Output):
Expand Down Expand Up @@ -1050,35 +1051,41 @@ def __init__(
# Toolbar
self._title = v.ToolbarTitle(children=[title])
self._refresh_btn = v.Btn(
icon=True, children=[v.Icon(children=["mdi-refresh"])], tooltip="Refresh"
**vc.icon_button(),
children=[v.Icon(children=["mdi-refresh"])],
tooltip="Refresh",
)
self._help_btn = v.Btn(
icon=True,
**vc.icon_button(),
children=[v.Icon(children=["mdi-help-circle-outline"])],
tooltip="Help",
)
self._toolbar = v.Toolbar(
dense=True,
**vc.dense(),
flat=True,
color="primary" if dark_topbar else "white",
dark=dark_topbar,
**vc.dark_theme(dark_topbar),
children=[self._title, v.Spacer(), self._refresh_btn, self._help_btn],
)

# Tabs header & items (linked by jslink)
self._tabs_header = v.Tabs(
v_model=0,
background_color="transparent",
**vc.tabs_background("transparent"),
slider_color="primary",
class_="px-4" if show_tab_header else "px-4 d-none",
children=[],
)
self._tabs_items = v.TabsItems(v_model=0, children=[])
self._tabs_items = vc.TabsWindow(v_model=0, children=[])
widgets.jslink((self._tabs_header, "v_model"), (self._tabs_items, "v_model"))

# Snackbar for quick feedback
self._snackbar = v.Snackbar(
v_model=False, timeout=1400, color="primary", bottom=True, children=[""]
v_model=False,
timeout=1400,
color="primary",
**vc.location_bottom(),
children=[""],
)

# Help dialog (default content)
Expand All @@ -1090,7 +1097,9 @@ def __init__(
""")
self._help_title = v.CardTitle(class_="text-h6", children=["Help"])
self._help_cardtext = v.CardText(class_="py-4", children=[default_help])
self._help_close_btn = v.Btn(text=True, color="primary", children=["Close"])
self._help_close_btn = v.Btn(
**vc.text_button(), color="primary", children=["Close"]
)
self._help_card = v.Card(
class_="rounded-xl",
children=[
Expand Down Expand Up @@ -1271,7 +1280,10 @@ def set_tab_icon(self, index: int, icon: Optional[str]) -> None:
tab = self._tabs_header.children[index]
label = self._labels[index]
if icon:
tab.children = [v.Icon(left=True, small=True, children=[icon]), label]
tab.children = [
v.Icon(**vc.icon_start(), **vc.small(), children=[icon]),
label,
]
else:
tab.children = [label]
if index < len(self._icons):
Expand Down Expand Up @@ -1448,13 +1460,18 @@ def _append_tab(self, label: str, icon: str, body: widgets.Widget) -> None:
hdr_children = list(self._tabs_header.children)
items_children = list(self._tabs_items.children)
tab_hdr = (
v.Tab(children=[v.Icon(left=True, small=True, children=[icon]), label])
v.Tab(
children=[
v.Icon(**vc.icon_start(), **vc.small(), children=[icon]),
label,
]
)
if icon
else v.Tab(children=[label])
)
hdr_children.append(tab_hdr)
content = self._card(label, body) if self._wrap_in_card else body
items_children.append(v.TabItem(children=[content]))
items_children.append(vc.TabsWindowItem(children=[content]))
self._tabs_header.children = tuple(hdr_children)
self._tabs_items.children = tuple(items_children)

Expand All @@ -1478,13 +1495,18 @@ def _insert_tab(
if not (0 <= index <= n):
raise IndexError(f"index {index} out of range (0..{n})")
tab_hdr = (
v.Tab(children=[v.Icon(left=True, small=True, children=[icon]), label])
v.Tab(
children=[
v.Icon(**vc.icon_start(), **vc.small(), children=[icon]),
label,
]
)
if icon
else v.Tab(children=[label])
)
hdr_children.insert(index, tab_hdr)
content = self._card(label, body) if self._wrap_in_card else body
items_children.insert(index, v.TabItem(children=[content]))
items_children.insert(index, vc.TabsWindowItem(children=[content]))
self._tabs_header.children = tuple(hdr_children)
self._tabs_items.children = tuple(items_children)
self._labels.insert(index, label)
Expand Down
70 changes: 53 additions & 17 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from maplibre.sources import GeoJSONSource, RasterTileSource

from . import common
from . import vuetify_compat as vc
from .basemaps import xyz_to_leaflet
from .common import (
_in_colab_shell,
Expand Down Expand Up @@ -92,14 +93,18 @@ def _panel_header_chevron(color: str) -> List[Dict[str, Any]]:

The default expand/collapse icon follows the Vuetify theme and is nearly
invisible on the light sidebar headers in dark mode, so it is colored
explicitly.
explicitly. Vuetify 3 swaps between expand and collapse icons instead of
rotating a custom one, and its icon takes the header text color, so no slot
is needed there.

Args:
color (str): The CSS color of the chevron.

Returns:
The ``v_slots`` list for ``v.ExpansionPanelHeader``.
The ``v_slots`` list for ``vc.ExpansionPanelTitle``.
"""
if vc.VUETIFY3:
return []
return [
{
"name": "actions",
Expand Down Expand Up @@ -5567,11 +5572,11 @@ def add_floating_sidebar(
# Create toggle button
toggle_icon = v.Icon(
children=["mdi-chevron-left"] if sidebar_visible else ["mdi-chevron-right"],
small=True,
**vc.small(),
style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};",
)
toggle_btn = v.Btn(
icon=True,
**vc.icon_button(),
children=[toggle_icon],
style_=(
f"width: 22px; height: 22px; min-width: 22px; padding: 0; "
Expand All @@ -5582,11 +5587,11 @@ def add_floating_sidebar(
# Create settings/wrench button
settings_icon = v.Icon(
children=["mdi-wrench"],
small=True,
**vc.small(),
style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};",
)
settings_btn = v.Btn(
icon=True,
**vc.icon_button(),
children=[settings_icon],
style_=(
f"width: 22px; height: 22px; min-width: 22px; padding: 0; "
Expand Down Expand Up @@ -8250,6 +8255,37 @@ class Container(v.Container):
row (v.Row): The main layout row containing the map and sidebar.
"""

# ipyvuetify 3 adds synced ``min_width`` and ``max_width`` traits to
# ``v.Container``. These properties shadow them so the sidebar widths are
# kept in Python only and do not constrain the whole container.
@property
def min_width(self) -> int:
"""int: Minimum width of the sidebar in pixels."""
return self._sidebar_min_width

@min_width.setter
def min_width(self, value: int) -> None:
"""Sets the minimum width of the sidebar.

Args:
value (int): The minimum width in pixels.
"""
self._sidebar_min_width = value

@property
def max_width(self) -> int:
"""int: Maximum width of the sidebar in pixels."""
return self._sidebar_max_width

@max_width.setter
def max_width(self, value: int) -> None:
"""Sets the maximum width of the sidebar.

Args:
value (int): The maximum width in pixels.
"""
self._sidebar_max_width = value

def __init__(
self,
host_map: Optional[Any] = None,
Expand Down Expand Up @@ -8312,7 +8348,7 @@ def __init__(
style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};",
)
self.toggle_btn = v.Btn(
icon=True,
**vc.icon_button(),
children=[self.toggle_icon],
style_=(
f"width: 48px; height: 48px; min-width: 48px; "
Expand All @@ -8327,7 +8363,7 @@ def __init__(
style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};",
)
self.settings_btn = v.Btn(
icon=True,
**vc.icon_button(),
children=[self.settings_icon],
style_=f"width: 36px; height: 36px; color: {SIDEBAR_PANEL_TEXT_COLOR};",
)
Expand Down Expand Up @@ -10469,8 +10505,8 @@ def __init__(

# Close icon button
close_btn = v.Btn(
icon=True,
small=True,
**vc.icon_button(),
**vc.small(),
class_="ma-0",
style_=f"min-width: 24px; width: 24px; color: {text_color};",
children=[
Expand All @@ -10482,7 +10518,7 @@ def __init__(
)
close_btn.on_event("click", self._handle_close)

header = v.ExpansionPanelHeader(
header = vc.ExpansionPanelTitle(
style_=(
f"height: {height}; min-height: {height}; "
f"background-color: {background_color}; "
Expand Down Expand Up @@ -10514,7 +10550,7 @@ def __init__(
# uses a dark theme.
panel_style = widgets.HTML(
"<style>"
".leafmap-layer-manager .v-expansion-panel-content__wrap"
f".leafmap-layer-manager .{vc.EXPANSION_PANEL_WRAPPER_CLASS}"
" { padding: 4px 8px 8px; }"
".leafmap-layer-manager {"
f" --jp-widgets-label-color: {SIDEBAR_PANEL_TEXT_COLOR};"
Expand All @@ -10532,7 +10568,7 @@ def __init__(
),
children=[
header,
v.ExpansionPanelContent(
vc.ExpansionPanelText(
style_=(
f"background-color: {SIDEBAR_PANEL_BACKGROUND}; "
f"color: {text_color}; "
Expand Down Expand Up @@ -10809,8 +10845,8 @@ def __init__(

# Close icon button
close_btn = v.Btn(
icon=True,
small=True,
**vc.icon_button(),
**vc.small(),
class_="ma-0",
style_=f"min-width: 24px; width: 24px; color: {text_color};",
children=[
Expand All @@ -10822,7 +10858,7 @@ def __init__(
)
close_btn.on_event("click", self._handle_close)

header = v.ExpansionPanelHeader(
header = vc.ExpansionPanelTitle(
style_=(
f"height: {height}; min-height: {height}; "
f"background-color: {background_color}; "
Expand Down Expand Up @@ -10857,7 +10893,7 @@ def __init__(
),
children=[
header,
v.ExpansionPanelContent(
vc.ExpansionPanelText(
style_=(
f"background-color: {SIDEBAR_PANEL_BACKGROUND}; "
f"color: {text_color}; "
Expand Down
Loading
Loading