refactor: extract reusable utils, remove screencapture facade
- Add ManagedTimer to replace repeated source_remove/timeout_add boilerplate - Add EvdevLockService base class for numlock/capslock (cut 154→28 lines) - Add BaseNotchIndicator for 5 near-identical indicator classes (cut 404→171 lines) - Add load_pixbuf_thumbnail and resolve_monitor to utils - Delete screencapture.py facade; callers use Screenshot/ScreenRecorder directly
This commit is contained in:
16 files changed
+401
-612
No files matched your search
+26
-1
@@ -3,7 +3,14 @@ import struct
|
||||
from pathlib import Path
|
||||
from typing import Literal
|
||||
|
||||
from fabric.utils import Gdk, GLib, bulk_connect, exec_shell_command_async, logger
|
||||
from fabric.utils import (
|
||||
Gdk,
|
||||
GdkPixbuf,
|
||||
GLib,
|
||||
bulk_connect,
|
||||
exec_shell_command_async,
|
||||
logger,
|
||||
)
|
||||
from fabric.widgets.svg import Svg
|
||||
|
||||
|
||||
@@ -168,3 +175,21 @@ class EvdevLEDMonitor:
|
||||
except OSError as e:
|
||||
logger.warning(f"[utils] os.close(self._fd) failed: {e}")
|
||||
self._fd = None
|
||||
|
||||
|
||||
def load_pixbuf_thumbnail(
|
||||
path: str, width: int, height: int, *, fallback: str | None = None
|
||||
) -> GdkPixbuf.Pixbuf | None:
|
||||
"""Load a pixbuf scaled to fit within *width* x *height*.
|
||||
|
||||
Returns ``None`` on failure (file missing, corrupt, etc.). Pass a
|
||||
*fallback* path to try that on failure too.
|
||||
"""
|
||||
for p in (path, fallback):
|
||||
if p is None:
|
||||
continue
|
||||
try:
|
||||
return GdkPixbuf.Pixbuf.new_from_file_at_scale(p, width, height, True)
|
||||
except Exception as e:
|
||||
logger.warning(f"[gtk_utils] Failed to load pixbuf from {p}: {e}")
|
||||
return None
|
||||
Reference in new issue
Block a user