forked from Teraskull/PyDebloatX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
245 lines (214 loc) · 10.9 KB
/
Copy pathapp.py
File metadata and controls
245 lines (214 loc) · 10.9 KB
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
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtGui import QCursor, QPixmap, QIcon
from gui_about import Ui_AboutWindow
from gui_main import Ui_MainWindow
import webbrowser
import subprocess
import img_res # skipcq: PYL-W0611
import sys
__version__ = "1.5.0"
class Logic():
def __init__(self):
about.label_version.setText(f"Version {__version__}")
self.total_size = 0
self.checkbox_dict = {
ui.checkBox: "*Microsoft.3DBuilder*", ui.checkBox_2: "*Microsoft.Microsoft3DViewer*", ui.checkBox_3: "*Microsoft.WindowsAlarms*",
ui.checkBox_4: "*Microsoft.WindowsCalculator*", ui.checkBox_5: "*microsoft.windowscommunicationsapps*", ui.checkBox_6: "*Microsoft.WindowsCamera*",
ui.checkBox_7: "*Microsoft.GetHelp*", ui.checkBox_8: "*Microsoft.ZuneMusic*", ui.checkBox_9: "*Microsoft.WindowsMaps*",
ui.checkBox_10: "*Microsoft.Messaging*", ui.checkBox_11: "*Microsoft.BingFinance*", ui.checkBox_12: "*Microsoft.ZuneVideo*",
ui.checkBox_13: "*Microsoft.BingNews*", ui.checkBox_14: "*Microsoft.MicrosoftOfficeHub*", ui.checkBox_15: "*Microsoft.Office.OneNote*",
ui.checkBox_16: "*Microsoft.MSPaint*", ui.checkBox_17: "*Microsoft.People*", ui.checkBox_18: "*Microsoft.Windows.Photos*",
ui.checkBox_19: "*Microsoft.SkypeApp*", ui.checkBox_20: "*Microsoft.MicrosoftSolitaireCollection*", ui.checkBox_21: "*Microsoft.BingSports*",
ui.checkBox_22: "*Microsoft.Getstarted*", ui.checkBox_23: "*Microsoft.WindowsSoundRecorder*", ui.checkBox_24: "*Microsoft.BingWeather*",
ui.checkBox_25: "*Microsoft.WindowsFeedbackHub*", ui.checkBox_26: "*xbox* | Where-Object {$_.name -notmatch 'xboxgamecallableui'}", ui.checkBox_27: "*Microsoft.YourPhone*",
}
self.size_dict = {
ui.checkBox: 35.02, ui.checkBox_2: 121.46, ui.checkBox_3: 11.87,
ui.checkBox_4: 9.27, ui.checkBox_5: 230.90, ui.checkBox_6: 49.05,
ui.checkBox_7: 11.89, ui.checkBox_8: 50.34, ui.checkBox_9: 29.93,
ui.checkBox_10: 30.08, ui.checkBox_11: 31.92, ui.checkBox_12: 51.80,
ui.checkBox_13: 33.70, ui.checkBox_14: 29.97, ui.checkBox_15: 156.01,
ui.checkBox_16: 65.79, ui.checkBox_17: 31.97, ui.checkBox_18: 346.04,
ui.checkBox_19: 104.70, ui.checkBox_20: 134.37, ui.checkBox_21: 30.92,
ui.checkBox_22: 16.62, ui.checkBox_23: 12.40, ui.checkBox_24: 30.59,
ui.checkBox_25: 35.02, ui.checkBox_26: 119.06, ui.checkBox_27: 64.59,
}
ui.progressbar.setValue(0)
ui.progressbar.setMaximum(len(self.checkbox_dict))
ui.button_uninstall.clicked.connect(self.uninstall)
ui.button_select_all.clicked.connect(self.select_all)
ui.button_deselect_all.clicked.connect(self.deselect_all)
ui.refresh_btn.clicked.connect(self.app_refresh)
ui.refresh_bind.activated.connect(self.app_refresh)
ui.homepage_btn.clicked.connect(self.app_homepage)
ui.homepage_bind.activated.connect(self.app_homepage)
ui.about_btn.clicked.connect(self.app_about)
ui.about_bind.activated.connect(self.app_about)
ui.quit_btn.clicked.connect(self.app_quit)
ui.quit_bind.activated.connect(self.app_quit)
about.button_quit_about.clicked.connect(self.about_close)
for i in self.checkbox_dict:
i.clicked.connect(self.enable_buttons)
with open("style.css", 'r') as file:
i.setStyleSheet(file.read())
self.workerThread = QThread()
self.thread_list = []
for item, i in enumerate(self.checkbox_dict):
self.thread_list.append(CheckApps(self.checkbox_dict, i))
self.thread_list[item].moveToThread(self.workerThread)
self.thread_list[item].app_signal.connect(self.enable_installed)
self.thread_list[item].progress_signal.connect(self.update_progress)
self.app_refresh()
def app_refresh(self):
self.installed_apps = []
self.progress = 0
for i in self.checkbox_dict:
i.setEnabled(False)
i.setChecked(False)
ui.progressbar.show()
ui.refresh_btn.setDisabled(True)
ui.refresh_bind.setEnabled(False)
ui.button_select_all.setDisabled(True)
ui.button_deselect_all.setDisabled(True)
ui.button_uninstall.setDisabled(True)
ui.refresh_btn.setIcon(QIcon(':/icon/no_refresh_icon.png'))
ui.button_select_all.setIcon(QIcon(':/icon/no_check_icon.png'))
ui.button_uninstall.setIcon(QIcon(':/icon/no_trash_icon.png'))
ui.button_deselect_all.setIcon(QIcon(':/icon/no_cancel_icon.png'))
QApplication.setOverrideCursor(QCursor(Qt.BusyCursor))
ui.label_info.setText('Refreshing list of installed apps...')
for new_thread in self.thread_list:
new_thread.start()
def thread_finished(self):
ui.progressbar.hide()
ui.progressbar.setValue(0)
QApplication.setOverrideCursor(QCursor())
ui.label_info.setText('Select the default Windows 10 apps to uninstall (Hover over items to view description):')
ui.refresh_btn.setDisabled(False)
ui.refresh_bind.setEnabled(True)
ui.refresh_btn.setIcon(QIcon(':/icon/refresh_icon.png'))
self.enable_buttons()
def enable_installed(self, i):
i.setEnabled(True)
self.installed_apps.append(i)
self.enable_buttons()
def update_progress(self):
self.progress += 1
ui.progressbar.setValue(self.progress)
if self.progress >= len(self.checkbox_dict):
self.thread_finished()
def enable_buttons(self):
self.total_size = 0
for i in self.installed_apps:
if i.isChecked():
self.total_size += self.size_dict[i]
ui.label_size.setText(f'{self.total_size:.2f} MB')
if any(i.isChecked() for i in self.installed_apps):
ui.button_uninstall.setDisabled(False)
ui.button_deselect_all.setDisabled(False)
ui.button_uninstall.setIcon(QIcon(':/icon/trash_icon.png'))
ui.button_deselect_all.setIcon(QIcon(':/icon/cancel_icon.png'))
else:
ui.button_uninstall.setDisabled(True)
ui.button_deselect_all.setDisabled(True)
ui.button_uninstall.setIcon(QIcon(':/icon/no_trash_icon.png'))
ui.button_deselect_all.setIcon(QIcon(':/icon/no_cancel_icon.png'))
ui.label_size.setText('0 MB')
if all(i.isChecked() for i in self.installed_apps):
ui.button_select_all.setDisabled(True)
ui.button_select_all.setIcon(QIcon(':/icon/no_check_icon.png'))
else:
ui.button_select_all.setDisabled(False)
ui.button_select_all.setIcon(QIcon(':/icon/check_icon.png'))
@staticmethod
def app_homepage():
webbrowser.open_new('https://github.com/Teraskull/PyDebloatX')
@staticmethod
def app_about():
about.setWindowModality(Qt.ApplicationModal)
about.show()
@staticmethod
def about_close():
about.close()
@staticmethod
def app_quit():
pixmap = QPixmap('icon.ico').scaledToWidth(35, Qt.SmoothTransformation)
msg_quit = QMessageBox()
msg_quit.setText("Quit PyDebloatX?")
msg_quit.addButton(QMessageBox.Yes).setProperty('class', 'button_yes')
msg_quit.addButton(QMessageBox.No).setProperty('class', 'button_no')
msg_quit.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint)
msg_quit.setWindowIcon(QIcon('icon.ico'))
msg_quit.setWindowTitle("PyDebloatX")
msg_quit.setIconPixmap(pixmap)
with open("style.css", 'r') as file:
msg_quit.setStyleSheet(file.read())
msg_quit_result = msg_quit.exec_()
if msg_quit_result == QMessageBox.Yes:
app.quit()
def select_all(self):
for i in self.installed_apps:
if not i.isChecked():
i.setChecked(True)
self.enable_buttons()
def deselect_all(self):
for i in self.installed_apps:
if i.isChecked():
i.setChecked(False)
self.enable_buttons()
def uninstall(self):
j = 0
for i in self.installed_apps:
if i.isChecked():
j += 1
pixmap = QPixmap('icon.ico').scaledToWidth(35, Qt.SmoothTransformation)
msg_confirm = QMessageBox()
msg_confirm.setText(f"Uninstall {j} app{'s' if j > 1 else ''}?\n\n{self.total_size:.2f} MB of of disk space will be available.")
msg_confirm.addButton(QMessageBox.Yes).setProperty('class', 'button_yes')
msg_confirm.addButton(QMessageBox.No).setProperty('class', 'button_no')
msg_confirm.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint)
msg_confirm.setWindowIcon(QIcon('icon.ico'))
msg_confirm.setWindowTitle("PyDebloatX")
msg_confirm.setIconPixmap(pixmap)
with open("style.css", 'r') as file:
msg_confirm.setStyleSheet(file.read())
msg_confirm_result = msg_confirm.exec_()
if msg_confirm_result == QMessageBox.Yes:
for i in self.checkbox_dict:
if i.isChecked():
subprocess.Popen(["powershell", f"(Get-AppxPackage {self.checkbox_dict[i]} | Remove-AppxPackage)"], shell=True)
i.setChecked(False)
i.setEnabled(False)
self.installed_apps.remove(i)
self.deselect_all()
msg_proceed = QMessageBox()
msg_proceed.setText(f"Uninstalling {j} app{'s' if j > 1 else ''}.")
msg_proceed.addButton(QMessageBox.Ok).setProperty('class', 'button_yes')
msg_proceed.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint)
msg_proceed.setWindowTitle("PyDebloatX")
msg_proceed.setIconPixmap(pixmap)
with open("style.css", 'r') as file:
msg_proceed.setStyleSheet(file.read())
msg_proceed.exec_()
class CheckApps(QThread):
progress_signal = pyqtSignal()
app_signal = pyqtSignal(object)
def __init__(self, checkbox_dict, i):
super().__init__()
self.checkbox_dict = checkbox_dict
self.i = i
def run(self):
x = subprocess.Popen(["powershell", f"(Get-AppxPackage {self.checkbox_dict[self.i]}) -and $?"], stdout=subprocess.PIPE, shell=True)
if x.communicate()[0].decode().strip() == "True":
self.app_signal.emit(self.i)
self.progress_signal.emit()
if __name__ == '__main__':
app = QApplication(sys.argv)
about = Ui_AboutWindow()
about.setupUi()
ui = Ui_MainWindow()
ui.setupUi()
ui.show()
logic = Logic()
sys.exit(app.exec_())