-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
108 lines (84 loc) Β· 3.14 KB
/
Copy path__init__.py
File metadata and controls
108 lines (84 loc) Β· 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from abc import ABCMeta, abstractmethod
from typing import Any, Callable, Optional
from collagraph.constants import EventLoopType
class Renderer(metaclass=ABCMeta): # pragma: no cover
"""Abstract base class for renderers"""
def preferred_event_loop_type(self) -> Optional[EventLoopType]:
"""Indicate the preferred default event loop type"""
return None
def register_asyncio(self) -> None:
"""
Called by collagraph instance when registering the scheduler with
asyncio so that the renderer can perform any additional setup.
"""
pass
@abstractmethod
def create_element(self, type: str) -> Any:
"""Create an element for the given type."""
pass
@abstractmethod
def create_text_element(self) -> Any:
"""Create a text element."""
pass
@abstractmethod
def insert(self, el: Any, parent: Any, anchor: Any = None):
"""
Add element `el` as a child to the element `parent`.
If an anchor is specified, it inserts `el` before the `anchor`
element.
"""
pass
@abstractmethod
def remove(self, el: Any, parent: Any):
"""Remove the element `el` from the children of the element `parent`."""
pass
@abstractmethod
def set_element_text(self, el: Any, value: str):
"""Set the text of a text element."""
pass
@abstractmethod
def set_attribute(self, el: Any, attr: str, value: Any):
"""Set the attribute `attr` of the element `el` to the value `value`."""
pass
@abstractmethod
def remove_attribute(self, el: Any, attr: str, value: Any):
"""Remove the attribute `attr` from the element `el`."""
pass
@abstractmethod
def add_event_listener(self, el: Any, event_type: str, value: Callable):
"""Add event listener for `event_type` to the element `el`."""
pass
@abstractmethod
def remove_event_listener(self, el: Any, event_type: str, value: Callable):
"""Remove event listener for `event_type` to the element `el`."""
pass
def save_element_state(self, el: Any) -> Optional[dict]:
"""
Save renderer-specific element state for hot reload.
Called before unmounting during hot reload to preserve element state
that isn't part of component state (e.g., window geometry).
Returns a dict of state to preserve, or None if nothing to save.
"""
return None
def restore_element_state(self, el: Any, state: dict) -> None:
"""
Restore renderer-specific element state after hot reload.
Called after remounting during hot reload to restore element state
that was saved by save_element_state().
"""
pass
from .dict_renderer import DictRenderer
try:
import pygfx
except ImportError: # pragma: no cover
pass
else:
from .pygfx_renderer import PygfxRenderer
try:
import PySide6
except ImportError: # pragma: no cover
pass
else:
from .pyside_renderer import PySideRenderer # noqa: I001
# Need to import the objects in order to register their methods
from .pyside import objects