refactor(modules): improve exception handling and simplify service usage
Enhancements - Replace bare `except:` with `except Exception:` in multiple modules- Cast step calculation to `int` for consistent type - Simplify `get_battery_icon_file` to return a string directly - Use `get_todo_service()` instead of module-level `todo_service` throughout todo widget - Remove unused `"zen": "zen-browser"` mapping entry Bug Fixes - Prevent bare exception swallowing by catching `Exception` explicitly - Ensure proper cleanup of timer IDs and other resources - Delete unused modules/osdd components New Features - None
This commit is contained in:
34 files changed
+682
-519
No files matched your search
@@ -0,0 +1,50 @@
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.svg import Svg
|
||||
from fabric.utils import get_relative_path
|
||||
from .base import BaseOSDContainer
|
||||
from services.capslock import CapsLock
|
||||
|
||||
|
||||
class CapsLockOSDContainer(BaseOSDContainer):
|
||||
def __init__(self, window, **kwargs):
|
||||
super().__init__(window, **kwargs)
|
||||
self.capslock = CapsLock.get_initial()
|
||||
self._setup_specific_components()
|
||||
self._connect_specific_signals()
|
||||
|
||||
def _setup_specific_components(self):
|
||||
self.osd_image = Svg(
|
||||
get_relative_path("../../../assets/icons/misc/caps-lock.svg"),
|
||||
size=(100, 100),
|
||||
name="osd-image",
|
||||
h_align="center",
|
||||
v_align="center",
|
||||
h_expand=True,
|
||||
v_expand=True,
|
||||
)
|
||||
self.label = Label(name="osd-label")
|
||||
self.add(self.osd_image)
|
||||
self._update_display(self.capslock.is_on)
|
||||
|
||||
def _connect_specific_signals(self):
|
||||
self.capslock.connect("state_changed", self._on_caps_lock_state_changed)
|
||||
|
||||
def _on_caps_lock_state_changed(self, _, is_on: bool):
|
||||
self._update_display(is_on)
|
||||
self.update()
|
||||
|
||||
def _update_display(self, is_on: bool):
|
||||
icon_path = "caps-lock.svg" if is_on else "caps-lock-off.svg"
|
||||
self.osd_image.set_from_file(
|
||||
get_relative_path(f"../../../assets/icons/misc/{icon_path}")
|
||||
)
|
||||
if is_on:
|
||||
self.add_style_class("capslock-on")
|
||||
self.remove_style_class("capslock-off")
|
||||
else:
|
||||
self.add_style_class("capslock-off")
|
||||
self.remove_style_class("capslock-on")
|
||||
|
||||
def update(self, *_):
|
||||
# We don't need a separate display update here as it's handled in the signal
|
||||
super().update()
|
||||
Reference in new issue
Block a user