Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit d484a42

Browse files
author
ambition_echo
committed
feat(config): 新增删除缓存功能
1 parent aa3b7df commit d484a42

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed

earth_wallpaper/config.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import shutil
2+
13
from PySide6.QtCore import Qt, QSettings, Signal
24
from PySide6.QtGui import QIcon
35
from PySide6.QtWidgets import QWidget, QMessageBox, QFileDialog
@@ -82,6 +84,7 @@ def _connect_(self):
8284
self.applyBtn.clicked.connect(self.write_config)
8385
self.selectFile.clicked.connect(self.select_file)
8486
self.selectDir.clicked.connect(self.select_dir)
87+
self.clearCache.clicked.connect(self.clear_cache)
8588

8689
def check(self):
8790
if os.path.exists(self.config_path):
@@ -196,3 +199,12 @@ def select_file(self):
196199
"24h壁纸文件 (*.ddw *.zip);;")
197200
logger.info(f"获取到文件地址{file}")
198201
self.wallpaperFile.setText(file[0])
202+
203+
@staticmethod
204+
def clear_cache():
205+
cache = PlatformInfo.download_dir()
206+
if os.path.exists(cache):
207+
shutil.rmtree(cache)
208+
logger.info(f"删除缓存目录: {cache}")
209+
message = QMessageBox()
210+
QMessageBox.information(message, "清理缓存", "已删除全部缓存壁纸", QMessageBox.Yes)

earth_wallpaper/ui/UI_config.py

+22-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Ui_Config(object):
2424
def setupUi(self, Config):
2525
if not Config.objectName():
2626
Config.setObjectName(u"Config")
27-
Config.resize(346, 534)
27+
Config.resize(346, 572)
2828
self.gridLayout_3 = QGridLayout(Config)
2929
self.gridLayout_3.setObjectName(u"gridLayout_3")
3030
self.AppSettings = QGroupBox(Config)
@@ -182,6 +182,20 @@ def setupUi(self, Config):
182182

183183
self.gridLayout_3.addWidget(self.AppSettings, 0, 0, 1, 3)
184184

