Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
CookSleep authored Jul 18, 2024
1 parent 2c62476 commit ee2bd2c
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 7 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

## 简介

这是一个使用PyQt5开发的项目文件导出工具。它允许用户通过拖拽项目文件夹到工具窗口中,自动生成项目的文件结构和代码内容的文本文件。该工具旨在方便开发者直接通过上下文向LLM传递项目详细信息
这是一个使用PyQt5开发的项目文件导出工具。它允许用户通过拖拽或选择文件夹的方式将项目文件夹到工具窗口中,然后自动生成项目的文件结构和具体内容(可选)的文本文件

本项目的代码几乎完全由GPT-4o编写,我仅提供需求和建议。
该工具旨在方便开发者直接通过上下文向LLM传递项目的详细信息。

本项目的代码几乎完全由GPT-4o、Claude3.5 Sonnet编写,我仅提供需求和建议。

## 功能特点

- 自动生成项目的文件结构树
- 提取每个文件的代码内容并写入输出文件
- 提取每个文件的代码内容并写入输出文件(可选)
- 使用XML标签包裹文件内容,便于LLM更好地读取文件
- 将导出的文本文件放置在导入的项目文件目录中
- 使用HarmonyOS Sans SC Regular字体,界面美观
- 实时显示导出状态和输出文件路径

## 使用方法
Expand All @@ -21,10 +22,9 @@
2. 下载最新版本的 `Project_Exporter.zip`
3. 解压 `Project_Exporter.zip`
4. 双击运行 `项目文件导出工具.exe`
5. 将需要导入的项目文件夹拖入程序窗口。
6. 在输出完成后,前往刚刚导入的项目目录(在输出框也有显示)查找输出文件。
5. 将需要导入的项目文件夹拖入程序窗口/点击“选择文件夹”选择需要导出的文件夹
6. 在输出完成后,前往刚刚选择的项目目录(在输出框也有显示)查找输出文件。
7. 复制粘贴全文到LLM的上下文窗口中,继续你和LLM的项目研究之旅。
8. 如果您在Mac电脑上运行本程序显示“无法打开 “ProjectExportTool”,因为Apple无法检查其是否包含恶意软件”,请在终端中输入以下命令:“sudo spctl --master-disable”,然后回车输入密码,再重新运行本程序即可。

## 贡献

Expand Down
Binary file added icon-3种尺寸.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 174 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import sys
import os
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QLabel, QLineEdit, QCheckBox, QPushButton, QFileDialog
)
from PyQt5.QtGui import QFontDatabase, QFont, QIcon
from PyQt5.QtCore import Qt

