Files
Modus/modules/osd/components/keyboard_layout.py
T
sankalp ef4065bc1f 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
2026-03-23 23:34:03 +05:45

41 lines
1.4 KiB
Python

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.keyboard_layout import KeyboardLayout
class KeyboardLayoutOSDContainer(BaseOSDContainer):
def __init__(self, window, **kwargs):
super().__init__(window, **kwargs)
self.keyboard_layout = KeyboardLayout.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/keyboard-layout.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.add(self.label)
self.label.set_text(self.keyboard_layout.current_layout)
def _connect_specific_signals(self):
self.keyboard_layout.connect("layout_changed", self._on_layout_changed)
def _on_layout_changed(self, service, layout: str):
if not self.is_hovered():
self.label.set_text(layout)
self.update()
def update(self, *_):
self.label.set_text(self.keyboard_layout.current_layout)
super().update()