up
This commit is contained in:
parent
438523c0ea
commit
39be40f81c
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# 目录图标工具 FilesTreeIco_Tool
|
||||
|
||||
在Windows上编辑配置来快速创建文件夹目录结构并设置图标
|
||||
|
||||
### ./图标
|
||||
|
||||
该路径下可放入自定义图片作为文件夹图标候选
|
||||
|
||||
### ./*.json
|
||||
|
||||
程序会依赖.json配置文件来记录目录结构和图标配置
|
55
main.py
55
main.py
@ -8,11 +8,12 @@ from typing import Dict, Optional
|
||||
from PIL import Image
|
||||
import subprocess
|
||||
import shutil
|
||||
from PIL import ImageTk
|
||||
|
||||
class ConfigEditorGUI:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.root.title("目录配置编辑器")
|
||||
self.root.title("目录图标工具 FilesTreeIco_Tool")
|
||||
self.root.geometry("800x600")
|
||||
|
||||
# 设置基本样式
|
||||
@ -37,7 +38,7 @@ class ConfigEditorGUI:
|
||||
self.main_frame = ttk.Frame(self.root, padding="10")
|
||||
self.main_frame.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
# 顶部工具栏
|
||||
# 顶部工具
|
||||
self._create_toolbar()
|
||||
|
||||
# 创建左右分栏
|
||||
@ -104,7 +105,7 @@ class ConfigEditorGUI:
|
||||
font=('微软雅黑', 10)
|
||||
).pack(anchor='w', pady=(0, 10))
|
||||
|
||||
# 创建图标显示区域
|
||||
# 创图标显示区域
|
||||
icon_frame = ttk.Frame(main_frame)
|
||||
icon_frame.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
@ -156,26 +157,18 @@ class ConfigEditorGUI:
|
||||
|
||||
# 加载实际图标
|
||||
icon_count = 1 # 从1开始计数,因为0被"无图标"占用
|
||||
for file in os.listdir('icons'):
|
||||
for file in os.listdir('图标'):
|
||||
if file.lower().endswith(('.ico', '.png')):
|
||||
try:
|
||||
icon_path = os.path.join('icons', file)
|
||||
icon_path = os.path.join('图标', file)
|
||||
if file.lower().endswith('.png'):
|
||||
# 创建预览图标(64x64)
|
||||
preview_size = 64
|
||||
original_icon = tk.PhotoImage(file=icon_path)
|
||||
|
||||
# 计算缩放比例
|
||||
scale = min(preview_size / original_icon.height(), preview_size / original_icon.width())
|
||||
scaled_w = int(original_icon.width() * scale)
|
||||
scaled_h = int(original_icon.height() * scale)
|
||||
|
||||
if scaled_w > 0 and scaled_h > 0:
|
||||
# 创建预览图标
|
||||
preview_icon = original_icon.subsample(
|
||||
max(1, original_icon.width() // scaled_w),
|
||||
max(1, original_icon.height() // scaled_h)
|
||||
)
|
||||
# 动态调整图标大小以适配预览
|
||||
max_size = 24
|
||||
preview_size = 32
|
||||
original_icon = Image.open(icon_path)
|
||||
# original_icon.thumbnail((max_size, max_size), Image.LANCZOS)
|
||||
original_icon = original_icon.resize((preview_size, preview_size), Image.LANCZOS)
|
||||
preview_icon = ImageTk.PhotoImage(original_icon)
|
||||
|
||||
# 创建图标按钮框架
|
||||
btn_frame = ttk.Frame(grid_frame)
|
||||
@ -241,7 +234,11 @@ class ConfigEditorGUI:
|
||||
# 原有的图标设置逻辑
|
||||
rel_path = os.path.relpath(icon_path)
|
||||
if rel_path not in self.icon_cache:
|
||||
self.icon_cache[rel_path] = tk.PhotoImage(file=icon_path)
|
||||
original_icon = Image.open(icon_path)
|
||||
# 动态调整图标大小以适配树状图
|
||||
max_size = 16
|
||||
original_icon.thumbnail((max_size, max_size), Image.LANCZOS)
|
||||
self.icon_cache[rel_path] = ImageTk.PhotoImage(original_icon)
|
||||
self.tree.item(item_id, image=self.icon_cache[rel_path])
|
||||
|
||||
path = self._get_item_path(item_id)
|
||||
@ -271,7 +268,7 @@ class ConfigEditorGUI:
|
||||
return path
|
||||
|
||||
def _create_tree_editor(self):
|
||||
"""创建右侧目录树编辑器"""
|
||||
"""创建右侧录树编辑器"""
|
||||
editor_frame = ttk.LabelFrame(self.paned, text="目录结构", padding="5")
|
||||
self.paned.add(editor_frame, weight=3)
|
||||
|
||||
@ -301,7 +298,7 @@ class ConfigEditorGUI:
|
||||
self._load_config_file(filename)
|
||||
|
||||
def _load_config_file(self, filename: str):
|
||||
"""加载指定的配置文件"""
|
||||
"""加载指定配置文件"""
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
self.folder_structure = json.load(f)
|
||||
@ -327,7 +324,11 @@ class ConfigEditorGUI:
|
||||
icon_path = content['_icon']
|
||||
try:
|
||||
if icon_path not in self.icon_cache:
|
||||
self.icon_cache[icon_path] = tk.PhotoImage(file=icon_path)
|
||||
original_icon = Image.open(icon_path)
|
||||
# 动态调整图标大小以适配树状图
|
||||
max_size = 16
|
||||
original_icon.thumbnail((max_size, max_size), Image.LANCZOS)
|
||||
self.icon_cache[icon_path] = ImageTk.PhotoImage(original_icon)
|
||||
icon = self.icon_cache[icon_path]
|
||||
except Exception as e:
|
||||
print(f"无法加载图标 {icon_path}: {str(e)}")
|
||||
@ -363,7 +364,7 @@ class ConfigEditorGUI:
|
||||
self.tree.item(selected[0], open=True)
|
||||
# 选中新节点
|
||||
self.tree.selection_set(new_item)
|
||||
# 确保新节点<EFBFBD><EFBFBD><EFBFBD>见
|
||||
# 确保新节点见
|
||||
self.tree.see(new_item)
|
||||
# 立即保存更改
|
||||
self.folder_structure = {"folders": self._get_folder_structure('')}
|
||||
@ -521,7 +522,7 @@ def create_folders(base_path: str, folders: Dict, current_file) -> None:
|
||||
subprocess.run(['attrib', '+s', '+h', desktop_ini_path], shell=True)
|
||||
# 设置icon文件为隐藏文件
|
||||
subprocess.run(['attrib', '+s', '+h', final_icon_path], shell=True)
|
||||
# 设置文件夹为只读
|
||||
# 设置文件夹为读
|
||||
subprocess.run(['attrib', '+r', folder_path], shell=True)
|
||||
|
||||
# 清除图标缓存
|
||||
@ -550,7 +551,7 @@ def main():
|
||||
root = tk.Tk()
|
||||
# 设置窗口图标
|
||||
try:
|
||||
root.iconbitmap("icons/app.ico")
|
||||
root.iconbitmap("图标/app.ico")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user