print_tree.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from pydrk import SceneNodeType, PropertyType, CallArgType, Expr
  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(node_path="/", depth=None):
  8. print(node_path)
  9. print_node_info(node_path, depth, indent=1)
  10. def print_node_info(parent_path, depth, indent):
  11. if indent - 1 == depth:
  12. return
  13. ws = " "*4*indent
  14. for (child_name, child_id, child_type) in api.get_children(parent_path):
  15. match child_type:
  16. case SceneNodeType.ROOT:
  17. child_type = "root"
  18. case SceneNodeType.WINDOW:
  19. child_type = "window"
  20. case SceneNodeType.WINDOW_INPUT:
  21. child_type = "window_input"
  22. case SceneNodeType.KEYBOARD:
  23. child_type = "keyboard"
  24. case SceneNodeType.MOUSE:
  25. child_type = "mouse"
  26. case SceneNodeType.LAYER:
  27. child_type = "layer"
  28. case SceneNodeType.OBJECT:
  29. child_type = "object"
  30. case SceneNodeType.VECTOR_ART:
  31. child_type = "vector_art"
  32. case SceneNodeType.TEXT:
  33. child_type = "text"
  34. case SceneNodeType.TEXTURE:
  35. child_type = "texture"
  36. case SceneNodeType.FONTS:
  37. child_type = "fonts"
  38. case SceneNodeType.FONT:
  39. child_type = "font"
  40. case SceneNodeType.CHAT_VIEW:
  41. child_type = "chat_view"
  42. case SceneNodeType.BUTTON:
  43. child_type = "button"
  44. case SceneNodeType.SETTING:
  45. child_type = "setting"
  46. desc = f"{ws}{child_name}:{child_id}/"
  47. desc += " "*(50 - len(desc))
  48. desc += f"[{child_type}]"
  49. print(desc)
  50. if parent_path == "/":
  51. child_path = "/" + child_name
  52. else:
  53. child_path = parent_path + "/" + child_name
  54. print_node_info(child_path, depth, indent+1)
  55. for prop in api.get_properties(parent_path):
  56. prop_val = api.get_property_value(parent_path, prop.name)
  57. def fmt_str(pv):
  58. return pv if isinstance(pv, Expr) else f"\"{pv}\""
  59. def fmt_f32(pv):
  60. return pv if isinstance(pv, Expr) else f"{pv:.2f}"
  61. if prop.type == PropertyType.STR:
  62. prop_val = "[" + ", ".join(fmt_str(pv) for pv in prop_val) + "]"
  63. elif prop.type == PropertyType.FLOAT32:
  64. prop_val = "[" + ", ".join(fmt_f32(pv) for pv in prop_val) + "]"
  65. if len(prop_val) == 1:
  66. prop_val = prop_val[0]
  67. prop_val = f" = {prop_val}"
  68. prop_type = PropertyType.to_str(prop.type)
  69. print(f"{ws}{prop.name}: {prop_type}{prop_val}")
  70. if prop.depends:
  71. print(f"{ws} depends: {prop.depends}")
  72. for sig in api.get_signals(parent_path):
  73. print(f"{ws}~{sig}")
  74. for slot_name, slot_id in api.get_slots(parent_path, sig):
  75. print(f"{ws}- '{slot_name}' ({slot_id})")
  76. for method_name in api.get_methods(parent_path):
  77. args, results = api.get_method(parent_path, method_name)
  78. args = [f"{name}: " + CallArgType.to_str(typ) for (name, _, typ) in args]
  79. results = [f"{name}: " + CallArgType.to_str(typ) for (name, _, typ) in results]
  80. method_str = f"{method_name}(" + ", ".join(args) + ") -> (" + ", ".join(results) + ")"
  81. print(f"{ws}{method_str}")