fix: support libadwaita versions without Adw.Banner
This commit is contained in:
+32
-1
@@ -156,6 +156,34 @@ def _load_css() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CompatBanner(Gtk.Revealer):
|
||||||
|
"""Fallback banner for libadwaita versions that don't provide `Adw.Banner`."""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.set_transition_type(Gtk.RevealerTransitionType.SLIDE_DOWN)
|
||||||
|
|
||||||
|
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
|
||||||
|
box.set_margin_top(8)
|
||||||
|
box.set_margin_bottom(8)
|
||||||
|
box.set_margin_start(12)
|
||||||
|
box.set_margin_end(12)
|
||||||
|
box.add_css_class("toolbar")
|
||||||
|
|
||||||
|
self._label = Gtk.Label(xalign=0)
|
||||||
|
self._label.set_wrap(True)
|
||||||
|
self._label.set_hexpand(True)
|
||||||
|
box.append(self._label)
|
||||||
|
|
||||||
|
self.set_child(box)
|
||||||
|
|
||||||
|
def set_title(self, title: str) -> None:
|
||||||
|
self._label.set_text(title)
|
||||||
|
|
||||||
|
def set_revealed(self, revealed: bool) -> None:
|
||||||
|
self.set_reveal_child(revealed)
|
||||||
|
|
||||||
|
|
||||||
# ── Settings Dialog ─────────────────────────────────────────────
|
# ── Settings Dialog ─────────────────────────────────────────────
|
||||||
class SettingsWindow(Adw.Window):
|
class SettingsWindow(Adw.Window):
|
||||||
"""Preferences dialog using libadwaita widgets."""
|
"""Preferences dialog using libadwaita widgets."""
|
||||||
@@ -377,7 +405,10 @@ class CellarWindow(Adw.ApplicationWindow):
|
|||||||
# ── Outer box (banner + progress + scrolled content) ──
|
# ── Outer box (banner + progress + scrolled content) ──
|
||||||
outer_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
outer_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
|
||||||
self.banner = Adw.Banner()
|
if hasattr(Adw, "Banner"):
|
||||||
|
self.banner = Adw.Banner()
|
||||||
|
else:
|
||||||
|
self.banner = CompatBanner()
|
||||||
self.banner.set_revealed(False)
|
self.banner.set_revealed(False)
|
||||||
outer_box.append(self.banner)
|
outer_box.append(self.banner)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user