zhong (钟鹏群) před 1 týdnem
rodič
revize
d0deb62782
2 změnil soubory, kde provedl 63 přidání a 47 odebrání
  1. 63 47
      src/latest.py
  2. 0 0
      src/print.log

+ 63 - 47
src/latest.py

@@ -153,13 +153,9 @@ class SquareWindow:
         else:
             dark_outline = "black"  # fallback
             
-        self.canvas.create_rectangle(x, y, x + size, y + size, outline=dark_outline, fill=color, width=1)
-        
-        # Add number in the center of the square (ensure it's drawn last so it's not covered)
-        center_x = x + size // 2
-        center_y = y + size // 2
-        # 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))
+        # Create a semi-transparent effect using stipple pattern
+        # This creates a checkerboard-like pattern that simulates transparency
+        self.canvas.create_rectangle(x, y, x + size, y + size, outline=dark_outline, fill=color, width=1, stipple='gray50')
         
         # Draw a line segment at the bottom edge of the square (inside the square) only if size >= 50
         if size >= 50:
@@ -215,69 +211,89 @@ def folder_to_config(folder_path, skip_folder=[]):
     """
     import os
     
-    # 存储所有遇到的路径,按访问顺序编号
-    all_paths = [folder_path]  # 根目录作为第一个元素
-    path_to_number = {}  # 映射路径到编号
-    number_to_name = {}  # 映射编号到文件/文件夹名称
+    # 存储路径到编号的映射
+    path_to_number = {}
+    number_to_name = {}
+    
+    # 首先为根目录分配编号
+    path_to_number[folder_path] = 0
+    number_to_name[0] = os.path.basename(folder_path)
+    
+    # 使用栈进行迭代式深度优先遍历,确保正确处理父子关系
+    stack = [folder_path]
     
-    def dfs_collect_paths(path):
-        """深度优先收集所有路径"""
+    while stack:
+        current_path = stack.pop()
+        
         try:
-            items = os.listdir(path)
+            items = os.listdir(current_path)
             
+            # 获取当前目录的直接子项(过滤掉需要跳过的目录)
+            direct_children = []
             for item in items:
-                item_path = os.path.join(path, item)
-                all_paths.append(item_path)  # 将新路径添加到列表
+                item_path = os.path.join(current_path, item)
+                
+                # 检查是否是需要跳过的目录
+                if os.path.isdir(item_path) and os.path.basename(item_path) in skip_folder:
+                    continue
+                
+                direct_children.append(item_path)
+            
+            # 为所有直接子项分配编号
+            for item_path in direct_children:
+                if item_path not in path_to_number:
+                    number = len(path_to_number)
+                    path_to_number[item_path] = number
+                    number_to_name[number] = os.path.basename(item_path)
                 
+                # 如果是目录且不在跳过列表中,加入栈中待处理
                 if os.path.isdir(item_path):
-                    # 检查是否在跳过列表中
-                    if os.path.basename(item_path) not in skip_folder:
-                        dfs_collect_paths(item_path)  # 递归收集子目录
+                    stack.append(item_path)
+        
         except PermissionError:
             # 如果没有权限访问某个文件夹,则跳过
-            return
-    
-    # 收集所有路径
-    dfs_collect_paths(folder_path)
+            continue
     
-    # 为所有路径分配编号和名称
-    for idx, path in enumerate(all_paths):
-        number = idx + 1  # 编号从1开始
-        path_to_number[path] = number
-        number_to_name[number] = os.path.basename(path)  # 使用文件/文件夹的基本名称
-    
-    # 构建结果
+    # 构建结果 - 计算每个目录的直接子项数量
     result = []
     
     # 添加根目录信息
+    root_items = []
     try:
-        root_items = [item for item in os.listdir(folder_path) 
-                      if os.path.basename(os.path.join(folder_path, item)) not in skip_folder]
-        result.append((None, len(root_items)))  # 根目录用None表示
+        items = os.listdir(folder_path)
+        for item in items:
+            item_path = os.path.join(folder_path, item)
+            if not (os.path.isdir(item_path) and os.path.basename(item_path) in skip_folder):
+                root_items.append(item_path)
     except PermissionError:
-        result.append((None, 0))
+        pass
+    
+    result.append((None, len(root_items)))  # 根目录用None表示
     
-    # 为每个子目录添加信息
-    for path, number in path_to_number.items():
+    # 为每个目录添加信息(除了根目录)
+    for path in path_to_number:
         if path != folder_path and os.path.isdir(path):  # 排除根目录,只处理子目录
             try:
-                # 检查该目录是否在跳过列表中
-                dir_name = os.path.basename(path)
-                if dir_name in skip_folder:
-                    # 如果在跳过列表中,将其视为空文件夹
-                    result.append((number, 0))
-                else:
-                    sub_items = [item for item in os.listdir(path) 
-                                 if os.path.basename(os.path.join(path, item)) not in skip_folder]
-                    result.append((number, len(sub_items)))  # 使用该目录的编号
+                items = os.listdir(path)
+                # 计算当前目录的直接子项数量(过滤掉需要跳过的目录)
+                child_count = 0
+                for item in items:
+                    item_path = os.path.join(path, item)
+                    if not (os.path.isdir(item_path) and os.path.basename(item_path) in skip_folder):
+                        child_count += 1
+                
+                parent_number = path_to_number[path]
+                result.append((parent_number, child_count))
             except PermissionError:
-                result.append((number, 0))
+                # 如果无法访问目录,子项数量为0
+                parent_number = path_to_number[path]
+                result.append((parent_number, 0))
     
     return result, number_to_name
 
 
 if __name__ == "__main__":
-    config, path_info = folder_to_config(r"E:\agricultural_research_platform", skip_folder=["automatedDeployment", "node_modules", ".vscode", ".git"])
+    config, path_info = folder_to_config(r"E:\agricultural_research_platform", skip_folder=["automatedDeployment", "node_modules", ".vscode", ".git", "images"])
     print(config)
     app = SquareWindow(config, path_info)
     app.run()

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
src/print.log


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů