-
Notifications
You must be signed in to change notification settings - Fork 14
/
interactive.py
336 lines (261 loc) · 9.56 KB
/
interactive.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
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
#!/usr/bin/env python3
import os
import sys
if sys.version_info < (3,0):
print("""ERROR: Python 3 is required to run this script.
Is python3 installed? Try running the script
as 'python3 interactive.py' instead.
If this doesn't work, you may need to install
the Python 3 interpreter from GNOME Software.
Exiting.""")
sys.exit(1)
class Folder:
def __init__(self, name, categories):
self.title = name
self.name = "".join(i for i in name.lower() if i.isalnum())
self.categories = categories
self.categoryString = ""
for cat in categories:
self.categoryString += "'{}', ".format(cat)
self.categoryString = "[" + self.categoryString[:-2] + "]"
def writeToDisk(self):
os.system(("gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders" +
"/folders/{}/ name \"{}\"".format(self.name, self.title)))
os.system(("gsettings set org.gnome.desktop.app-folders.folder:/org/gnome/desktop/app-folders" +
"/folders/{}/ categories \"{}\"".format(self.name, self.categoryString)))
DEFAULTS = [Folder("Accessories", ['Utility']),
Folder("Chrome Apps", ['chrome-apps']),
Folder("Games", ['Game']),
Folder("Graphics", ['Graphics']),
Folder("Internet", ['Network', 'WebBrowser', 'Email']),
Folder("Office", ['Office']),
Folder("Programming", ['Development']),
Folder("Science", ['Science']),
Folder("Sound & Video", ['AudioVideo', 'Audio', 'Video']),
Folder("System Tools", ['System', 'Settings']),
Folder("Universal Access", ['Accessibility']),
Folder("Wine", ['Wine', 'X-Wine', 'Wine-Programs-Accessories'])]
def ynQuery(question):
while True:
print()
print(question)
choice = input("[y/n] >>> ")
if choice.isalpha():
if choice.lower() == "y":
return True
elif choice.lower() == "n":
return False
print("ERROR: Invalid choice.")
def menu():
while True:
print()
print("""---Main Menu---
1. Set folders to default categories.
2. Customize folders and categories before applying.
3. Remove all existing folders from dashboard.
4. Cancel and exit.""")
print()
choice = input("What do you want to do? >>> ")
if choice.isnumeric() and int(choice) in range(1, 5):
return int(choice)
else:
os.system("clear")
for i in range(2): print()
print("ERROR: Invalid choice.")
def doReset():
os.system("gsettings reset-recursively org.gnome.desktop.app-folders")
def resetAll():
os.system("clear")
for i in range(2): print()
print("""WARNING! This will erase ALL folders you have
in your apps dashboard and return all apps
to an unsorted state.
This includes user-created folders as well as
any created by this script or other means.""")
if ynQuery("Are you sure you wish to do this?"):
os.system("clear")
for i in range(2): print()
doReset()
print("Your apps dashboard is now free of all folders.")
else:
print("Reset not performed. Exiting.")
sys.exit()
def mkCatString(folders):
catString = ""
for item in folders:
catString += "'{}', ".format(item.name)
catString = catString = "[" + catString[:-2] + "]"
return "gsettings set org.gnome.desktop.app-folders folder-children \"{}\"".format(catString)
def writeSettings(folders):
os.system(mkCatString(folders))
for item in folders:
item.writeToDisk()
def setSorted():
os.system("clear")
for i in range(2): print()
print("""WARNING! This will erase ALL folders you have
in your apps dashboard and sort your apps
based upon a predefined set of basic
categories.
The folders erased will include user-created
folders as well as any created by other means.""")
if ynQuery("Are you sure you wish to do this?"):
print()
doReset()
writeSettings(DEFAULTS)
os.system("clear")
for i in range(2): print()
print("Your apps dashboard is now sorted by the predefined categories.")
else:
print()
print("Sort not performed. Exiting.")
sys.exit()
def listCats(cats):
print("Your current folders are:")
for i in range(len(cats)):
print()
print("{}. TITLE: {}".format(i + 1, cats[i].title))
print(" CATEGORIES: {}".format(cats[i].categoryString[1:-1]))
def editMenu():
while True:
for i in range(2): print()
print("""--Edit Menu--
** You may need to scroll to view all current folders.
1. Add a new folder
2. Delete an existing folder
3. Delete all existing folders
4. Finished editing, write to disk""")
choice = input("What do you want to do? >>> ")
if choice.isnumeric() and int(choice) in range(1,5):
if int(choice) == 1:
return "add"
elif int(choice) == 2:
return "delete"
elif int(choice) == 3:
return "delete-all"
elif int(choice) == 4:
return "done"
else:
print("ERROR: Invalid choice.")
def addFolder():
print("Enter a folder title.")
title = input(">>> ")
adding = True
cats = []
while adding:
print()
print("Current categories: {}".format(cats))
print("""Enter text to add a category.
To remove previous, type 'r'
To remove all, type 'x'
When done, type 'q'""")
userinput = input(">>> ")
if userinput == "q":
adding = False
elif userinput == 'r':
cats.remove(cats[-1])
elif userinput == 'x':
cats = []
else:
cats.append(userinput)
return Folder(title, cats)
def removeFolder(folders):
while True:
if len(folders) > 0:
print("Enter the number of the folder you wish to remove.")
userinput = input(">>> ")
if userinput.isnumeric() and int(userinput) in range(1, len(folders)+1):
return folders[int(userinput) - 1]
else:
print("ERROR: Invalid choice.")
else:
print("ERROR! No folders left to delete.")
return -1
def customBuild():
os.system("clear")
userFolders = DEFAULTS
for i in range(2): print()
print("The default folders are preloaded and will be listed for you.")
print("After listing all preloads, you will be given the opportunity to edit.")
print("** You might want to maximize your terminal window to get a better view.")
print()
input("PRESS RETURN TO CONTINUE... ")
stillEditing = True
while stillEditing:
os.system("clear")
for x in range(2): print()
listCats(userFolders)
choice = editMenu()
if choice == "add":
userFolders.append(addFolder())
elif choice == "delete":
deleteChoice = removeFolder(userFolders)
if deleteChoice != -1:
userFolders.remove(deleteChoice)
elif choice == "delete-all":
if ynQuery("Really delete all existing folders?"):
userFolders = []
else:
print("Cancelled.")
elif choice == "done":
if len(userFolders) == 0:
os.system("clear")
for i in range(2): print()
print("ERROR: You must have at least one folder.")
print("To delete all, use reset function in main menu.")
print("Exiting.")
sys.exit()
os.system("clear")
listCats(userFolders)
if ynQuery("""
-------------------------------------------------
Please confirm that your categories are correctly
formatted before continuing. Failing to do so may
cause damage to your system configuration.
Make sure there aren't any duplicate entries
or misspellings.
Furthermore, be mindful that any previously created
folders, by user or other means will be permanently
erased and replaced with the configuration here.
Are you sure the information above is correct and that
you want to write these changes to disk?"""):
stillEditing = False
doReset()
writeSettings(userFolders)
os.system("clear")
for i in range(2): print()
print("Changes written to disk.")
# Main code execution begins below this line.
os.system("clear")
for i in range(2): print()
print("""GNOME DASH FIX
Copyright (c) 2017 Ben Godfrey
Welcome! This script can help you organize
your GNOME Apps Dashboard into categories.""")
print()
input("PRESS RETURN TO BEGIN...")
os.system("clear")
for i in range(2): print()
print("""This software is currently in beta and may
not function as intended. You use this software
at your own risk -- you are responsible for
any damages that occur.
This software is licensed under the MIT License.
For full license terms, see the project's
GitHub page (https://github.com/benjetson/gnome-dash-fix)
""")
if not ynQuery("Do you agree to the terms and conditions?"):
for i in range(2): print()
print("ERROR: You cannot run this software without agreeing to the terms.")
os.system("clear")
choice = menu()
if choice == 1:
setSorted()
elif choice == 2:
customBuild()
#print("Sorry! This feature is currently planned, but not yet implemented.")
elif choice == 3:
resetAll()
elif choice == 4:
print("Goodbye.")
sys.exit()