From c20fa99f068be7e2e6b33a8b790d4a131f25c5b7 Mon Sep 17 00:00:00 2001 From: dmy Date: Fri, 28 Feb 2025 18:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=88=B0=E6=96=87=E4=BB=B6=E5=A4=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 自动归类/core.py | 4 ++-- 自动归类/ui.py | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/自动归类/core.py b/自动归类/core.py index c0b5dff..d2131f2 100644 --- a/自动归类/core.py +++ b/自动归类/core.py @@ -75,6 +75,7 @@ def get_file_name_before_bracket(file_path): class Worker(QThread): progress = Signal(int) # 定义一个信号,用于传递进度 + destination_directory = Signal(str) def __init__(self, images_path: List[str], start_index: int = 0): super().__init__() @@ -88,6 +89,7 @@ class Worker(QThread): # image_path = r"D:/现场查看/" # 提取目录路径 new_dir_location = os.path.join(os.path.dirname(self.images_path[0]), "整理后") + self.destination_directory.emit(os.path.normpath(new_dir_location)) # start_index = 156 # 目录编号 # 以下是实际代码 # all_images = get_jpg_files(image_path) @@ -112,7 +114,5 @@ class Worker(QThread): os.system( f'copy "{os.path.normpath(image[0])}" "{os.path.normpath(new_file_path_name)}" /Y' ) - # shutil.copy(image[0], destination_path) print(f"copy {image[0]} {new_file_path_name}") - # print(group) self.start_index += 1 diff --git a/自动归类/ui.py b/自动归类/ui.py index 8bb29ab..efc0afe 100644 --- a/自动归类/ui.py +++ b/自动归类/ui.py @@ -16,8 +16,13 @@ from PySide6.QtWidgets import ( QProgressBar, # 导入 QProgressBar 类 ) from PySide6.QtWidgets import QHeaderView -from PySide6.QtGui import QStandardItemModel, QStandardItem +from PySide6.QtGui import ( + QStandardItemModel, + QStandardItem, + QRegularExpressionValidator, +) # 修改 QRegExpValidator 为 QRegularExpressionValidator from PySide6.QtCore import Slot # 导入 Slot 装饰器 +from PySide6.QtCore import Qt, QRegularExpression # 导入 Qt 和 QRegularExpression 类 import core @@ -42,7 +47,18 @@ class FolderSelectorApp(QMainWindow): # 创建文件开始计数 self.start_index_label = QLabel("目录开始基数:", self) self.start_index_text = QLineEdit(self) - self.start_index_text.setText("0") + self.start_index_text.setText("1") + # 添加验证器以只接受正整数,并且当数字超过2位时,第一位不能是0 + regex = QRegularExpression( + r"^(?!0\d)\d+$" + ) # 正则表达式确保当数字超过2位时,第一位不能是0 + validator = QRegularExpressionValidator(regex, self) + self.start_index_text.setValidator(validator) + # 创建目标文件夹 + self.destination_directory_label = QLabel("保存到文件夹:", self) + self.destination_directory_text = QLineEdit(self) + self.destination_directory_text.setReadOnly(True) + self.destination_directory_text.setCursorMoveStyle(Qt.VisualMoveStyle) # 创建QTableView self.table_view = QTableView(self) @@ -63,10 +79,15 @@ class FolderSelectorApp(QMainWindow): start_index_layout.addWidget(self.start_index_label) start_index_layout.addWidget(self.start_index_text) start_index_layout.addStretch(2) + # 保持到文件夹布局 + destination_directory_layout = QHBoxLayout() + destination_directory_layout.addWidget(self.destination_directory_label) + destination_directory_layout.addWidget(self.destination_directory_text) # 选择文件的布局 layout = QVBoxLayout() # layout.addWidget(self.select_folders_button) layout.addLayout(start_index_layout) + layout.addLayout(destination_directory_layout) layout.addWidget(self.select_files_button) layout.addWidget(self.arrage_button) layout.addWidget(self.table_view) @@ -128,6 +149,14 @@ class FolderSelectorApp(QMainWindow): """更新进度条的值""" self.progress_bar.setValue(value) + def finished_notification(self): + """显示完成通知""" + QMessageBox.information(self, "完成", "整理完成!") + + def update_destination_directory(self, path): + """更新目标文件夹路径""" + self.destination_directory_text.setText(path) + def arrage_pic(self): # 获取table_view中第一列的数据 name_list = [] @@ -149,6 +178,10 @@ class FolderSelectorApp(QMainWindow): ) self.worker.progress.connect(self.update_progress) # 连接信号到槽函数 self.worker.finished.connect(self.worker.deleteLater) # 任务完成后删除 worker + self.worker.finished.connect(self.finished_notification) # 完成后提示 + self.worker.destination_directory.connect( + self.update_destination_directory + ) # 给出目标文件夹路径 self.worker.start() # 启动线程 def resizeEvent(self, event): @@ -160,6 +193,9 @@ class FolderSelectorApp(QMainWindow): dialog = QFileDialog(self) dialog.setWindowTitle("请选择多个文件") dialog.setFileMode(QFileDialog.ExistingFiles) # 设置为文件选择模式 + dialog.setNameFilter( + "JPG Files (*.jpg *.JPG)" + ) # 设置文件过滤器,只允许选择jpg文件 dialog.setOption( QFileDialog.DontUseNativeDialog, False ) # 使用Qt对话框以支持多选