MetaCoreEngineV2/Demos/B_Checkbox.py
2026-01-13 17:06:06 +08:00

50 lines
1.3 KiB
Python

import sys
from pathlib import Path
lui_path = Path(__file__).parent.parent.absolute()
builtin_path = lui_path / "Builtin"
sys.path.insert(0, str(lui_path))
sys.path.insert(0, str(builtin_path))
import panda3d.core
import lui
import panda3d
panda3d.lui = lui
sys.modules["panda3d.lui"] = lui
from DemoFramework import DemoFramework
from LUICheckbox import LUICheckbox
import random
f = DemoFramework()
f.prepare_demo("LUICheckbox")
# Constructor
f.add_constructor_parameter("checked", "False")
f.add_constructor_parameter("label", "'Checkbox'")
# Functions
f.add_public_function("get_checked", [], "bool")
f.add_public_function("toggle_checked", [], "bool")
f.add_public_function("set_checked", [("checked", "bool")])
f.add_public_function("get_label", [], "UILabel")
f.add_property("checked", "bool")
f.add_property("label", "LUILabel")
# Events
f.add_event("changed")
f.construct_sourcecode("LUICheckbox")
# Create the checkbox
checkbox = LUICheckbox(parent=f.get_widget_node())
f.set_actions({
"Set Checked": lambda: checkbox.set_checked(True),
"Set Unchecked": lambda: checkbox.set_checked(False),
"Toggle Checked": lambda: checkbox.toggle_checked(),
"Set Random Text": lambda: checkbox.get_label().set_text("Text: " + str(random.randint(100, 10000))),
})
run()