zhong (钟鹏群) 1 settimana fa
parent
commit
5bf1ab6e55
1 ha cambiato i file con 22 aggiunte e 9 eliminazioni
  1. 22 9
      src/latest.py

+ 22 - 9
src/latest.py

@@ -1,11 +1,13 @@
 import tkinter as tk
 
 class SquareWindow:
-    def __init__(self, config):
+    def __init__(self, config, path_info=None):
         # Configuration: [(parent_number, count), ...] 
         # (None, 11) means draw 11 squares inside square #0 (the main square)
         # (2, 7) means draw 7 squares inside square #2
+        # path_info: Optional dict mapping square numbers to file/folder names
         self.config = config
+        self.path_info = path_info if path_info is not None else {}
         
         # Set window size to 1000x1000 pixels (needed for calculate_squares)
         self.window_size = 1000
@@ -117,6 +119,8 @@ class SquareWindow:
             number: Number to display in the center
             parent_number: The number of the parent square (None if no parent)
         """
+        # Get the name associated with this square number if available
+        name = self.path_info.get(number, str(number))
         # Calculate the level of the square (how deep it is in the hierarchy)
         level = self.get_square_level(number)
         
@@ -157,10 +161,14 @@ class SquareWindow:
         # Use black text for better contrast against any background
         self.canvas.create_text(center_x, center_y, text=str(number), fill="black", font=("Arial", 10))
         
-        # Draw a line segment at the bottom edge of the square (inside the square) only if size >= 25
+        # Draw a line segment at the bottom edge of the square (inside the square) only if size >= 50
         if size >= 50:
             line_y = y + size - 20  # Just above the bottom edge of the square
             self.canvas.create_line(x, line_y, x + size, line_y, fill="black", width=1)
+            
+            # Draw the name between the square and the line
+            name_y = y + size - 10  # Position the name between square and line
+            self.canvas.create_text(x + size // 2, name_y, text=name, fill="black", font=("Arial", 8))
         
         # Record the square's position information
         self.square_positions[number] = (x, y, size, parent_number)
@@ -200,14 +208,17 @@ def folder_to_config(folder_path, skip_folder=[]):
         skip_folder: 不需要遍历的文件夹名称列表
         
     Returns:
-        list: 包含(父级编号, 子项数量)元组的列表
-               (None, n) 表示根目录下有n个子项
+        tuple: (config_list, path_info_dict)
+               config_list: 包含(父级编号, 子项数量)元组的列表
+                           (None, n) 表示根目录下有n个子项
+               path_info_dict: 映射编号到文件/文件夹名称的字典
     """
     import os
     
     # 存储所有遇到的路径,按访问顺序编号
     all_paths = [folder_path]  # 根目录作为第一个元素
     path_to_number = {}  # 映射路径到编号
+    number_to_name = {}  # 映射编号到文件/文件夹名称
     
     def dfs_collect_paths(path):
         """深度优先收集所有路径"""
@@ -229,9 +240,11 @@ def folder_to_config(folder_path, skip_folder=[]):
     # 收集所有路径
     dfs_collect_paths(folder_path)
     
-    # 为所有路径分配编号
+    # 为所有路径分配编号和名称
     for idx, path in enumerate(all_paths):
-        path_to_number[path] = idx + 1  # 编号从1开始
+        number = idx + 1  # 编号从1开始
+        path_to_number[path] = number
+        number_to_name[number] = os.path.basename(path)  # 使用文件/文件夹的基本名称
     
     # 构建结果
     result = []
@@ -260,11 +273,11 @@ def folder_to_config(folder_path, skip_folder=[]):
             except PermissionError:
                 result.append((number, 0))
     
-    return result
+    return result, number_to_name
 
 
 if __name__ == "__main__":
-    config = folder_to_config(r"E:\agricultural_research_platform", skip_folder=["automatedDeployment", "node_modules", ".vscode"])
+    config, path_info = folder_to_config(r"E:\agricultural_research_platform", skip_folder=["automatedDeployment", "node_modules", ".vscode", ".git"])
     print(config)
-    app = SquareWindow(config)
+    app = SquareWindow(config, path_info)
     app.run()