refiled directories
This commit is contained in:
@@ -9,84 +9,63 @@ import gi
|
||||
gi.require_version("Gtk", "4.0")
|
||||
gi.require_version("Adw", "1")
|
||||
|
||||
from gi.repository import Adw, Gdk, Gio, GLib, Gtk # noqa: E402
|
||||
from gi.repository import Adw, Gdk, Gio, GLib, Gtk
|
||||
|
||||
from .config import load_config # noqa: E402
|
||||
from .service_tile import ServiceTile # noqa: E402
|
||||
from .config import load_config
|
||||
from .service_tile import ServiceTile
|
||||
|
||||
APP_ID = "com.sovransystems.hub"
|
||||
|
||||
|
||||
class SovranHubWindow(Adw.ApplicationWindow):
|
||||
"""Primary window: a 4-across grid of service tiles with auto-refresh."""
|
||||
|
||||
def __init__(self, app: Adw.Application, config: dict):
|
||||
def __init__(self, app, config):
|
||||
super().__init__(
|
||||
application=app,
|
||||
title="Sovran_SystemsOS Hub",
|
||||
default_width=680,
|
||||
default_height=700,
|
||||
application=app, title="Sovran_SystemsOS Hub",
|
||||
default_width=680, default_height=700,
|
||||
)
|
||||
self._config = config
|
||||
self._tiles: list[ServiceTile] = []
|
||||
self._tiles = []
|
||||
|
||||
# ── Load custom CSS ──
|
||||
css_path = os.environ.get("SOVRAN_HUB_CSS", "")
|
||||
if css_path and os.path.isfile(css_path):
|
||||
provider = Gtk.CssProvider()
|
||||
provider.load_from_path(css_path)
|
||||
Gtk.StyleContext.add_provider_for_display(
|
||||
Gdk.Display.get_default(),
|
||||
provider,
|
||||
Gdk.Display.get_default(), provider,
|
||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
)
|
||||
|
||||
# ── Header bar ──
|
||||
header = Adw.HeaderBar()
|
||||
|
||||
refresh_btn = Gtk.Button(
|
||||
icon_name="view-refresh-symbolic",
|
||||
tooltip_text="Refresh now",
|
||||
)
|
||||
refresh_btn = Gtk.Button(icon_name="view-refresh-symbolic", tooltip_text="Refresh now")
|
||||
refresh_btn.connect("clicked", lambda _b: self._refresh_all())
|
||||
header.pack_end(refresh_btn)
|
||||
|
||||
# ── FlowBox: 4 tiles across ──
|
||||
self._flowbox = Gtk.FlowBox(
|
||||
max_children_per_line=4,
|
||||
min_children_per_line=2,
|
||||
selection_mode=Gtk.SelectionMode.NONE,
|
||||
homogeneous=True,
|
||||
row_spacing=12,
|
||||
column_spacing=12,
|
||||
margin_top=16,
|
||||
margin_bottom=16,
|
||||
margin_start=16,
|
||||
margin_end=16,
|
||||
halign=Gtk.Align.CENTER,
|
||||
valign=Gtk.Align.START,
|
||||
max_children_per_line=4, min_children_per_line=2,
|
||||
selection_mode=Gtk.SelectionMode.NONE, homogeneous=True,
|
||||
row_spacing=12, column_spacing=12,
|
||||
margin_top=16, margin_bottom=16, margin_start=16, margin_end=16,
|
||||
halign=Gtk.Align.CENTER, valign=Gtk.Align.START,
|
||||
)
|
||||
|
||||
# ── Scrollable content ──
|
||||
scrolled = Gtk.ScrolledWindow(
|
||||
hscrollbar_policy=Gtk.PolicyType.NEVER,
|
||||
vscrollbar_policy=Gtk.PolicyType.AUTOMATIC,
|
||||
vexpand=True,
|
||||
child=self._flowbox,
|
||||
vexpand=True, child=self._flowbox,
|
||||
)
|
||||
|
||||
toolbar_view = Adw.ToolbarView()
|
||||
toolbar_view.add_top_bar(header)
|
||||
toolbar_view.set_content(scrolled)
|
||||
|
||||
self.set_content(toolbar_view)
|
||||
|
||||
# ── Populate ──
|
||||
self._build_tiles()
|
||||
self._start_auto_refresh()
|
||||
interval = config.get("refresh_interval", 5)
|
||||
if interval and interval > 0:
|
||||
GLib.timeout_add_seconds(interval, self._auto_refresh)
|
||||
|
||||
def _build_tiles(self):
|
||||
"""Create ServiceTile widgets from config."""
|
||||
for entry in self._config.get("services", []):
|
||||
tile = ServiceTile(
|
||||
name=entry.get("name", entry["unit"]),
|
||||
@@ -99,27 +78,18 @@ class SovranHubWindow(Adw.ApplicationWindow):
|
||||
self._tiles.append(tile)
|
||||
|
||||
def _refresh_all(self):
|
||||
for tile in self._tiles:
|
||||
tile.refresh()
|
||||
for t in self._tiles:
|
||||
t.refresh()
|
||||
|
||||
def _start_auto_refresh(self):
|
||||
interval = self._config.get("refresh_interval", 5)
|
||||
if interval and interval > 0:
|
||||
GLib.timeout_add_seconds(interval, self._auto_refresh_cb)
|
||||
|
||||
def _auto_refresh_cb(self) -> bool:
|
||||
def _auto_refresh(self):
|
||||
self._refresh_all()
|
||||
return True
|
||||
|
||||
|
||||
class SovranHubApp(Adw.Application):
|
||||
"""Sovran_SystemsOS_Hub Adw.Application."""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
application_id=APP_ID,
|
||||
flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
|
||||
)
|
||||
super().__init__(application_id=APP_ID, flags=Gio.ApplicationFlags.DEFAULT_FLAGS)
|
||||
self._config = load_config()
|
||||
|
||||
def do_activate(self):
|
||||
|
||||
Reference in New Issue
Block a user