Add GObject reactive utility
This commit is contained in:
parent
9e818dab35
commit
32584313b0
2 changed files with 27 additions and 0 deletions
lazy_player/reactive
27
lazy_player/reactive/gobject.py
Normal file
27
lazy_player/reactive/gobject.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any, TypeVar
|
||||
|
||||
from gi.repository import GObject
|
||||
|
||||
from . import Ref
|
||||
|
||||
__all__ = ["GRef"]
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
class GRef(Ref[T]):
|
||||
_prop_name: str
|
||||
_gobject: GObject.Object
|
||||
|
||||
def __init__(self, gobj: GObject.Object, prop_name: str):
|
||||
super().__init__(gobj.get_property(prop_name))
|
||||
self._prop_name = prop_name
|
||||
gobj.connect(f"notify::{prop_name}", self._on_notify)
|
||||
|
||||
def _on_notify(self, *args: Any):
|
||||
self.value = self._gobject.get_property(self._prop_name)
|
||||
|
||||
def __repr__(self):
|
||||
return f"GRef(gobj={self._gobject!r}, prop_name={self._prop_name!r})"
|
Loading…
Reference in a new issue