print_tree.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from pydrk import SceneNodeType, PropertyType
  2. from .api import api
  3. def join(parent_path, child_name):
  4. if parent_path == "/":
  5. return f"/{child_name}"
  6. return f"{parent_path}/{child_name}"
  7. def print_tree():
  8. root_id = api.lookup_node_id("/")
  9. print_node_info(root_id)
  10. def print_node_info(parent_id, indent=0):
  11. ws = " "*4*indent
  12. for (child_name, child_id, child_type) in api.get_children(parent_id):
  13. match child_type:
  14. case SceneNodeType.ROOT:
  15. child_type = "root"
  16. case SceneNodeType.WINDOW:
  17. child_type = "window"
  18. case SceneNodeType.WINDOW_INPUT:
  19. child_type = "window_input"
  20. case SceneNodeType.KEYBOARD:
  21. child_type = "keyboard"
  22. case SceneNodeType.MOUSE:
  23. child_type = "mouse"
  24. case SceneNodeType.RENDER_LAYER:
  25. child_type = "render_layer"
  26. case SceneNodeType.RENDER_OBJECT:
  27. child_type = "render_object"
  28. case SceneNodeType.RENDER_MESH:
  29. child_type = "render_mesh"
  30. case SceneNodeType.RENDER_TEXT:
  31. child_type = "render_text"
  32. case SceneNodeType.RENDER_TEXTURE:
  33. child_type = "render_texture"
  34. case SceneNodeType.FONTS:
  35. child_type = "fonts"
  36. case SceneNodeType.FONT:
  37. child_type = "font"
  38. case SceneNodeType.LINE_POSITION:
  39. child_type = "line_position"
  40. desc = f"{ws}{child_name}:{child_id}/"
  41. desc += " "*(50 - len(desc))
  42. desc += f"[{child_type}]"
  43. print(desc)
  44. print_node_info(child_id, indent+1)
  45. for prop_name, prop_type in api.get_properties(parent_id):
  46. if prop_type == PropertyType.STR:
  47. prop_val = api.get_property(parent_id, prop_name)
  48. prop_val = f" = \"{prop_val}\""
  49. elif prop_type != PropertyType.BUFFER:
  50. prop_val = api.get_property(parent_id, prop_name)
  51. prop_val = f" = {prop_val}"
  52. else:
  53. prop_val = ""
  54. prop_type = PropertyType.to_str(prop_type)
  55. print(f"{ws}{prop_name}: {prop_type}{prop_val}")
  56. for sig in api.get_signals(parent_id):
  57. print(f"{ws}~{sig}")
  58. for slot_id, slot in api.get_slots(parent_id, sig):
  59. print(f"{ws}- '{slot}' ({slot_id})")
  60. for method_name in api.get_methods(parent_id):
  61. args, results = api.get_method(parent_id, method_name)
  62. args = [f"{name}: " + PropertyType.to_str(typ) for (name, typ) in args]
  63. results = [f"{name}: " + PropertyType.to_str(typ) for (name, typ) in results]
  64. method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
  65. print(f"{ws}{method_str}")