增加了保存到文件夹。
This commit is contained in:
parent
914761fb78
commit
c20fa99f06
|
|
@ -75,6 +75,7 @@ def get_file_name_before_bracket(file_path):
|
||||||
|
|
||||||
class Worker(QThread):
|
class Worker(QThread):
|
||||||
progress = Signal(int) # 定义一个信号,用于传递进度
|
progress = Signal(int) # 定义一个信号,用于传递进度
|
||||||
|
destination_directory = Signal(str)
|
||||||
|
|
||||||
def __init__(self, images_path: List[str], start_index: int = 0):
|
def __init__(self, images_path: List[str], start_index: int = 0):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -88,6 +89,7 @@ class Worker(QThread):
|
||||||
# image_path = r"D:/现场查看/"
|
# image_path = r"D:/现场查看/"
|
||||||
# 提取目录路径
|
# 提取目录路径
|
||||||
new_dir_location = os.path.join(os.path.dirname(self.images_path[0]), "整理后")
|
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 # 目录编号
|
# start_index = 156 # 目录编号
|
||||||
# 以下是实际代码
|
# 以下是实际代码
|
||||||
# all_images = get_jpg_files(image_path)
|
# all_images = get_jpg_files(image_path)
|
||||||
|
|
@ -112,7 +114,5 @@ class Worker(QThread):
|
||||||
os.system(
|
os.system(
|
||||||
f'copy "{os.path.normpath(image[0])}" "{os.path.normpath(new_file_path_name)}" /Y'
|
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(f"copy {image[0]} {new_file_path_name}")
|
||||||
# print(group)
|
|
||||||
self.start_index += 1
|
self.start_index += 1
|
||||||
|
|
|
||||||
40
自动归类/ui.py
40
自动归类/ui.py
|
|
@ -16,8 +16,13 @@ from PySide6.QtWidgets import (
|
||||||
QProgressBar, # 导入 QProgressBar 类
|
QProgressBar, # 导入 QProgressBar 类
|
||||||
)
|
)
|
||||||
from PySide6.QtWidgets import QHeaderView
|
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 Slot # 导入 Slot 装饰器
|
||||||
|
from PySide6.QtCore import Qt, QRegularExpression # 导入 Qt 和 QRegularExpression 类
|
||||||
import core
|
import core
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,7 +47,18 @@ class FolderSelectorApp(QMainWindow):
|
||||||
# 创建文件开始计数
|
# 创建文件开始计数
|
||||||
self.start_index_label = QLabel("目录开始基数:", self)
|
self.start_index_label = QLabel("目录开始基数:", self)
|
||||||
self.start_index_text = QLineEdit(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
|
# 创建QTableView
|
||||||
self.table_view = QTableView(self)
|
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_label)
|
||||||
start_index_layout.addWidget(self.start_index_text)
|
start_index_layout.addWidget(self.start_index_text)
|
||||||
start_index_layout.addStretch(2)
|
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 = QVBoxLayout()
|
||||||
# layout.addWidget(self.select_folders_button)
|
# layout.addWidget(self.select_folders_button)
|
||||||
layout.addLayout(start_index_layout)
|
layout.addLayout(start_index_layout)
|
||||||
|
layout.addLayout(destination_directory_layout)
|
||||||
layout.addWidget(self.select_files_button)
|
layout.addWidget(self.select_files_button)
|
||||||
layout.addWidget(self.arrage_button)
|
layout.addWidget(self.arrage_button)
|
||||||
layout.addWidget(self.table_view)
|
layout.addWidget(self.table_view)
|
||||||
|
|
@ -128,6 +149,14 @@ class FolderSelectorApp(QMainWindow):
|
||||||
"""更新进度条的值"""
|
"""更新进度条的值"""
|
||||||
self.progress_bar.setValue(value)
|
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):
|
def arrage_pic(self):
|
||||||
# 获取table_view中第一列的数据
|
# 获取table_view中第一列的数据
|
||||||
name_list = []
|
name_list = []
|
||||||
|
|
@ -149,6 +178,10 @@ class FolderSelectorApp(QMainWindow):
|
||||||
)
|
)
|
||||||
self.worker.progress.connect(self.update_progress) # 连接信号到槽函数
|
self.worker.progress.connect(self.update_progress) # 连接信号到槽函数
|
||||||
self.worker.finished.connect(self.worker.deleteLater) # 任务完成后删除 worker
|
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() # 启动线程
|
self.worker.start() # 启动线程
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
|
|
@ -160,6 +193,9 @@ class FolderSelectorApp(QMainWindow):
|
||||||
dialog = QFileDialog(self)
|
dialog = QFileDialog(self)
|
||||||
dialog.setWindowTitle("请选择多个文件")
|
dialog.setWindowTitle("请选择多个文件")
|
||||||
dialog.setFileMode(QFileDialog.ExistingFiles) # 设置为文件选择模式
|
dialog.setFileMode(QFileDialog.ExistingFiles) # 设置为文件选择模式
|
||||||
|
dialog.setNameFilter(
|
||||||
|
"JPG Files (*.jpg *.JPG)"
|
||||||
|
) # 设置文件过滤器,只允许选择jpg文件
|
||||||
dialog.setOption(
|
dialog.setOption(
|
||||||
QFileDialog.DontUseNativeDialog, False
|
QFileDialog.DontUseNativeDialog, False
|
||||||
) # 使用Qt对话框以支持多选
|
) # 使用Qt对话框以支持多选
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue