FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/src/pythonnative/animation_graph.py at v0.43.1 · pythonnative/pythonnative · GitHub
pythonnative
pythonnative
Repository navigation
Code
Issues
11
(11)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
animation_graph.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (66 loc) · 2.98 KB
Breadcrumbs
pythonnative
/
src
/
pythonnative
/
animation_graph.py
Copy path
File metadata and controls
78 lines (66 loc) · 2.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""Portable animation expressions evaluated by the native UI thread."""
from
__future__
import
annotations
from
typing
import
Any
def
serialize
(
root
:
Any
)
->
dict
[
str
,
Any
]:
"""Serialize one connected animation graph in dependency order."""
from
.
animated
import
AnimatedInterpolation
,
AnimatedNode
,
AnimatedValue
,
_AnimatedDiffClamp
,
_AnimatedOperation
connected
:
dict
[
int
,
Any
]
=
{}
def
discover
(
node
:
Any
)
->
None
:
if
not
isinstance
(
node
,
AnimatedNode
)
or
id
(
node
)
in
connected
:
return
connected
[
id
(
node
)]
=
node
for
child
in
list
(
node
.
_children
):
discover
(
child
)
for
parent
in
getattr
(
node
,
"_parents"
, [
getattr
(
node
,
"_parent"
,
None
)]):
discover
(
parent
)
discover
(
root
)
encoded
:
dict
[
int
,
dict
[
str
,
Any
]]
=
{}
def
encode
(
node
:
Any
)
->
Any
:
if
not
isinstance
(
node
,
AnimatedNode
):
return
{
"constant"
:
float
(
node
)}
identity
=
id
(
node
)
if
identity
not
in
encoded
:
definition
:
dict
[
str
,
Any
]
=
{
"id"
:
identity
}
if
isinstance
(
node
,
AnimatedValue
):
definition
.
update
(
kind
=
"value"
,
value
=
node
.
value
)
elif
isinstance
(
node
,
AnimatedInterpolation
):
definition
.
update
(
kind
=
"interpolate"
,
inputs
=
[
encode
(
node
.
_parent
)],
ranges
=
node
.
_inputs
,
outputs
=
node
.
_outputs
,
color
=
node
.
_kind
==
"color"
,
left
=
node
.
_left
,
right
=
node
.
_right
,
)
elif
isinstance
(
node
,
_AnimatedOperation
):
definition
.
update
(
kind
=
node
.
_op
,
inputs
=
[
encode
(
parent
)
for
parent
in
node
.
_parents
])
elif
isinstance
(
node
,
_AnimatedDiffClamp
):
definition
.
update
(
kind
=
"diff_clamp"
,
inputs
=
[
encode
(
node
.
_parent
)],
minimum
=
node
.
_min
,
maximum
=
node
.
_max
,
previous
=
node
.
_last_input
,
value
=
node
.
value
,
)
else
:
raise
TypeError
(
f"Unsupported animated node
{
type
(
node
).
__name__
}
"
)
encoded
[
identity
]
=
definition
return
{
"node"
:
identity
}
for
node
in
connected
.
values
():
encode
(
node
)
bindings
=
[[
tag
,
prop
,
id
(
node
)]
for
node
in
connected
.
values
()
for
tag
,
prop
in
node
.
attachments
()]
return
{
"id"
:
min
(
connected
),
"nodes"
:
list
(
encoded
.
values
()),
"bindings"
:
bindings
}
def
install
(
node
:
Any
,
*
,
detached_tag
:
int
|
None
=
None
)
->
dict
[
str
,
Any
]
|
None
:
"""Synchronize native graph ownership when a binding is attached or removed."""
from
.
animated
import
_backend
backend
=
_backend
()
handler
=
getattr
(
backend
,
"install_animation_graph"
,
None
)
if
handler
is
None
:
return
None
graph
=
serialize
(
node
)
tag
=
graph
[
"bindings"
][
0
][
0
]
if
graph
[
"bindings"
]
else
detached_tag
if
tag
is
not
None
:
handler
(
tag
,
graph
)
return
graph
Back
|
FazBrowse Home
|
New Git URL