2020
2121# 主窗口
2222class Window (QMainWindow ):
23-
2423 def mousePressEvent (self , event ):
2524 # 重写一堆方法使其支持拖动
2625 if event .button () == Qt .LeftButton :
@@ -78,8 +77,7 @@ def doFadeOut(self):
7877 self .animation .start ()
7978
8079 def setWarninginfo (self , text ):
81- self .lab_info .setStyleSheet (
82- """
80+ self .lab_info .setStyleSheet ("""
8381 .QLabel {
8482 border:1px solid #ffccc7;
8583 border-radius:3px;
@@ -88,13 +86,11 @@ def setWarninginfo(self, text):
8886 color: #434343;
8987 background: #fff2f0;
9088 }
91- """
92- )
89+ """ )
9390 self .lab_info .setText (text )
9491
9592 def setSuccessinfo (self , text ):
96- self .lab_info .setStyleSheet (
97- """
93+ self .lab_info .setStyleSheet ("""
9894 .QLabel {
9995 border:1px solid #b7eb8f;
10096 border-radius:3px;
@@ -103,8 +99,7 @@ def setSuccessinfo(self, text):
10399 color: #434343;
104100 background: #f6ffed;
105101 }
106- """
107- )
102+ """ )
108103 self .lab_info .setText (text )
109104
110105
@@ -116,15 +111,17 @@ def _connect(self):
116111 self .btn_close .clicked .connect (self .save_config )
117112 self .btn_file .clicked .connect (self .open_file )
118113
119-
120114 def open_file (self ):
121115 openfile_path = QFileDialog .getExistingDirectory (self , '选择微信数据目录' , '' )
122116 if not openfile_path or openfile_path == '' :
123117 return False
124118 if check_dir (openfile_path ) == 0 :
125119 self .setSuccessinfo ('读取路径成功!' )
126120 list_ = os .listdir (openfile_path )
127- user_list = [elem for elem in list_ if elem != 'All Users' and elem != 'Applet' ]
121+ user_list = [
122+ elem for elem in list_
123+ if elem != 'All Users' and elem != 'Applet'
124+ ]
128125 # 如果已有用户配置,那么写入新的用户配置,否则默认写入新配置
129126 dir_list = []
130127 user_config = []
@@ -146,12 +143,10 @@ def open_file(self):
146143 "timer" : "0h"
147144 })
148145
149- config = {
150- "data_dir" : dir_list ,
151- "users" : user_config
152- }
146+ config = {"data_dir" : dir_list , "users" : user_config }
153147
154- with open (working_dir + "/config.json" , "w" , encoding = "utf-8" ) as f :
148+ with open (
149+ working_dir + "/config.json" , "w" , encoding = "utf-8" ) as f :
155150 json .dump (config , f )
156151 self .load_config ()
157152 else :
@@ -178,12 +173,14 @@ def load_config(self):
178173 for value in self .config ["users" ]:
179174 self .combo_user .addItem (value ["wechat_id" ])
180175
181- self .line_gobackdays .setText (str (self .config ["users" ][0 ]["clean_days" ]))
176+ self .line_gobackdays .setText (
177+ str (self .config ["users" ][0 ]["clean_days" ]))
182178 self .check_is_clean .setChecked (self .config ["users" ][0 ]["is_clean" ])
183179 self .check_picdown .setChecked (self .config ["users" ][0 ]["clean_pic" ])
184180 self .check_files .setChecked (self .config ["users" ][0 ]["clean_file" ])
185181 self .check_video .setChecked (self .config ["users" ][0 ]["clean_video" ])
186- self .check_picscache .setChecked (self .config ["users" ][0 ]["clean_pic_cache" ])
182+ self .check_picscache .setChecked (
183+ self .config ["users" ][0 ]["clean_pic_cache" ])
187184 self .setSuccessinfo ("加载配置文件成功" )
188185
189186 def refresh_ui (self ):
@@ -222,10 +219,7 @@ def create_config(self):
222219 self .setWarninginfo ("目录非微信数据目录,请检查" )
223220 return
224221
225- self .config = {
226- "data_dir" : self .version_scan ,
227- "users" : []
228- }
222+ self .config = {"data_dir" : self .version_scan , "users" : []}
229223 for value in self .users_scan :
230224 self .config ["users" ].append ({
231225 "wechat_id" : value ,
@@ -238,7 +232,8 @@ def create_config(self):
238232 "is_timer" : true ,
239233 "timer" : "0h"
240234 })
241- with open (working_dir + "/config.json" , "w" , encoding = "utf-8" ) as f :
235+ with open (
236+ working_dir + "/config.json" , "w" , encoding = "utf-8" ) as f :
242237 json .dump (self .config , f )
243238 self .load_config ()
244239 self .setSuccessinfo ("加载配置文件成功" )
@@ -258,13 +253,13 @@ def update_config(self):
258253 except ValueError :
259254 value ["clean_days" ] = "0"
260255 value ["is_clean" ] = self .check_is_clean .isChecked ()
261- value ["clean_pic" ] = self .check_picdown .isChecked ()
262- value ["clean_file" ] = self .check_files .isChecked ()
263- value ["clean_video" ] = self .check_video .isChecked ()
264- value ["clean_pic_cache" ] = self .check_picscache .isChecked ()
265-
266- with open (working_dir + "/config.json" ,"w" ,encoding = "utf-8" ) as f :
267- json .dump (self .config ,f )
256+ value ["clean_pic" ] = self .check_picdown .isChecked ()
257+ value ["clean_file" ] = self .check_files .isChecked ()
258+ value ["clean_video" ] = self .check_video .isChecked ()
259+ value ["clean_pic_cache" ] = self .check_picscache .isChecked ()
260+
261+ with open (working_dir + "/config.json" , "w" , encoding = "utf-8" ) as f :
262+ json .dump (self .config , f )
268263 self .setSuccessinfo ("更新配置文件成功" )
269264 self .Signal_OneParameter .emit (1 )
270265
@@ -282,6 +277,8 @@ def __init__(self):
282277
283278
284279class MainWindow (Window ):
280+ config_exists = False
281+
285282 def deal_emit_slot (self , set_status ):
286283 if set_status and not self .config_exists :
287284 self .setSuccessinfo ("已经准备好,可以开始了!" )
@@ -323,23 +320,30 @@ def get_fileNum(self, path, day, picCacheCheck, fileCheck, picCheck,
323320 if picCacheCheck :
324321 path_one = correct_path / 'Attachment'
325322 path_two = correct_path / 'FileStorage/Cache'
326- self .getPathFileNum (now , day , path_one , path_two , file_list , dir_list )
323+ self .getPathFileNum (now , day , path_one , path_two , file_list ,
324+ dir_list )
327325 if fileCheck :
328326 path_one = correct_path / 'Files'
329327 path_two = correct_path / 'FileStorage/File'
330- self .getPathFileNum (now , day , path_one , path_two , file_list , dir_list )
328+ self .getPathFileNum (now , day , path_one , path_two , file_list ,
329+ dir_list )
331330 if picCheck :
332331 path_one = correct_path / 'Image/Image'
333332 path_two = correct_path / 'FileStorage/Image'
334- self .getPathFileNum (now , day , path_one , path_two , file_list , dir_list )
333+ self .getPathFileNum (now , day , path_one , path_two , file_list ,
334+ dir_list )
335335 if videoCheck :
336336 path_one = correct_path / 'Video'
337337 path_two = correct_path / 'FileStorage/Video'
338- self .getPathFileNum (now , day , path_one , path_two , file_list , dir_list )
338+ self .getPathFileNum (now , day , path_one , path_two , file_list ,
339+ dir_list )
339340
340341 def pathFileDeal (self , now , day , path , file_list , dir_list ):
341342 if os .path .exists (path ):
342- filelist = [f for f in os .listdir (path ) if os .path .isfile (os .path .join (path , f ))]
343+ filelist = [
344+ f for f in os .listdir (path )
345+ if os .path .isfile (os .path .join (path , f ))
346+ ]
343347 for i in range (0 , len (filelist )):
344348 file_path = os .path .join (path , filelist [i ])
345349 if os .path .isdir (file_path ):
@@ -350,11 +354,12 @@ def pathFileDeal(self, now, day, path, file_list, dir_list):
350354 if diff >= day :
351355 file_list .append (file_path )
352356
353- def getPathFileNum (self , now , day , path_one , path_two , file_list , dir_list ):
357+ def getPathFileNum (self , now , day , path_one , path_two , file_list ,
358+ dir_list ):
354359 # caculate path_one
355360 self .pathFileDeal (now , day , path_one , file_list , dir_list )
356361 td = datetime .datetime .now () - datetime .timedelta (days = day )
357- td_year = td .year
362+ td_year = td .year
358363 td_month = td .month
359364 # caculate path_two
360365 if os .path .exists (path_two ):
@@ -371,23 +376,28 @@ def getPathFileNum(self, now, day, path_one, path_two, file_list, dir_list):
371376 if re .match ('\d{4}(\-)\d{2}' , dirlist [i ]) != None :
372377 cyear = int (dirlist [i ].split ('-' , 1 )[0 ])
373378 cmonth = int (dirlist [i ].split ('-' , 1 )[1 ])
374- if self .__before_deadline (cyear , cmonth , td_year , td_month ):
379+ if self .__before_deadline (cyear , cmonth , td_year ,
380+ td_month ):
375381 dir_list .append (file_path )
376382 else :
377383 if cmonth == td_month :
378- self .pathFileDeal (now , day , file_path , file_list , dir_list )
384+ self .pathFileDeal (now , day , file_path , file_list ,
385+ dir_list )
379386
380- def __before_deadline (self ,cyear , cmonth , td_year , td_month ):
387+ def __before_deadline (self , cyear , cmonth , td_year , td_month ):
381388 if cyear < td_year :
382389 return True
383- else :
390+ elif cyear > td_year :
391+ return False
392+ elif cyear == td_year :
384393 return cmonth < td_month
385394
386395 def callback (self , v ):
387396 value = v / int ((self .total_file + self .total_dir )) * 100
388397 self .bar_progress .setValue (value )
389398 if value == 100 :
390- out = "本次共清理文件" + str (self .total_file ) + "个,文件夹" + str (self .total_dir ) + "个。请前往回收站检查并清空。"
399+ out = "本次共清理文件" + str (self .total_file ) + "个,文件夹" + str (
400+ self .total_dir ) + "个。请前往回收站检查并清空。"
391401 self .setSuccessinfo (out )
392402 return
393403
@@ -404,14 +414,18 @@ def justdoit(self): # 这个Api设计的太脑残了,其实dir可以直接放
404414 file_list = []
405415 dir_list = []
406416 if value ["is_clean" ]:
407- self .get_fileNum (self .config ["data_dir" ][i ], int (value ["clean_days" ]), value ["clean_pic_cache" ],
408- value ["clean_file" ], value ["clean_pic" ], value ["clean_video" ], file_list , dir_list )
417+ self .get_fileNum (self .config ["data_dir" ][i ],
418+ int (value ["clean_days" ]),
419+ value ["clean_pic_cache" ], value ["clean_file" ],
420+ value ["clean_pic" ], value ["clean_video" ],
421+ file_list , dir_list )
409422
410423 if len (file_list ) + len (dir_list ) != 0 :
411424 need_clean = True
412425 total_file += len (file_list )
413426 total_dir += len (dir_list )
414- thread_list .append (multiDeleteThread (file_list , dir_list , share_thread_arr ))
427+ thread_list .append (
428+ multiDeleteThread (file_list , dir_list , share_thread_arr ))
415429 thread_list [- 1 ].delete_process_signal .connect (self .callback )
416430 i = i + 1
417431
0 commit comments