print_tree.py 2.8 KB

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