-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImgProcess.pyw
1624 lines (1508 loc) · 79.9 KB
/
ImgProcess.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import time
import re
import urllib.parse
import pygetwindow as gw
from PyQt5.QtWidgets import QLabel, QMenu, QMessageBox, QPushButton, QVBoxLayout, QFileDialog, QListWidget, QListWidgetItem, QLineEdit
from PyQt5.QtWidgets import QComboBox, QFrame, QStackedWidget, QProgressBar, QApplication, QWidget, QDesktopWidget,QHBoxLayout, QShortcut
from PyQt5.QtGui import QBrush, QFont, QIcon,QColor,QDesktopServices, QPainter, QKeySequence, QRegExpValidator
from PyQt5.QtCore import QCoreApplication, QPropertyAnimation, QRect, QSettings,Qt, QUrl, QTimer, QThread, pyqtSignal, QRegExp
from PIL import Image
from psd_tools import PSDImage
class Worker(QThread):
finished_signal = pyqtSignal()
archiving_thread_start_signal = pyqtSignal()
progress_update = pyqtSignal(int)
def __init__(self, parent):
super().__init__(parent)
self.file_right_list = parent.file_right_list
self.start1 = False
def run(self):
if self.start1:
self.archiving_thread()
def archiving_thread(self):
total_psd_files = 0 # 初始化总文件数量
jpg_files = 0 # 初始化已处理的 JPG 文件数量
for i in range(self.file_right_list.count()):
item = self.file_right_list.item(i)
# 检查item是否为空
if item is None:
continue
folder_path = os.path.join(item.data(Qt.UserRole), "已修")
total_psd_files += sum(1 for file_name in os.listdir(folder_path) if file_name.endswith(".psd") and os.path.isfile(os.path.join(folder_path, file_name)))
for i in range(self.file_right_list.count()):
item = self.file_right_list.item(i)
# 检查item是否为空
if item is None:
continue
folder_path = os.path.join(item.data(Qt.UserRole), "已修")
self.right_list_path = item.data(Qt.UserRole)
self.file_path_right = os.path.join(self.right_list_path, "已修")
if os.path.exists(self.file_path_right):
self.psd_folder_right = os.path.join(self.file_path_right, "psd")
# 遍历目标文件夹中的文件
for file_name in os.listdir(self.file_path_right):
# 检查文件类型是否为 PSD
if os.path.isfile(os.path.join(self.file_path_right, file_name)) and file_name.endswith(".psd"):
try:
# 导出为 JPG
jpg_file_name = os.path.splitext(file_name)[0] + ".jpg"
jpg_path = os.path.join(self.right_list_path, "已修", jpg_file_name)
psd = PSDImage.open(os.path.join(self.file_path_right, file_name))
image = psd.compose()
# 将 RGBA 转换为 RGB
if image.mode == "RGBA":
image = image.convert("RGB")
image.save(jpg_path, "JPEG")
# 发送子进度更新信号
jpg_files += 1
if total_psd_files != 0:
total_progress = (jpg_files / total_psd_files) * 100
self.progress_update.emit(int(total_progress))
else:
self.progress_update.emit(100)
# 处理事件队列,确保及时更新UI
QCoreApplication.processEvents()
except Exception as e:
full_path = os.path.join(self.file_path_right, file_name)
print(f"无法处理文件: {file_name} ({full_path})")
destination_path = os.path.join(self.file_path_right, file_name)
source_path = os.path.join(self.psd_folder_right, file_name)
try:
# 移动 PSD 文件到 "psd" 文件夹
os.rename(destination_path, source_path)
except FileExistsError:
# 在文件名中添加后缀
base, extension = os.path.splitext(file_name)
counter = 1
new_psd_dest_path = os.path.join(self.psd_folder_right, f"{base}_backup_{counter}{extension}")
# 生成唯一的文件名
while os.path.exists(new_psd_dest_path):
counter += 1
new_psd_dest_path = os.path.join(self.psd_folder_right, f"{base}_backup_{counter}{extension}")
# 移动文件到新路径
os.rename(destination_path, new_psd_dest_path)
# 当线程耗时任务完成时,直接发送总进度为100%
self.progress_update.emit(100)
time.sleep(0.5)
self.start1 = False
self.finished_signal.emit()
class ImgProcess(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
###########设置默认项
self.settings = QSettings("lemon-o", "ImgProcess")
# 从设置中获取上次输入的名称和数量
self.last_folder_name = self.settings.value("last_folder_name", "")
self.last_num_folders = int(self.settings.value("last_num_folders", "1"))
self.folder_name_entry.setText(self.last_folder_name)
self.num_folders_entry.setText(str(self.last_num_folders))
#设置默认文件类型
last_input_left = self.settings.value("last_input_left", "", str)
self.filter_combo.setEditText(last_input_left)
self.filter_combo.lineEdit().textChanged.connect(lambda text: self.settings.setValue("last_input_left", text))
#设置默认排序方式
last_selected_right = self.settings.value("last_selected_right", 0, int)
self.sort_combo.setCurrentIndex(last_selected_right)
self.sort_combo.currentIndexChanged.connect(lambda index: self.settings.setValue("last_selected_right", index) )
#设置默认窗口大小
# self.load_window_size()
#初始化变量
self.parent_dir = None
self.dir_path = None
self.file_type = ""
self.new_position = None
self.animation = None # 初始化动画属性
self.psd_found = False
self.thread_running = False
self.is_dragging = False
self.expanded = None
self.double_clicked = False
self.monitor_top_border = 0
self.animation_finished = False
self.selected_page1 = None
self.selected_page2 = None
self.selected_page3 = None
# 初始化列表
self.clicked_folder_path = []
self.target_folder_titles = []
self.clicked_folder_names = []
self.renamed_folders = []
# 创建一个线程实例
self.thread = Worker(self)
self.thread.finished_signal.connect(self.thread_finished)
# self.thread.archiving_thread_start_signal.connect(self.refresh)
#创建UI界面
def init_ui(self):
# 设置界面
# self.setMinimumSize(650, 450) # 设置最小大小
# self.setMaximumSize(1080, 1080) # 设置最大大小
# self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) # 设置大小策略
# 窗口始终在最顶层&去除默认标题栏
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
# 获取显示器宽高
screen = QDesktopWidget().screenGeometry()
self.screen_height = screen.height()
self.screen_width = screen.width()
#设置窗口大小
if 1000 <= self.screen_height <= 1200:
self.fixed_height = 430
self.fixed_width = 600
elif 1300 <= self.screen_height <= 1500:
self.fixed_height = 500
self.fixed_width = 680
elif 2000 <= self.screen_height <= 2200:
self.fixed_height = 700
self.fixed_width = 1000
else:
if self.screen_height > self.screen_width:
if 1000 <= self.screen_width <= 1200:
self.fixed_height = 430
self.fixed_width = 600
elif 1300 <= self.screen_width <= 1500:
self.fixed_height = 500
self.fixed_width = 680
elif 2000 <= self.screen_width <= 2200:
self.fixed_height = 700
self.fixed_width = 1000
else:
self.fixed_height = int((45 / 108) * screen.height())
self.fixed_width = int((65 / 192) * screen.width())
self.setGeometry(100, 100, self.fixed_width, self.fixed_height)
# 窗口默认居中
size = self.geometry()
x = int((screen.width() - size.width()) / 2)
y = int((screen.height() - size.height()) / 2)
self.move(x, y)
#设置缩进边距这样才能绘制窗口投影
self.margin = round((5 / 430) * self.fixed_height)
#设置窗口图标
self.setWindowIcon(QIcon('./icon/ImgProcess.ico'))
# 创建堆叠小部件
self.stackedWidget = QStackedWidget(self)
# 连接currentChanged信号到槽函数
self.stackedWidget.currentChanged.connect(self.update_window_size)
#创建自定义标题栏和dock栏 ############################################################
self.title_label = QLabel('ImgProcess')
self.title_label.setStyleSheet('color: #ffffff;')
button_width = int((25 / 650) * self.fixed_width)
button_height = int((25 / 450) * self.fixed_height)
button_width_close = int((35 / 650) * self.fixed_width)
button_height_close = int((25 / 450) * self.fixed_height)
self.button_width_dock = int((4 / 90) * self.fixed_width)
self.button_height_dock = int((4 / 90) * self.fixed_width)
button_style_close = """
QPushButton {
color: #ffffff;
border: 0px;
}
QPushButton:hover {
background-color: #f55b31;
border: 0px;
}
"""
button_style_top = """
QPushButton {
color: #ffffff;
border: 0px;
}
QPushButton:hover {
background-color: #2c2c2c;
border: 0px;
}
"""
button_style_dock = """
QPushButton {
color: #ffffff; /* 未点击按钮的普通样式 */
border: 0px;
}
QPushButton:checked {
background-color: #ffffff; /* 已点击按钮的普通样式 */
border-radius: 3%;
border: 0px;
}
QPushButton:hover {
background-color: #dedfe0; /* 未点击按钮的hover样式 */
border-radius: 3%;
border: 0px;
}
QPushButton:checked:hover {
background-color: #ffffff; /* 已点击按钮的hover样式 */
border-radius: 3%;
border: 0px;
}
"""
self.main_icon = QPushButton()
self.main_icon.setFixedSize(button_width, button_height)
self.main_icon.setStyleSheet("border: 0px solid white;")
self.main_icon.setIcon(QIcon('./icon/ImgProcess.ico'))
self.github_button = QPushButton()
self.github_button.setFixedSize(button_width, button_height)
self.github_button.setStyleSheet(button_style_top)
self.github_button.setIcon(QIcon('./icon/github.ico'))
self.github_button.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://github.com/lemon-o/ImgProcess")))
self.minimize_button = QPushButton()
self.minimize_button.setFixedSize(button_width, button_height)
self.minimize_button.setStyleSheet(button_style_top)
self.minimize_button.setIcon(QIcon('./icon/minimize.ico'))
self.minimize_button.clicked.connect(self.showMinimized) # 点击按钮最小化窗口
self.close_button = QPushButton()
self.close_button.setFixedSize(button_width_close, button_height_close)
self.close_button.setStyleSheet(button_style_close)
self.close_button.setIcon(QIcon('./icon/close.ico'))
self.close_button.clicked.connect(self.close) # 点击关闭按钮关闭窗口
#创建左侧dock
self.dock_button_1 = QPushButton()
self.setup_button(self.dock_button_1, 0, button_style_dock)
self.dock_button_1.setIcon(QIcon('./icon/GSfolders.ico'))
self.dock_button_2 = QPushButton()
self.setup_button(self.dock_button_2, 1, button_style_dock)
self.dock_button_2.setIcon(QIcon('./icon/FoldersFilter.ico'))
self.dock_button_2.setChecked(True) #默认选择第二个按钮
self.dock_button_3 = QPushButton()
self.setup_button(self.dock_button_3, 2, button_style_dock)
self.dock_button_3.setIcon(QIcon('./icon/Cmingoz.ico'))
# 上面是自定义标题栏和dock栏 ############################################################
# 创建GSfolders界面 ############################################################
# 创建标签1
self.folder_name_label = QLabel('名称')
self.folder_name_label.setStyleSheet('color: #3b3b3b; margin-top: 5px; margin-bottom: 0px;')
# 创建标签2
self.folder_num_label = QLabel('数量')
self.folder_num_label.setStyleSheet('color: #3b3b3b; margin-top: 5px; margin-bottom: 0px;')
#创建输入框
linedit_style_1 = 'background-color: white; color: #272727; border-radius: 6px; border: 1px solid #C5C5C5;'
linedit_height_1 = int((30 / 450) * self.fixed_height)
self.num_folders_entry = QLineEdit()
self.num_folders_entry.setFixedHeight(linedit_height_1)
self.num_folders_entry.setPlaceholderText("输入文件夹数量")
self.num_folders_entry.setStyleSheet(linedit_style_1)
self.folder_name_entry = QLineEdit()
self.folder_name_entry.setFixedHeight(linedit_height_1)
self.folder_name_entry.setPlaceholderText("输入文件夹名称")
self.folder_name_entry.setStyleSheet(linedit_style_1)
#创建按钮
button_height_build = int((30 / 450) * self.fixed_height)
button_style_build = """
QPushButton {
background-color: #f5f5f5;
color: #3b3b3b;
border-radius: 6%; /* 圆角半径使用相对单位,可以根据需要调整 */
border: 1px solid #f5f5f5;
}
QPushButton:hover {
background-color: #0773fc;
color: #ffffff;
border: 0.1em solid #0773fc; /* em为相对单位 */
}
"""
self.select_path_button = QPushButton("创建文件夹")
self.select_path_button.setFixedHeight(button_height_build)
self.select_path_button.setStyleSheet(button_style_build)
self.select_path_button.clicked.connect(self.select_path)
# 创建子界面布局管理器
self.GSfolders_page = QWidget()
#创建水平布局管理器
hbox_name = QHBoxLayout()
hbox_name.addWidget(self.folder_name_label)
hbox_name.addWidget(self.folder_name_entry)
hbox_num = QHBoxLayout()
hbox_num.addWidget(self.folder_num_label)
hbox_num.addWidget(self.num_folders_entry)
# 创建主窗口的垂直布局管理器
vbox_main1 = QVBoxLayout(self.GSfolders_page)
vbox_main1.addLayout(hbox_name)
vbox_main1.addLayout(hbox_num)
vbox_main1.addWidget(self.select_path_button)
vbox_main1.addSpacing(15)
# 将界面添加到堆叠小部件中
self.stackedWidget.addWidget(self.GSfolders_page)
# 上面是GSfolders界面 ############################################################
# 创建FoldersFilter界面 ############################################################
#创建按钮
button_height1 = int((30 / 450) * self.fixed_height)
button_style = """
QPushButton {
background-color: #f5f5f5;
color: #3b3b3b;
border-radius: 6%; /* 圆角半径使用相对单位,可以根据需要调整 */
border: 1px solid #f5f5f5;
}
QPushButton:hover {
background-color: #0773fc;
color: #ffffff;
border: 0.1em solid #0773fc; /* em为相对单位 */
}
"""
self.folder_button = QPushButton('选择文件夹', self)
self.folder_button.setFixedHeight(button_height1)
self.folder_button.setStyleSheet(button_style)
self.folder_button.clicked.connect(self.select_folder)
self.reset_button = QPushButton('清空列表', self)
self.reset_button.setFixedHeight(button_height1)
self.reset_button.setStyleSheet(button_style)
self.reset_button.clicked.connect(self.reset)
self.refresh_button = QPushButton('刷新列表', self)
self.refresh_button.setFixedHeight(button_height1)
self.refresh_button.setStyleSheet(button_style)
self.refresh_button.clicked.connect(self.refresh)
# 创建标签1
self.folder_label = QLabel('已选择的文件夹')
self.folder_label.setStyleSheet('color: #3b3b3b; margin-top: 5px; margin-bottom: 0px;')
#创建下拉框
combo_width = int((85 / 650) * self.fixed_width)
combo_height = int((30 / 450) * self.fixed_height)
combo_style_1 = 'QComboBox { color: #3b3b3b; border: 1px solid #C5C5C5; border-radius: 4%; margin-top: 10px; padding-left:20px;} QComboBox::drop-down { background-color: #C5C5C5; border: none; }'
combo_style_2 = 'QComboBox { color: #3b3b3b; border: 1px solid #C5C5C5; border-radius: 4%; margin-top: 10px; padding-left:20px;} QComboBox::drop-down { background-color: #C5C5C5; border: none; }'
self.filter_combo = QComboBox() # 文件类型选择
self.filter_combo.setFixedSize(combo_width, combo_height)
self.filter_combo.setStyleSheet(combo_style_1)
self.filter_combo.setEditable(True)
self.file_type = []
self.filter_combo.activated.connect(self.select_folder)
self.sort_combo = QComboBox()#排序选择
self.sort_combo.setFixedSize(combo_width, combo_height)
self.sort_combo.setStyleSheet(combo_style_2)
sort_options = ["升序", "降序"]
for option in sort_options:
self.sort_combo.addItem(option)
self.sort_combo.activated.connect(self.folders_sort)
#创建标签2
label_style_3 = 'color: #3b3b3b; margin-top: 10px; margin-bottom: 0px; margin-left: 0px;'
label_style_4 = 'color: #3b3b3b; margin-top: 10px; margin-bottom: 0px; margin-left: 0px;'
self.folder_type_label = QLabel('文件筛选类型:')
self.folder_type_label.setStyleSheet(label_style_3)
self.folder_sort_label = QLabel('列表排序方式:')
self.folder_sort_label.setStyleSheet(label_style_4)
#创建标签3
label_style_1 = 'color: #3b3b3b; margin-top: 0px; margin-bottom: 0px;'
label_style_2 = 'color: #3b3b3b; margin-top: 0px; margin-bottom: 0px; margin-left: 0px;color: #B6A338;'
self.folder_left_label = QLabel('不含')
self.folder_left_label.setStyleSheet(label_style_1)
self.folder_left_num_label = QLabel()
self.folder_left_num_label.setStyleSheet(label_style_2)
self.folder_right_label = QLabel('含有')
self.folder_right_label.setStyleSheet(label_style_1)
self.folder_right_num_label = QLabel()
self.folder_right_num_label.setStyleSheet(label_style_2)
# 创建列表
list_style = 'background-color: white; color: #272727; border-radius: 6%; border: 1px solid #C5C5C5;'
self.file_left_list = QListWidget()
self.file_left_list.setStyleSheet(list_style)
self.file_right_list = QListWidget()
self.file_right_list.setStyleSheet(list_style)
self.file_filter_folders_list = QListWidget()
self.file_filter_folders_list.setStyleSheet(list_style)
# 创建一个定时器对象
self.timer = QTimer()
self.countdown_label = QLabel(self)
self.countdown_label.setText("90 秒后自动归档")
self.countdown_label.setStyleSheet("color: #3b3b3b; margin-top: 10px; margin-bottom: 0px; margin-left: 0px; color: rgba(0, 0, 0, 0.1);")
#创建进度条
self.progress_bar = QProgressBar()
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(100)
self.progress_bar.setRange(0, 100)
self.progress_bar.setValue(self.progress_bar.minimum())
self.progress_bar.setStyleSheet("QProgressBar {color: transparent;border: 1px solid #F0F0F0 ;border-radius: 4% ;text-align: center;} QProgressBar::chunk {background-color: #51B163;border-radius: 2% ;}")
bar_height = int((10 / 450) * self.fixed_height)
self.progress_bar.setFixedHeight(bar_height) # 设置进度条的高度
# 创建水平布局管理器
hbox1_left = QHBoxLayout()
hbox1_left.addWidget(self.folder_button)
hbox2_left = QHBoxLayout()
hbox2_left.addWidget(self.reset_button)
hbox2_left.addWidget(self.refresh_button)
hbox3_left = QHBoxLayout()
hbox3_left.addWidget(self.folder_label)
hbox4_left = QHBoxLayout() # 筛选的文件夹显示框
hbox4_left.addWidget(self.file_filter_folders_list)
hbox5_left = QHBoxLayout()
hbox5_left.addWidget(self.folder_type_label)
hbox5_left.addWidget(self.filter_combo)
hbox6_left = QHBoxLayout()
hbox6_left.addWidget(self.folder_sort_label)
hbox6_left.addWidget(self.sort_combo)
hbox7_left = QHBoxLayout()
hbox7_left.addWidget(self.countdown_label)
hbox1_right = QHBoxLayout()
hbox1_right.addWidget(self.folder_left_label)
hbox1_right.addWidget(self.folder_left_num_label)
hbox1_right.addWidget(self.folder_right_label)
hbox1_right.addWidget(self.folder_right_num_label)
hbox2_right = QHBoxLayout()
hbox2_right.addWidget(self.file_left_list)
hbox2_right.addWidget(self.file_right_list)
hbox3_right = QHBoxLayout()
hbox3_right.addWidget(self.progress_bar)
# 创建垂直布局管理器
vbox1_Pack = QWidget()
new_pack_width = int((190 / 650) * self.fixed_width) # 设置 容器 的宽度
vbox1_Pack.setFixedWidth(new_pack_width)
vbox1_Pack.setContentsMargins(0, 0, 0, 0) # 调整边距
vbox1 = QVBoxLayout(vbox1_Pack)
vbox1.setContentsMargins(0, 0, 0, 0) # 调整边距
vbox1.addSpacing(20) # 添加()像素的空白占位
vbox1.addLayout(hbox1_left)
vbox1.addSpacing(5) # 添加()像素的空白占位
vbox1.addLayout(hbox2_left)
vbox1.addSpacing(15) # 添加()像素的空白占位
vbox1.addLayout(hbox3_left)
vbox1.addLayout(hbox4_left)
vbox1.addSpacing(15) # 添加()像素的空白占位
vbox1.addLayout(hbox5_left)
vbox1.addLayout(hbox6_left)
vbox1.addLayout(hbox7_left)
vbox1.addSpacing(25) # 添加()像素的空白占位
vbox2 = QVBoxLayout()
vbox2.addSpacing(0) # 添加()像素的空白占位
vbox2.addLayout(hbox1_right)
vbox2.addLayout(hbox2_right)
vbox2.addLayout(hbox3_right)
vbox2.addSpacing(10) # 添加()像素的空白占位
# 创建子界面布局管理器
self.FoldersFilter_page = QWidget()
# 创建水平布局管理器
hbox_main_page2 = QHBoxLayout(self.FoldersFilter_page)
hbox_main_page2.addWidget(vbox1_Pack)
hbox_main_page2.addSpacing(26) # 添加()像素的空白占位
hbox_main_page2.addLayout(vbox2)
self.stackedWidget.addWidget(self.FoldersFilter_page) # 将布局放进小部件
# 上面是FoldersFilter界面 #############################################################
# 创建Cmingoz界面 #############################################################
linedit_style_3 = 'background-color: white; color: #272727; border-radius: 6px; border: 1px solid #C5C5C5;'
linedit_height_3 = int((30 / 450) * self.fixed_height)
self.cm_input = QLineEdit()
self.cm_input.setStyleSheet(linedit_style_3)
self.cm_input.setFixedHeight(linedit_height_3)
validator1 = QRegExpValidator(QRegExp(r'^[0-9]+(\.[0-9]+)?$'))
self.cm_input.setValidator(validator1)
self.in_input = QLineEdit()
self.in_input.setStyleSheet(linedit_style_3)
self.in_input.setFixedHeight(linedit_height_3)
validator2 = QRegExpValidator(QRegExp(r'^[0-9]+(\.[0-9]+)?$'))
self.in_input.setValidator(validator2)
self.g_input = QLineEdit()
self.g_input.setStyleSheet(linedit_style_3)
self.g_input.setFixedHeight(linedit_height_3)
validator3 = QRegExpValidator(QRegExp(r'^[0-9]+(\.[0-9]+)?$'))
self.g_input.setValidator(validator3)
self.oz_input = QLineEdit()
self.oz_input.setStyleSheet(linedit_style_3)
self.oz_input.setFixedHeight(linedit_height_3)
validator4 = QRegExpValidator(QRegExp(r'^[0-9]+(\.[0-9]+)?$'))
self.oz_input.setValidator(validator4)
label_style_1 = 'color: #3B3E41; margin-top: 0px; margin-bottom: 0px;'
self.cm_label = QLabel("厘米")
self.cm_label.setStyleSheet(label_style_1)
self.equal2 = QLabel("=")
self.equal2.setStyleSheet(label_style_1)
self.in_label = QLabel("英寸")
self.in_label.setStyleSheet(label_style_1)
self.goz_result = QLabel()
self.goz_result.setStyleSheet(label_style_1)
self.g_label = QLabel("克")
self.g_label.setStyleSheet(label_style_1)
self.equal = QLabel("=")
self.equal.setStyleSheet(label_style_1)
self.oz_label = QLabel("盎司")
self.oz_label.setStyleSheet(label_style_1)
self.cmin_result = QLabel()
self.cmin_result.setStyleSheet(label_style_1)
#创建按钮
button_width_copy = int((90 / 650) * self.fixed_width)
button_height_copy = int((30 / 450) * self.fixed_height)
button_style_copy = """
QPushButton {
background-color: #f5f5f5;
color: #3b3b3b;
border-radius: 6%; /* 圆角半径使用相对单位,可以根据需要调整 */
border: 1px solid #f5f5f5;
}
QPushButton:hover {
background-color: #0773fc;
color: #ffffff;
border: 0.1em solid #0773fc; /* em为相对单位 */
}
"""
self.inch_copy_button = QPushButton("复制结果F1")
self.inch_copy_button.setStyleSheet(button_style_copy)
self.inch_copy_button.setFixedSize(button_width_copy, button_height_copy)
self.ounce_copy_button = QPushButton("复制结果F2")
self.ounce_copy_button.setStyleSheet(button_style_copy)
self.ounce_copy_button.setFixedSize(button_width_copy, button_height_copy)
self.convert_cm_to_inch()
self.convert_inch_to_cm()
self.convert_g_to_ounce()
self.convert_ounce_to_g()
self.cm_input.textChanged.connect(self.convert_cm_to_inch)
self.in_input.textChanged.connect(self.convert_inch_to_cm)
self.g_input.textChanged.connect(self.convert_g_to_ounce)
self.oz_input.textChanged.connect(self.convert_ounce_to_g)
self.inch_copy_button.clicked.connect(self.copy_cmin_result)
self.ounce_copy_button.clicked.connect(self.copy_goz_result)
# 创建布局管理器
inch_layout = QHBoxLayout()
inch_layout.addWidget(self.cmin_result)
inch_layout.addSpacing(10)
inch_layout.addWidget(self.inch_copy_button)
inch2_layout = QHBoxLayout()
inch2_layout.addWidget(self.cm_input)
inch2_layout.addWidget(self.cm_label)
inch2_layout.addWidget(self.equal)
inch2_layout.addWidget(self.in_input)
inch2_layout.addWidget(self.in_label)
ounce_layout = QHBoxLayout()
ounce_layout.addWidget(self.goz_result)
ounce_layout.addSpacing(0)
ounce_layout.addWidget(self.ounce_copy_button)
ounce2_layout = QHBoxLayout()
ounce2_layout.addWidget(self.g_input)
ounce2_layout.addWidget(self.g_label)
ounce2_layout.addWidget(self.equal2)
ounce2_layout.addWidget(self.oz_input)
ounce2_layout.addWidget(self.oz_label)
# 创建子界面布局管理器
self.Cmingoz_page = QWidget()
main_page3 = QVBoxLayout(self.Cmingoz_page)
main_page3.addSpacing(12)
main_page3.addLayout(inch2_layout)
main_page3.addLayout(inch_layout)
main_page3.addSpacing(36)
main_page3.addLayout(ounce2_layout)
main_page3.addLayout(ounce_layout)
main_page3.addSpacing(12)
# 将界面添加到堆叠小部件中
self.stackedWidget.addWidget(self.Cmingoz_page)
self.shortcut_return = QShortcut(QKeySequence(Qt.Key_F1), self)
self.shortcut_return.activated.connect(self.copy_cmin_result)
self.shortcut_return = QShortcut(QKeySequence(Qt.Key_F2), self)
self.shortcut_return.activated.connect(self.copy_goz_result)
# 上面是Cmingoz界面 ############################################################
# 创建自定义标题栏水平布局管理器
hbox_top = QHBoxLayout()
hbox_top.setContentsMargins(0, 0, 0, 0) # 去除边距
hbox_top.setSpacing(0) # 设置控件之间的间距为0
hbox_top.addSpacing(self.margin) # 添加()像素的空白占位
hbox_top.addWidget(self.main_icon)
hbox_top.addWidget(self.title_label)
hbox_top.addStretch(1)
hbox_top.addWidget(self.github_button)
hbox_top.addWidget(self.minimize_button)
hbox_top.addWidget(self.close_button)
hbox_top.addSpacing(self.margin)
# 创建dock和主窗口水平布局管理器
hbox_main = QHBoxLayout()
hbox_main.addSpacing(self.margin) # 添加()像素的空白占位
vbox_dock_widget = QWidget() # 创建一个新容器
new_width1 = int((5 / 90) * self.fixed_width) # 设置 容器 的宽度
vbox_dock_widget.setFixedWidth(new_width1)
vbox_dock = QVBoxLayout(vbox_dock_widget)
left_margin = int(((5 / 90) * self.fixed_width - self.button_width_dock) // 2)
vbox_dock.setContentsMargins(left_margin , 0, 0, 0) # 调整边距
vbox_dock.setSpacing(0) # 设置控件之间的间距为0
vbox_dock.addWidget(self.dock_button_1)
vbox_dock.addSpacing(5)
vbox_dock.addWidget(self.dock_button_2)
vbox_dock.addSpacing(5)
vbox_dock.addWidget(self.dock_button_3)
vbox_dock.addSpacing(5)
vbox_dock.addStretch(1)
##### 上面是dock部分 #######
hbox_main.addWidget(vbox_dock_widget)
hbox_main.addWidget(self.stackedWidget)
hbox_main.addSpacing(10)
# 主布局
main_layout = QVBoxLayout()
main_layout.setContentsMargins(0, 0, 0, 0) # 去除边距
main_layout.addSpacing(self.margin) # 添加()像素的空白占位
main_layout.addLayout(hbox_top)
main_layout.addLayout(hbox_main)
self.setLayout(main_layout) # 将main_layout贴在父窗口上
self.stackedWidget.setCurrentIndex(1) # 初始页面为page2
# 设置窗口背景透明
self.setAttribute(Qt.WA_TranslucentBackground)
# 创建垂直分隔线添加到page2
self.vline = QFrame(self.FoldersFilter_page)
self.vline.setFrameShape(QFrame.VLine)
vline_x = int((217 / 650) * self.fixed_width) # 设置垂直分隔线的位置
vline_y = 0 # 设置垂直分隔线的位置
self.vline.setGeometry(x, self.margin, 1, self.height())
margin_top_value = self.margin
margin_bottom_value = self.margin
self.vline.setStyleSheet("border: 1px solid #C5C5C5; margin-top: {}px; margin-bottom: {}px;".format(margin_top_value, margin_bottom_value))
self.vline.setGeometry(vline_x, vline_y, 1, self.fixed_height - 9*self.margin)
# 创建垂直分隔线添加到page3
self.hline = QFrame(self.Cmingoz_page)
self.hline.setFrameShape(QFrame.HLine)
vline_y = int((150 / 650) * self.fixed_height) # 设置水平分隔线的位置
self.hline.setGeometry(0, vline_y, self.fixed_width - 9*self.margin, 1)
self.hline.setStyleSheet("border: 1px solid #C5C5C5;")
# 切换不同的窗口大小和设置绘制标记
def update_window_size(self, index):
if index == 0:
self.change_width = int((250 / 600) * self.fixed_width)
self.change_height = int((200 / 430) * self.fixed_height)
self.setFixedSize(self.change_width, self.change_height)
self.selected_page1 = True
elif index == 1:
self.change_width = int((600 / 600) * self.fixed_width)
self.change_height = int((430 / 430) * self.fixed_height)
self.setFixedSize(self.change_width, self.change_height)
self.selected_page2 = True
if index == 2:
self.change_width = int((350/ 600) * self.fixed_width)
self.change_height = int((235 / 430) * self.fixed_height)
self.setFixedSize(self.change_width, self.change_height)
self.selected_page3 = True
# 设置dock按钮
def setup_button(self, button, index, style):
button.setFixedSize(self.button_width_dock, self.button_height_dock)
button.setStyleSheet(style)
button.setCheckable(True)
button.clicked.connect(lambda: self.set_button_selected(index))
button.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(index)) # 连接切换页面槽函数
def set_button_selected(self, index):
for btn in self.findChildren(QPushButton):
btn.setChecked(False)
sender_button = self.sender()
sender_button.setChecked(True)
def paintEvent(self, event):
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing) # 开启抗锯齿
rect_color = QColor(7, 115, 252)
corner_radius_percentage = 2
# 计算相对单位的圆角大小
rect = self.rect()
corner_radius = min(rect.width(), rect.height()) * corner_radius_percentage / 100.0
if self.animation_finished:
#绘制一个圆角矩形用于触发下拉效果
painter.setBrush(rect_color)
painter.setPen(Qt.NoPen)
width = self.width() // 5
x = (self.width() - width) // 2
painter.drawRoundedRect(x, 0, width, self.height(), corner_radius, corner_radius)
else:
# 画多个矩形透明度渐变实现羽化边缘效果
for i in range(self.margin):
# 透明度从0开始递增
alpha = i * self.margin
shade_level = self.margin // 4
brush_color = QColor(0, 0, 0, alpha)
painter.setBrush(QBrush(brush_color))
# 禁用描边
painter.setPen(Qt.NoPen)
rect = self.rect().adjusted(i * shade_level, i * shade_level, -i * shade_level, -i * shade_level)
painter.drawRect(rect)
# 绘制主窗口背景
painter.fillRect(self.margin, self.margin, self.width() - 2 * self.margin, self.height() - 2 * self.margin, QColor(255, 255, 255))
# 在窗口左侧添加纵向遮罩
self.mask_width = int((5 / 90) * self.fixed_width)
painter.fillRect(self.margin, self.margin, self.mask_width, self.height() - 2 * self.margin, QColor(239, 242, 246))
# 在窗口顶部添加横向遮罩
self.mask_height = int((5 / 90) * self.fixed_height)
painter.fillRect(self.margin, self.margin, self.width() - 2 * self.margin, self.mask_height, QColor(0, 0, 0))
# 获取显示器边界信息
def update_screen_info(self):
# 保存 QDesktopWidget 的实例
self.desktop_widget = QDesktopWidget()
# 获取主窗口所在的屏幕索引
screen_number = self.desktop_widget.screenNumber(self)
# 获取主窗口所在屏幕的信息
screen = self.desktop_widget.screen(screen_number)
screen_geometry = screen.geometry()
self.monitor_top_border = screen_geometry.y()
#让自定义标题栏可以拖动主窗口
def mousePressEvent(self, event):
# 处理鼠标按下事件
if event.button() == Qt.LeftButton and event.y() < self.mask_height + self.margin:
self.is_dragging = True
self.offset = event.pos()
def mouseMoveEvent(self, event):
# 处理鼠标移动事件
if self.is_dragging:
old_position = self.pos() # 保存当前位置
self.new_position = self.mapToParent(event.pos() - self.offset)
if self.new_position == old_position: # 检查新位置是否等于原位置
return
self.update_screen_info()
# 确保y不超过显示器上边界
if self.new_position.y() < self.monitor_top_border - self.margin:
self.new_position.setY(self.monitor_top_border - self.margin)
self.move(self.new_position)
def mouseReleaseEvent(self, event):
# 处理鼠标释放事件
if self.is_dragging:
if event.button() == Qt.LeftButton:
# 添加对y是否等于显示器上边界的检测触发隐藏窗口效果
if self.new_position is not None and self.new_position.y() == self.monitor_top_border - self.margin:
self.up_move_window()
self.expanded = False
else:
self.expanded = None
self.is_dragging = False
#实现窗口隐藏显示的效果
def enterEvent(self, event):
#鼠标进入窗口区域
if not self.expanded and self.y() == round(self.monitor_top_border - (994/1000) * self.change_height):
self.down_move_window()
self.expanded = True
def leaveEvent(self, event):
#鼠标离开窗口区域
if self.expanded and self.y() == self.monitor_top_border - self.margin:
if not self.double_clicked:
if not self.underMouse() and self.expanded:
self.up_move_window()
self.expanded = False
#主窗口移动动画
def up_move_window(self):
if self.animation is None or self.animation.state() == QPropertyAnimation.Stopped:
self.animation = QPropertyAnimation(self, b'geometry')
self.animation.setDuration(300)
self.animation.setStartValue(QRect(self.geometry()))
# 使用round()处理舍入误差问题
new_y = round(self.geometry().y() - (994/1000) * self.change_height + self.margin)
self.animation.setEndValue(QRect(
self.geometry().x(),
new_y,
self.geometry().width(),
self.geometry().height()
))
self.animation.finished.connect(self.animation_finished_work)
self.animation.start()
def down_move_window(self):
if self.animation is None or self.animation.state() == QPropertyAnimation.Stopped:
self.animation = QPropertyAnimation(self, b'geometry')
self.animation.setDuration(300)
self.animation.setStartValue(QRect(self.geometry()))
# 使用round()处理舍入误差问题
new_y = round(self.geometry().y() + (994/1000) * self.change_height - self.margin)
self.animation.setEndValue(QRect(
self.geometry().x(),
new_y,
self.geometry().width(),
self.geometry().height()
))
self.animation_finished = False
self.update()
self.animation.start()
def animation_finished_work(self):
self.animation_finished = True
self.update()
#倒计时自动执行
def update_countdown(self):
self.remaining_time -= 1
if self.remaining_time <= 0:
self.auto_archiving()
# 重置倒计时时间
self.remaining_time = 90
self.countdown_label.setText(f"{self.remaining_time} 秒后自动归档")
else:
self.countdown_label.setText(f"{self.remaining_time} 秒后自动归档")
#############主程序########################################主程序###################################主程序#######################################主程序###############################
###GSfolders##############################################################GSfolders#######################################GSfolders#########################################
def select_path(self):
if not self.folder_name_entry.text():
QMessageBox.information(self, "提示", "请输入文件夹名称")
return
if not self.num_folders_entry.text():
QMessageBox.information(self, "提示", "请输入文件夹数量")
return
#设置默认文件夹路径
last_folder_path = self.settings.value("last_folder_path", ".")
if not last_folder_path:
last_folder_path = "."
folder_path = str(QFileDialog.getExistingDirectory(self, "创建文件夹", last_folder_path))
if not folder_path:
return # 如果用户没有选择文件夹,则直接返回
self.settings.setValue("last_folder_path", folder_path) # 保存上次选择的文件夹路径
self.create_folders(folder_path)
def create_folders(self, folder_path):
num_folders = self.num_folders_entry.text()
folder_name = self.folder_name_entry.text()
try:
num_folders = int(num_folders)
if num_folders <= 0:
raise ValueError
except ValueError:
QMessageBox.information(self, "出错了", "请输入正整数的文件夹数量")
return
success_count = 0
skip_count = 0
# 保存当前输入的名称和数量到设置中
self.settings.setValue("last_folder_name", folder_name)
self.settings.setValue("last_num_folders", num_folders)
# Extract numeric suffix from the existing folder name
existing_suffix_match = re.search(r'\d+$', folder_name)
existing_suffix = int(existing_suffix_match.group()) if existing_suffix_match else None
if existing_suffix is not None:
for i in range(existing_suffix, existing_suffix + num_folders):
current_folder_name = re.sub(r'\d+$', str(i), folder_name)
folder_path_i = os.path.join(folder_path, current_folder_name)
if os.path.exists(folder_path_i):
skip_count += 1
continue
try:
os.makedirs(folder_path_i)
subfolder1_path = os.path.join(folder_path_i, "待修")
os.makedirs(subfolder1_path)
subfolder2_path = os.path.join(folder_path_i, "已修")
os.makedirs(subfolder2_path)
subfolder3_path = os.path.join(subfolder2_path, "psd")
os.makedirs(subfolder3_path)
subfolder4_path = os.path.join(subfolder2_path, "其他尺寸")
os.makedirs(subfolder4_path)
success_count += 1
except:
pass
else:
# 如果文件夹名称末尾没有数字,则在最后一个文字后面从0开始依次递增
for i in range(num_folders):
current_folder_name = f"{folder_name}{i}"
folder_path_i = os.path.join(folder_path, current_folder_name)
if os.path.exists(folder_path_i):
skip_count += 1
continue
try:
os.makedirs(folder_path_i)
subfolder1_path = os.path.join(folder_path_i, "待修")
os.makedirs(subfolder1_path)
subfolder2_path = os.path.join(folder_path_i, "已修")
os.makedirs(subfolder2_path)
subfolder3_path = os.path.join(subfolder2_path, "psd")
os.makedirs(subfolder3_path)
subfolder4_path = os.path.join(subfolder2_path, "其他尺寸")
os.makedirs(subfolder4_path)
success_count += 1
except:
pass
if success_count > 0:
QMessageBox.information(self, "提示", f"成功创建 {success_count} 个文件夹。已存在的文件夹被跳过 {skip_count} 个。")
elif skip_count == num_folders:
QMessageBox.information(self, "提示", "所有文件夹均已存在,无需创建。")
else:
QMessageBox.information(self, "出错了", f"创建文件夹失败,共有 {num_folders - skip_count} 个文件夹创建失败。已存在的文件夹被跳过 {skip_count} 个。")
###GSfolders##############################################################GSfolders#######################################GSfolders#########################################
###FolderFilter#######################################################FolderFilter###################################FolderFilter#####################################################
#选择文件夹
def select_folder(self):
self.expanded = None
self.clear_list_flag = True #不清空时选择的文件夹时候用的
if self.thread_running:
QMessageBox.information(self,'提示','后台正在运行自动归档,请稍后再操作')
return
# 获取用户输入的文件类型
file_type = self.filter_combo.currentText()
if not file_type:
QMessageBox.information(self,'提示','请输入要筛选的文件类型\n例如:“.txt”')
return
else:
#设置进度条为初始状态
self.progress_bar.setValue(0)
#设置默认文件夹路径
last_dir_path = self.settings.value("last_dir_path", ".")
if not last_dir_path: # 如果还没有保存过选择的文件夹路径,则使用当前目录作为默认路径
last_dir_path = "."
dir_path = str(QFileDialog.getExistingDirectory(self, '选择文件夹', last_dir_path))
if not dir_path:
self.clear_list_flag = False
else:
if not os.access(dir_path, os.R_OK):
QMessageBox.warning(self, '警告', '无法读取选择的文件夹,请检查权限设置。')
self.clear_list_flag = False
if dir_path in [self.file_filter_folders_list.item(index).data(Qt.UserRole) for index in range(self.file_filter_folders_list.count())]: