import sysfrom PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QGroupBox, QRadioButton, QComboBox, QTextEdit, QFileDialog, QMessageBox)from PyQt6.QtCore import Qt, QThread, pyqtSignalfrom PyQt6.QtGui import QIconclass FileOrganizerGUI(QMainWindow): def __init__(self): super().__init__() self.init_ui() def init_ui(self): self.setWindowTitle("文件组织工具 - File Organizer") self.setFixedSize(750, 720) # 设置样式 self.setStyleSheet(""" QMainWindow { background-color: #f0f2f5; } QLabel { color: #2c3e50; font-size: 13px; } QPushButton { background-color: #3498db; color: white; border: none; padding: 8px 20px; border-radius: 6px; font-size: 13px; font-weight: bold; } QPushButton:hover { background-color: #2980b9; } QPushButton:pressed { background-color: #21618c; } QPushButton:disabled { background-color: #bdc3c7; color: #7f8c8d; } QLineEdit { padding: 8px 12px; border: 2px solid #dcdde1; border-radius: 6px; font-size: 13px; background-color: white; } QLineEdit:focus { border-color: #3498db; } QComboBox { padding: 8px 12px; border: 2px solid #dcdde1; border-radius: 6px; font-size: 13px; background-color: white; min-width: 120px; } QComboBox:hover { border-color: #3498db; } QTextEdit { border: 2px solid #dcdde1; border-radius: 6px; font-size: 12px; font-family: 'Consolas', 'Courier New', monospace; background-color: #fafafa; } QGroupBox { font-weight: bold; border: 2px solid #dcdde1; border-radius: 8px; margin-top: 10px; padding-top: 10px; background-color: white; } QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 10px 0 10px; color: #2c3e50; } QRadioButton { font-size: 13px; color: #2c3e50; spacing: 8px; } QRadioButton::indicator { width: 18px; height: 18px; } """) # 中央部件 central_widget = QWidget() self.setCentralWidget(central_widget) main_layout = QVBoxLayout() main_layout.setSpacing(15) main_layout.setContentsMargins(25, 25, 25, 25) central_widget.setLayout(main_layout) # 设置区域 settings_group = QGroupBox("设置") settings_layout = QVBoxLayout() settings_group.setLayout(settings_layout) # 根目录选择 root_dir_layout = QHBoxLayout() root_dir_label = QLabel("📁 根目录:") root_dir_label.setFixedWidth(80) root_dir_layout.addWidget(root_dir_label) self.root_dir_edit = QLineEdit() self.root_dir_edit.setPlaceholderText("请选择要处理的根目录...") root_dir_layout.addWidget(self.root_dir_edit) self.browse_root_btn = QPushButton("浏览...") self.browse_root_btn.setFixedWidth(100) self.browse_root_btn.clicked.connect(self.browse_root_directory) root_dir_layout.addWidget(self.browse_root_btn) settings_layout.addLayout(root_dir_layout) # 保存目录选择(独立于根目录) save_dir_layout = QHBoxLayout() save_dir_label = QLabel("💾 保存目录:") save_dir_label.setFixedWidth(80) save_dir_layout.addWidget(save_dir_label) self.save_dir_edit = QLineEdit() self.save_dir_edit.setPlaceholderText("请选择保存组织后文件的目录...") save_dir_layout.addWidget(self.save_dir_edit) self.browse_save_btn = QPushButton("浏览...") self.browse_save_btn.setFixedWidth(100) self.browse_save_btn.clicked.connect(self.browse_save_directory) save_dir_layout.addWidget(self.browse_save_btn) settings_layout.addLayout(save_dir_layout) # 文件和分隔符 - 水平紧凑布局 options_layout = QHBoxLayout() options_layout.setSpacing(30) # 模式选择 mode_group = QGroupBox("组织模式") mode_group.setStyleSheet(""" QGroupBox { font-weight: bold; border: 2px solid #dcdde1; border-radius: 8px; margin-top: 10px; padding-top: 10px; background-color: white; margin-right: 0px; } QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 10px 0 10px; color: #2c3e50; } """) mode_layout = QVBoxLayout() mode_group.setLayout(mode_layout) self.simple_radio = QRadioButton("简单模式 - 每层单独命名") self.simple_radio.setToolTip("例: 4-1-1-001.bmp → 4/1/1/") self.cumulative_radio = QRadioButton("累积模式 - 每层包含完整路径") self.cumulative_radio.setToolTip("例: 4-1-1-001.bmp → 4/4-1/4-1-1/") self.cumulative_radio.setChecked(True) mode_layout.addWidget(self.simple_radio) mode_layout.addWidget(self.cumulative_radio) options_layout.addWidget(mode_group) # 分隔符选择 sep_group = QGroupBox("文件名分隔符") sep_group.setStyleSheet(""" QGroupBox { font-weight: bold; border: 2px solid #dcdde1; border-radius: 8px; margin-top: 10px; padding-top: 10px; background-color: white; margin-left: 0px; } QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 10px 0 10px; color: #2c3e50; } """) sep_layout = QVBoxLayout() sep_group.setLayout(sep_layout) sep_combo_layout = QHBoxLayout() self.sep_combo = QComboBox() self.sep_combo.addItems(['- (连字符)', '_ (下划线)', '. (点)', '自定义']) sep_combo_layout.addWidget(self.sep_combo) self.sep_custom_edit = QLineEdit() self.sep_custom_edit.setPlaceholderText("输入自定义分隔符") self.sep_custom_edit.setFixedWidth(130) self.sep_custom_edit.setEnabled(False) sep_combo_layout.addWidget(self.sep_custom_edit) sep_layout.addLayout(sep_combo_layout) self.sep_combo.currentIndexChanged.connect(self.on_separator_changed) options_layout.addWidget(sep_group) options_layout.addStretch() settings_layout.addLayout(options_layout) # 文件后缀筛选 ext_layout = QHBoxLayout() ext_label = QLabel("📄 文件后缀:") ext_label.setFixedWidth(80) ext_layout.addWidget(ext_label) self.ext_edit = QLineEdit() self.ext_edit.setPlaceholderText("例如: .bmp, .jpg, .png (多个用逗号分隔,留空则处理所有文件)") ext_layout.addWidget(self.ext_edit) settings_layout.addLayout(ext_layout) main_layout.addWidget(settings_group) # 日志区域 log_group = QGroupBox("操作日志") log_layout = QVBoxLayout() log_group.setLayout(log_layout) self.log_text = QTextEdit() self.log_text.setReadOnly(True) self.log_text.setMaximumHeight(420) self.log_text.setStyleSheet(""" QTextEdit { background-color: #fafafa; line-height: 1.5; } """) log_layout.addWidget(self.log_text) # 底部控制栏 - 四个按钮居中 bottom_widget = QWidget() bottom_layout = QHBoxLayout() bottom_widget.setLayout(bottom_layout) # 清除日志按钮 self.clear_btn = QPushButton("🗑 清除日志") self.clear_btn.clicked.connect(self.clear_log) self.clear_btn.setStyleSheet(""" QPushButton { background-color: #95a5a6; padding: 8px 20px; min-width: 100px; } QPushButton:hover { background-color: #7f8c8d; } """) bottom_layout.addWidget(self.clear_btn) # 执行移动按钮 self.execute_btn = QPushButton("▶ 执行递归创建文件夹且移动文件") self.execute_btn.setStyleSheet(""" QPushButton { background-color: #e74c3c; padding: 8px 20px; min-width: 120px; } QPushButton:hover { background-color: #c0392b; } """) bottom_layout.addWidget(self.execute_btn) # 撤销按钮 self.undo_btn = QPushButton("↩ 撤销") self.undo_btn.setEnabled(False) self.undo_btn.setStyleSheet(""" QPushButton { background-color: #3498db; padding: 8px 20px; min-width: 100px; } QPushButton:hover { background-color: #2980b9; } QPushButton:enabled { background-color: #f39c12; } QPushButton:enabled:hover { background-color: #e67e22; } """) bottom_layout.addWidget(self.undo_btn) # 停止按钮 self.stop_btn = QPushButton("⏹ 停止") self.stop_btn.setEnabled(False) self.stop_btn.setStyleSheet(""" QPushButton { background-color: #95a5a6; padding: 8px 20px; min-width: 100px; } QPushButton:hover { background-color: #7f8c8d; } QPushButton:enabled { background-color: #e67e22; } QPushButton:enabled:hover { background-color: #d35400; } """) bottom_layout.addWidget(self.stop_btn) # 让四个按钮整体居中 bottom_layout.insertStretch(0) bottom_layout.insertStretch(5) log_layout.addWidget(bottom_widget) main_layout.addWidget(log_group) def on_separator_changed(self, index): if index == 3: # 自定义 self.sep_custom_edit.setEnabled(True) self.sep_custom_edit.setFocus() else: self.sep_custom_edit.setEnabled(False) def browse_root_directory(self): dir_path = QFileDialog.getExistingDirectory(self, "选择根目录(扫描文件的目录)") if dir_path: self.root_dir_edit.setText(dir_path) def browse_save_directory(self): dir_path = QFileDialog.getExistingDirectory(self, "选择保存目录(存放组织后文件的目录)") if dir_path: self.save_dir_edit.setText(dir_path) def clear_log(self): self.log_text.clear()def main(): app = QApplication(sys.argv) app.setStyle('Fusion') app.setWindowIcon(QIcon()) window = FileOrganizerGUI() window.show() sys.exit(app.exec())if __name__ == "__main__": main()