format tile size
This commit is contained in:
@@ -10,7 +10,7 @@ gi.require_version("Gtk", "4.0")
|
|||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
gi.require_version("Gdk", "4.0")
|
gi.require_version("Gdk", "4.0")
|
||||||
|
|
||||||
from gi.repository import Gdk, GdkPixbuf, GLib, Gtk
|
from gi.repository import Gdk, GdkPixbuf, GLib, Gtk, Pango
|
||||||
|
|
||||||
from . import systemctl
|
from . import systemctl
|
||||||
|
|
||||||
@@ -19,6 +19,9 @@ LOADING_STATES = {"reloading", "activating", "deactivating", "maintenance"}
|
|||||||
ICON_DIR = os.environ.get("SOVRAN_HUB_ICONS", "")
|
ICON_DIR = os.environ.get("SOVRAN_HUB_ICONS", "")
|
||||||
ICON_EXTENSIONS = [".svg", ".png"]
|
ICON_EXTENSIONS = [".svg", ".png"]
|
||||||
|
|
||||||
|
TILE_WIDTH = 148
|
||||||
|
TILE_HEIGHT = 170
|
||||||
|
|
||||||
|
|
||||||
class ServiceTile(Gtk.Box):
|
class ServiceTile(Gtk.Box):
|
||||||
|
|
||||||
@@ -26,13 +29,12 @@ class ServiceTile(Gtk.Box):
|
|||||||
icon_name="", enabled=True, **kw):
|
icon_name="", enabled=True, **kw):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
orientation=Gtk.Orientation.VERTICAL,
|
orientation=Gtk.Orientation.VERTICAL,
|
||||||
spacing=6,
|
spacing=4,
|
||||||
halign=Gtk.Align.CENTER,
|
halign=Gtk.Align.CENTER,
|
||||||
valign=Gtk.Align.CENTER,
|
valign=Gtk.Align.START,
|
||||||
width_request=140,
|
width_request=TILE_WIDTH,
|
||||||
height_request=160,
|
height_request=TILE_HEIGHT,
|
||||||
css_classes=["card", "sovran-tile"],
|
css_classes=["card", "sovran-tile"],
|
||||||
margin_top=6, margin_bottom=6, margin_start=6, margin_end=6,
|
|
||||||
**kw,
|
**kw,
|
||||||
)
|
)
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
@@ -40,39 +42,67 @@ class ServiceTile(Gtk.Box):
|
|||||||
self._method = method
|
self._method = method
|
||||||
self._enabled = enabled
|
self._enabled = enabled
|
||||||
|
|
||||||
self._logo = Gtk.Image(pixel_size=48, margin_top=12, halign=Gtk.Align.CENTER)
|
# ── Icon ─────────────────────────────────────────────────
|
||||||
|
self._logo = Gtk.Image(
|
||||||
|
pixel_size=40,
|
||||||
|
margin_top=16,
|
||||||
|
halign=Gtk.Align.CENTER,
|
||||||
|
)
|
||||||
self._set_logo(icon_name)
|
self._set_logo(icon_name)
|
||||||
self.append(self._logo)
|
self.append(self._logo)
|
||||||
|
|
||||||
self.append(Gtk.Label(
|
# ── Name label (wraps, max 2 lines) ──────────────────────
|
||||||
label=name, css_classes=["heading"],
|
self._name_label = Gtk.Label(
|
||||||
halign=Gtk.Align.CENTER, ellipsize=3, max_width_chars=14,
|
label=name,
|
||||||
))
|
css_classes=["heading"],
|
||||||
|
halign=Gtk.Align.CENTER,
|
||||||
|
justify=Gtk.Justification.CENTER,
|
||||||
|
wrap=True,
|
||||||
|
wrap_mode=Pango.WrapMode.WORD_CHAR,
|
||||||
|
max_width_chars=16,
|
||||||
|
lines=2,
|
||||||
|
ellipsize=Pango.EllipsizeMode.END,
|
||||||
|
margin_start=8,
|
||||||
|
margin_end=8,
|
||||||
|
margin_top=4,
|
||||||
|
)
|
||||||
|
self.append(self._name_label)
|
||||||
|
|
||||||
|
# ── Status label ─────────────────────────────────────────
|
||||||
self._status_label = Gtk.Label(
|
self._status_label = Gtk.Label(
|
||||||
label="● …",
|
label="● …",
|
||||||
css_classes=["caption", "dim-label"],
|
css_classes=["caption", "dim-label"],
|
||||||
halign=Gtk.Align.CENTER,
|
halign=Gtk.Align.CENTER,
|
||||||
|
margin_top=2,
|
||||||
)
|
)
|
||||||
self.append(self._status_label)
|
self.append(self._status_label)
|
||||||
|
|
||||||
|
# ── Spacer to push controls to bottom ────────────────────
|
||||||
|
spacer = Gtk.Box(vexpand=True)
|
||||||
|
self.append(spacer)
|
||||||
|
|
||||||
|
# ── Controls ─────────────────────────────────────────────
|
||||||
controls = Gtk.Box(
|
controls = Gtk.Box(
|
||||||
orientation=Gtk.Orientation.HORIZONTAL,
|
orientation=Gtk.Orientation.HORIZONTAL,
|
||||||
spacing=8, halign=Gtk.Align.CENTER, margin_bottom=8,
|
spacing=8,
|
||||||
|
halign=Gtk.Align.CENTER,
|
||||||
|
margin_bottom=12,
|
||||||
)
|
)
|
||||||
self._switch = Gtk.Switch(valign=Gtk.Align.CENTER)
|
self._switch = Gtk.Switch(valign=Gtk.Align.CENTER)
|
||||||
self._switch.connect("state-set", self._on_toggled)
|
self._switch.connect("state-set", self._on_toggled)
|
||||||
controls.append(self._switch)
|
controls.append(self._switch)
|
||||||
|
|
||||||
restart_btn = Gtk.Button(
|
restart_btn = Gtk.Button(
|
||||||
icon_name="view-refresh-symbolic", valign=Gtk.Align.CENTER,
|
icon_name="view-refresh-symbolic",
|
||||||
tooltip_text="Restart", css_classes=["flat", "circular"],
|
valign=Gtk.Align.CENTER,
|
||||||
|
tooltip_text="Restart",
|
||||||
|
css_classes=["flat", "circular"],
|
||||||
)
|
)
|
||||||
restart_btn.connect("clicked", self._on_restart)
|
restart_btn.connect("clicked", self._on_restart)
|
||||||
controls.append(restart_btn)
|
controls.append(restart_btn)
|
||||||
self.append(controls)
|
self.append(controls)
|
||||||
|
|
||||||
# If the feature is disabled in custom.nix, lock the tile immediately
|
# If the feature is disabled in custom.nix, lock the tile
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
self._switch.set_active(False)
|
self._switch.set_active(False)
|
||||||
self._switch.set_sensitive(False)
|
self._switch.set_sensitive(False)
|
||||||
@@ -87,7 +117,7 @@ class ServiceTile(Gtk.Box):
|
|||||||
path = os.path.join(ICON_DIR, f"{icon_name}{ext}")
|
path = os.path.join(ICON_DIR, f"{icon_name}{ext}")
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
try:
|
try:
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, 48, 48, True)
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, 40, 40, True)
|
||||||
texture = Gdk.Texture.new_for_pixbuf(pixbuf)
|
texture = Gdk.Texture.new_for_pixbuf(pixbuf)
|
||||||
self._logo.set_from_paintable(texture)
|
self._logo.set_from_paintable(texture)
|
||||||
return
|
return
|
||||||
@@ -96,7 +126,6 @@ class ServiceTile(Gtk.Box):
|
|||||||
self._logo.set_from_icon_name("system-run-symbolic")
|
self._logo.set_from_icon_name("system-run-symbolic")
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
# Don't poll systemctl for disabled features
|
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
.sovran-tile {
|
.sovran-tile {
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
padding: 8px;
|
padding: 0px;
|
||||||
min-width: 140px;
|
min-width: 148px;
|
||||||
min-height: 160px;
|
max-width: 148px;
|
||||||
|
min-height: 170px;
|
||||||
|
max-height: 170px;
|
||||||
transition: box-shadow 200ms ease-in-out;
|
transition: box-shadow 200ms ease-in-out;
|
||||||
}
|
}
|
||||||
.sovran-tile:hover {
|
.sovran-tile:hover {
|
||||||
|
|||||||
Reference in New Issue
Block a user