增加了保存到文件夹。

This commit is contained in:
dmy 2025-02-28 18:27:34 +08:00
parent 914761fb78
commit c20fa99f06
2 changed files with 40 additions and 4 deletions

View File

@ -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

View File

@ -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对话框以支持多选