Skip to content

Commit c2bbbfd

Browse files
committed
Add signal connection to tests/6-expose-python-to-godot/
1 parent 04b75df commit c2bbbfd

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
Godot Engine .* - https://godotengine.org
22

33
Godot-Python .* \(CPython .*\)
4+
MyPythonNode: _on_tree_entered
45
MyPythonNode: _ready
56
MyPythonNode: hello\(42\)
67
MyPythonNode: hello_static_method\(GDString\('World'\)\)
78
MyPythonNode: hello_class_method\(GDArray\(\[42, "World"\]\), MyPythonNode\(foo=1, _read_write_prop=Vector2\(x=0.0, y=0.0\)\)\)
89
GDScript: simple_signal received
910
GDScript: data_signal received with count=99, message=test message
11+
MyPythonNode: _on_tree_exiting

tests/6-expose-python-to-godot/main.tscn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88

99
[node name="Node" type="Node" parent="."]
1010
script = ExtResource("1_ig7tw")
11+
12+
[connection signal="tree_entered" from="MyPythonNode" to="MyPythonNode" method="_on_tree_entered"]

tests/6-expose-python-to-godot/node.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import field
33
from typing import ClassVar
44

5-
from godot import GDAny, GDArray, GDString, Vector2, signal, classes, gddataclass
5+
from godot import GDAny, GDArray, GDString, Vector2, signal, classes, gddataclass, GDCallable
66

77

88
@gddataclass(init=False)
@@ -38,6 +38,13 @@ def read_write_prop(self, val: Vector2) -> None:
3838

3939
def _ready(self):
4040
print("MyPythonNode: _ready", flush=True)
41+
self.tree_exiting.connect(GDCallable.create(self, "_on_tree_exiting"))
42+
43+
def _on_tree_entered(self):
44+
print("MyPythonNode: _on_tree_entered", flush=True)
45+
46+
def _on_tree_exiting(self):
47+
print("MyPythonNode: _on_tree_exiting", flush=True)
4148

4249
def hello(self, a: int) -> GDString:
4350
print(f"MyPythonNode: hello({a!r})", flush=True)

0 commit comments

Comments
 (0)