185+
self.applySpacer = QSpacerItem(57, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
186+
187+
self.gridLayout_3.addItem(self.applySpacer, 2, 0, 1, 1)
188+
189+
self.applyBtn = QPushButton(Config)
190+
self.applyBtn.setObjectName(u"applyBtn")
191+
192+
self.gridLayout_3.addWidget(self.applyBtn, 2, 1, 1, 1)
193+
194+
self.closeBtn = QPushButton(Config)
195+
self.closeBtn.setObjectName(u"closeBtn")
196+
197+
self.gridLayout_3.addWidget(self.closeBtn, 2, 2, 1, 1)
198+
185199
self.SystemSettings = QGroupBox(Config)
186200
self.SystemSettings.setObjectName(u"SystemSettings")
187201
sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
@@ -248,22 +262,13 @@ def setupUi(self, Config):
248262

249263
self.gridLayout.addLayout(self.addGroup, 1, 0, 1, 1)
250264

265+
self.clearCache = QPushButton(self.SystemSettings)
266+
self.clearCache.setObjectName(u"clearCache")
251267

252-
self.gridLayout_3.addWidget(self.SystemSettings, 1, 0, 1, 3)
253-
254-
self.applySpacer = QSpacerItem(57, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
255-
256-
self.gridLayout_3.addItem(self.applySpacer, 2, 0, 1, 1)
257-
258-
self.applyBtn = QPushButton(Config)
259-
self.applyBtn.setObjectName(u"applyBtn")
260-
261-
self.gridLayout_3.addWidget(self.applyBtn, 2, 1, 1, 1)
268+
self.gridLayout.addWidget(self.clearCache, 2, 0, 1, 1)
262269

263-
self.closeBtn = QPushButton(Config)
264-
self.closeBtn.setObjectName(u"closeBtn")
265270

266-
self.gridLayout_3.addWidget(self.closeBtn, 2, 2, 1, 1)
271+
self.gridLayout_3.addWidget(self.SystemSettings, 1, 0, 1, 3)
267272

268273

269274
self.retranslateUi(Config)
@@ -297,14 +302,15 @@ def retranslateUi(self, Config):
297302
self.People.setText(QCoreApplication.translate("Config", u"People", None))
298303
self.selectFile.setText(QCoreApplication.translate("Config", u"\u6d4f\u89c8", None))
299304
self.selectDir.setText(QCoreApplication.translate("Config", u"\u6d4f\u89c8", None))
305+
self.applyBtn.setText(QCoreApplication.translate("Config", u"\u5e94\u7528", None))
306+
self.closeBtn.setText(QCoreApplication.translate("Config", u"\u5173\u95ed", None))
300307
self.SystemSettings.setTitle(QCoreApplication.translate("Config", u"\u7cfb\u7edf\u8bbe\u7f6e", None))
301308
self.proxy_l.setText(QCoreApplication.translate("Config", u"\u7f51\u7edc\u4ee3\u7406\uff1a", None))
302309
self.proxyNone.setText(QCoreApplication.translate("Config", u"\u65e0", None))
303310
self.proxyHttp.setText(QCoreApplication.translate("Config", u"http", None))
304311
self.proxySocks.setText(QCoreApplication.translate("Config", u"socks", None))
305312
self.add_l.setText(QCoreApplication.translate("Config", u"\u5730\u5740\uff1a", None))
306313
self.port_l.setText(QCoreApplication.translate("Config", u":", None))
307-
self.applyBtn.setText(QCoreApplication.translate("Config", u"\u5e94\u7528", None))
308-
self.closeBtn.setText(QCoreApplication.translate("Config", u"\u5173\u95ed", None))
314+
self.clearCache.setText(QCoreApplication.translate("Config", u"\u5220\u9664\u7f13\u5b58", None))
309315
# retranslateUi
310316

earth_wallpaper/ui/config.ui

+35-28
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>346</width>
10-
<height>534</height>
10+
<height>572</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -238,6 +238,33 @@ color: #774444;</string>
238238
</layout>
239239
</widget>
240240
</item>
241+
<item row="2" column="0">
242+
<spacer name="applySpacer">
243+
<property name="orientation">
244+
<enum>Qt::Horizontal</enum>
245+
</property>
246+
<property name="sizeHint" stdset="0">
247+
<size>
248+
<width>57</width>
249+
<height>20</height>
250+
</size>
251+
</property>
252+
</spacer>
253+
</item>
254+
<item row="2" column="1">
255+
<widget class="QPushButton" name="applyBtn">
256+
<property name="text">
257+
<string>应用</string>
258+
</property>
259+
</widget>
260+
</item>
261+
<item row="2" column="2">
262+
<widget class="QPushButton" name="closeBtn">
263+
<property name="text">
264+
<string>关闭</string>
265+
</property>
266+
</widget>
267+
</item>
241268
<item row="1" column="0" colspan="3">
242269
<widget class="QGroupBox" name="SystemSettings">
243270
<property name="sizePolicy">
@@ -322,36 +349,16 @@ color: #774444;</string>
322349
</item>
323350
</layout>
324351
</item>
352+
<item row="2" column="0">
353+
<widget class="QPushButton" name="clearCache">
354+
<property name="text">
355+
<string>删除缓存</string>
356+
</property>
357+
</widget>
358+
</item>
325359
</layout>
326360
</widget>
327361
</item>
328-
<item row="2" column="0">
329-
<spacer name="applySpacer">
330-
<property name="orientation">
331-
<enum>Qt::Horizontal</enum>
332-
</property>
333-
<property name="sizeHint" stdset="0">
334-
<size>
335-
<width>57</width>
336-
<height>20</height>
337-
</size>
338-
</property>
339-
</spacer>
340-
</item>
341-
<item row="2" column="1">
342-
<widget class="QPushButton" name="applyBtn">
343-
<property name="text">
344-
<string>应用</string>
345-
</property>
346-
</widget>
347-
</item>
348-
<item row="2" column="2">
349-
<widget class="QPushButton" name="closeBtn">
350-
<property name="text">
351-
<string>关闭</string>
352-
</property>
353-
</widget>
354-
</item>
355362
</layout>
356363
</widget>
357364
<resources/>

0 commit comments

Comments
 (0)