-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
150 lines (112 loc) · 4.98 KB
/
classes.py
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
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from functions import *
import os
class Main(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("qCleaner")
self.setWindowIcon(QIcon("icon.png"))
self.InitWidget()
self.setLayout(self.MainGrid)
self.show()
def InitWidget(self):
PathLabel = QLabel("操作目录:")
PathEdit = QLineEdit()
BrowseButton = QPushButton("浏览")
BrowseButton.clicked.connect(lambda: BrowseDialog(PathEdit))
ProcessButton = QPushButton("清理")
ProcessButton.clicked.connect(lambda: MainProcessGuide(PathEdit.text()))
AboutButton = QPushButton("关于")
AboutButton.clicked.connect(AboutThisProject)
self.MainGrid = QGridLayout()
self.MainGrid.setSpacing(10)
self.MainGrid.addWidget(PathLabel, 1, 1)
self.MainGrid.addWidget(PathEdit, 1, 2)
self.MainGrid.addWidget(BrowseButton, 1, 3)
self.MainGrid.addWidget(ProcessButton, 2, 1, 1, 2)
self.MainGrid.addWidget(AboutButton, 2, 3)
class ProcessModule(QDialog):
def __init__(self, path):
super().__init__()
self.setWindowTitle("正在清理")
self.setWindowIcon(QIcon("icon.png"))
self.resize(300, 200)
self.PathCount = self.FileCount = self.SpaceCount = 0
self.UpdateCount = self.ForcedTerminated = 0
self.PathCountStatus = QLabel()
self.FileCountStatus = QLabel()
self.SpaceCountStatus = QLabel()
self.CurrentPathStatus = QLabel()
self.ExitButton = QPushButton("取消")
self.ExitButton.clicked.connect(self.ForcedTermination)
GridLayout = QGridLayout()
GridLayout.addWidget(self.CurrentPathStatus, 1, 1)
GridLayout.addWidget(self.PathCountStatus, 2, 1)
GridLayout.addWidget(self.FileCountStatus, 3, 1)
GridLayout.addWidget(self.SpaceCountStatus, 4, 1)
GridLayout.addWidget(self.ExitButton, 5, 1)
self.setLayout(GridLayout)
import threading
process = threading.Thread(target=self.ProcessGuide, args=(path,))
process.start()
def ForcedTermination(self):
self.ForcedTerminated = 1
def ProcessGuide(self, path):
self.process(path, 500)
self.UpdateData("")
self.ExitButton.setText("确定")
self.ExitButton.clicked.disconnect(self.ForcedTermination)
self.ExitButton.clicked.connect(self.close)
if self.ForcedTerminated:
self.setWindowTitle("已取消")
else:
self.setWindowTitle("清理完成")
def UpdateData(self, CurrentPath):
self.CurrentPathStatus.setText("当前目录:%s" % CurrentPath)
self.PathCountStatus.setText("已遍历%d个文件夹" % self.PathCount)
self.FileCountStatus.setText("已删除%d个.exe文件" % self.FileCount)
self.SpaceCountStatus.setText("已释放出%dMB的空间" % (self.SpaceCount / 1024 / 1024))
def process(self, path, UpdateCountBase):
if self.ForcedTerminated:
return
self.PathCount += 1
try:
FileList = os.listdir(path)
except:
return
for file in FileList:
self.UpdateCount -= 1
if self.UpdateCount <= 0:
self.UpdateData(path)
self.UpdateCount = UpdateCountBase
AbsolutePath = path + os.sep + file
if os.path.isdir(AbsolutePath):
self.process(AbsolutePath, UpdateCountBase)
elif os.path.splitext(file)[1] == ".cpp":
ExecutableFile = os.path.splitext(file)[0] + ".exe"
if (ExecutableFile in FileList):
self.SpaceCount += os.path.getsize(path + os.sep + ExecutableFile)
self.FileCount += 1
self.UpdateData(path)
os.remove(path + os.sep + ExecutableFile)
class AboutPage(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("About qCleaner")
self.setWindowIcon(QIcon("icon.png"))
ProjectPageGuide = QLabel("Project Page:")
ProjectPageLink = QLabel("""<a href="https://github.com/yongzhengqi/qCleaner">https://github.com/yongzhengqi/qCleaner</a>""")
ProjectPageLink.setOpenExternalLinks(True)
ProjectLicenseGuide = QLabel("Project License:")
ProjectLicense = QLabel("""<a href="https://www.gnu.org/licenses/gpl-3.0.en.html" target="_blank">GNU General Public License v3.0</a>""")
ProjectLicense.setOpenExternalLinks(True)
ExitButton = QPushButton("确定")
ExitButton.clicked.connect(self.close)
GridLayout = QGridLayout()
self.setLayout(GridLayout)
GridLayout.addWidget(ProjectPageGuide, 1, 1)
GridLayout.addWidget(ProjectPageLink, 1, 2)
GridLayout.addWidget(ProjectLicenseGuide, 2, 1)
GridLayout.addWidget(ProjectLicense, 2, 2)
GridLayout.addWidget(ExitButton, 3, 1, 1, 3)