class ProjectExportTool(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("项目文件导出工具")
self.setGeometry(100, 100, 500, 400) # 调整窗口大小
self.initUI()

def initUI(self):
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QVBoxLayout(self.central_widget)

# 加载图标
icon_path = os.path.join(os.path.dirname(__file__), 'icon-3种尺寸.ico')
if os.path.exists(icon_path):
self.setWindowIcon(QIcon(icon_path))
else:
print("图标文件未找到")

# 加载并设置字体
font_path = os.path.join(os.path.dirname(__file__), 'HarmonyOS_Sans_SC_Regular.ttf')
font_id = QFontDatabase.addApplicationFont(font_path)
if font_id != -1:
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
font = QFont(font_family, 12) # 增加基础字体大小
self.setFont(font)
else:
print("字体加载失败,使用系统默认字体")

# 创建标题
title_label = QLabel("项目文件导出工具", self)
title_label.setAlignment(Qt.AlignCenter)
title_label.setStyleSheet("font-size: 24px; font-weight: bold; margin: 15px 0;")
self.layout.addWidget(title_label)

# 创建拖拽框
self.drag_label = QLabel("拖入项目文件夹", self)
self.drag_label.setAlignment(Qt.AlignCenter)
self.drag_label.setStyleSheet("""
QLabel {
border: 2px dashed #aaa;
border-radius: 5px;
padding: 30px;
background-color: #f8f8f8;
color: #555;
font-size: 16px;
}
""")
self.drag_label.setMinimumHeight(120)
self.layout.addWidget(self.drag_label)

# 创建选择文件夹按钮
self.select_button = QPushButton("选择文件夹", self)
self.select_button.setStyleSheet("""
QPushButton {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 4px;
font-size: 16px;
}
QPushButton:hover {
background-color: #45a049;
}
""")
self.select_button.clicked.connect(self.select_folder)
self.layout.addWidget(self.select_button)

# 创建复选框
self.export_tree_only_checkbox = QCheckBox("只导出文件结构", self)
self.export_tree_only_checkbox.setStyleSheet("font-size: 14px; margin-top: 10px;")
self.layout.addWidget(self.export_tree_only_checkbox)

# 创建状态编辑框
self.status_edit = QLineEdit(self)
self.status_edit.setReadOnly(True)
self.status_edit.setPlaceholderText('输出状态将显示在这里')
self.status_edit.setStyleSheet("""
QLineEdit {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f9f9f9;
font-size: 14px;
}
""")
self.layout.addWidget(self.status_edit)

self.central_widget.setLayout(self.layout)
self.setAcceptDrops(True)

def select_folder(self):
dir_path = QFileDialog.getExistingDirectory(self, "选择项目文件夹")
if dir_path:
self.process_folder(dir_path)

def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.acceptProposedAction()

def dropEvent(self, event):
urls = event.mimeData().urls()
if urls:
dir_path = urls[0].toLocalFile()
self.process_folder(dir_path)

def process_folder(self, dir_path):
if os.path.isdir(dir_path):
self.status_edit.clear()
project_name = os.path.basename(dir_path)
if self.export_tree_only_checkbox.isChecked():
output_file = os.path.join(dir_path, f'{project_name}_文件结构.txt')
else:
output_file = os.path.join(dir_path, f'{project_name}_文结构和内容.txt')
self.generate_file_structure(dir_path, output_file)
self.status_edit.setText(f'导出完成:{output_file}')

def generate_file_structure(self, root_dir, output_file):
with open(output_file, 'w', encoding='utf-8') as f:
f.write(self.get_directory_tree(root_dir, output_file))
if not self.export_tree_only_checkbox.isChecked():
for dirpath, _, filenames in os.walk(root_dir):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
if filepath == output_file:
continue
normalized_path = os.path.normpath(filepath).replace('\\', '/')
f.write(f"\n<file path=\"{normalized_path}\">\n")
try:
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()
f.write(content + "\n")
except Exception as e:
f.write(f"无法读取文件内容: {e}\n")
f.write("</file>\n")

def get_directory_tree(self, root_dir, output_file):
tree = []
for dirpath, dirnames, filenames in os.walk(root_dir):
level = dirpath.replace(root_dir, '').count(os.sep)
indent = '│ ' * (level)
tree.append(f"{indent}├── {os.path.basename(dirpath)}/")
subindent = '│ ' * (level + 1)
for f in filenames:
if os.path.join(dirpath, f) == output_file:
continue
tree.append(f"{subindent}├── {f}")
return "\n".join(tree) + "\n"

if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyle('Fusion')

# 设置全局字体
font_path = os.path.join(os.path.dirname(__file__), 'HarmonyOS_Sans_SC_Regular.ttf')
font_id = QFontDatabase.addApplicationFont(font_path)
if font_id != -1:
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
font = QFont(font_family, 12) # 增加基础字体大小
app.setFont(font)

mainWin = ProjectExportTool()
mainWin.show()
sys.exit(app.exec_())
48 changes: 48 additions & 0 deletions project_exporter.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- mode: python ; coding: utf-8 -*-

import os

block_cipher = None

# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(SPEC))
# 定义输出目录为当前目录
output_dir = os.path.join(current_dir, 'build')

a = Analysis(['main.py'],
pathex=[],
binaries=[],
datas=[('HarmonyOS_Sans_SC_Regular.ttf', '.'), ('README.md', '.'), ('LICENSE', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)

pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)

exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='项目文件导出工具',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='icon-3种尺寸.ico',
distpath=output_dir) # 指定输出目录

0 comments on commit ee2bd2c

Please sign in to comment.