modify a bit

This commit is contained in:
Julian Freeman
2025-08-10 13:30:40 -04:00
parent b3728f14c8
commit 60cc9ae91b

19
main.py
View File

@@ -1,7 +1,8 @@
import sys
import os
import json
from pathlib import Path
# from pathlib import Path
from datetime import date
from PySide6.QtWidgets import (
QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel,
QPushButton, QFileDialog, QLineEdit, QListWidget, QMessageBox, QHBoxLayout, QInputDialog
@@ -15,12 +16,12 @@ class FileRenamer(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("批量文件重命名工具")
self.setMinimumSize(600, 400)
self.setMinimumSize(800, 600)
self.setAcceptDrops(True)
self.files = []
self.initial_path = ""
self.prefix = ""
self.prefix = f"AI-{date.today().strftime('%Y%m%d')}-"
self.categories = self.load_categories()
central_widget = QWidget()
@@ -30,7 +31,7 @@ class FileRenamer(QMainWindow):
self.info_label = QLabel("拖拽文件到此区域")
self.info_label.setAlignment(Qt.AlignCenter)
self.info_label.setStyleSheet("border: 2px dashed #aaa; padding: 20px; font-size: 16px;")
self.info_label.setStyleSheet("border: 2px dashed #aaa; padding: 20px; font-size: 20px;")
layout.addWidget(self.info_label)
path_layout = QHBoxLayout()
@@ -39,14 +40,18 @@ class FileRenamer(QMainWindow):
self.path_label = QLabel("未设置")
path_layout.addWidget(self.path_btn)
path_layout.addWidget(self.path_label)
path_layout.setStretch(0, 1)
path_layout.setStretch(1, 3)
layout.addLayout(path_layout)
prefix_layout = QHBoxLayout()
self.prefix_btn = QPushButton("设置前缀")
self.prefix_btn.clicked.connect(self.set_prefix)
self.prefix_label = QLabel("当前前缀: (无)")
self.prefix_label = QLabel(f"当前前缀: {self.prefix if self.prefix else '(无)'}")
prefix_layout.addWidget(self.prefix_btn)
prefix_layout.addWidget(self.prefix_label)
prefix_layout.setStretch(0, 1)
prefix_layout.setStretch(1, 3)
layout.addLayout(prefix_layout)
self.name_input = QLineEdit()
@@ -68,6 +73,7 @@ class FileRenamer(QMainWindow):
event.acceptProposedAction()
def dropEvent(self, event: QDropEvent):
self.files.clear()
for url in event.mimeData().urls():
file_path = url.toLocalFile()
if os.path.isfile(file_path):
@@ -151,6 +157,9 @@ class FileRenamer(QMainWindow):
if __name__ == "__main__":
app = QApplication(sys.argv)
f = app.font()
f.setPointSize(20)
app.setFont(f)
window = FileRenamer()
window.show()
sys.exit(app.exec())