-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0Main.py
More file actions
287 lines (249 loc) · 12.9 KB
/
0Main.py
File metadata and controls
287 lines (249 loc) · 12.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
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
'''
██████╗░███████╗░██████╗██╗░░██╗███╗░░░███╗░█████╗░░██████╗████████╗███████╗██████╗░
██╔══██╗██╔════╝██╔════╝██║░██╔╝████╗░████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗
██║░░██║█████╗░░╚█████╗░█████═╝░██╔████╔██║███████║╚█████╗░░░░██║░░░█████╗░░██████╔╝
██║░░██║██╔══╝░░░╚═══██╗██╔═██╗░██║╚██╔╝██║██╔══██║░╚═══██╗░░░██║░░░██╔══╝░░██╔══██╗
██████╔╝███████╗██████╔╝██║░╚██╗██║░╚═╝░██║██║░░██║██████╔╝░░░██║░░░███████╗██║░░██║
╚═════╝░╚══════╝╚═════╝░╚═╝░░╚═╝╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═════╝░░░░╚═╝░░░╚══════╝╚═╝░░╚═╝
version 1.0
(ascii art from: https://fsymbols.com/generators/carty/)
'''
import os
import subprocess
import shutil
script_path = os.path.dirname(os.path.abspath(__file__)) #path to this file
saver_path = script_path + "\saver.bat" #this file is responsable for saving desktops
# print("changing desktops too often (more than once every 30 sec) will temporarly disable your wallpaper (atleast if you are using Lively Wallpaper)")
# print("if this occurs just put them them back on again")
print("⚠️⚠️ LOADING AND MOVING WILL BRIEFLY KILL THE WINDOWS FILE EXPORER, make sure nothing is being uploaded/downloaded/deleted/moved around as it may corrupt the data ⚠️⚠️")
"""
def listDesks_old():
'''
:return: Lists all of the current folders in desktop (assumed to be desktop_files)
'''
global script_path
folder_path = script_path + "\Desktops"
file_list = os.listdir(folder_path)
return file_list
#Retired because it listed all files instead of just directories
"""
# currentDesktop = "currentDesk was not called"
if os.path.exists(script_path+"\Desktops") == False:
print("\Desktops file not found, making a new one")
os.mkdir(script_path+"\Desktops")
def currentDesk(command,data="if you see this you forgot to put the data in the write file"):
'''
:param command: r= read , w=write
:param data: desktop name (useless for read)
:return:
'''
global script_path
global currentDesktop
file_path = f"{script_path}\\data.txt"
if command == "r":
with open(file_path, 'r') as file:
currentDesktop = file.read()
return currentDesktop
if command == "w":
with open(file_path, 'w') as file:
currentDesktop = file.write(data)
# print("your current desktop is now: " + currentDesk("r") )
def listDesks(printOnly=False):
'''
:param printOnly: As the variable name suggests, this should only be used for printing out the current desktops.
:return: a list of all the desktops (unless printOnly)
'''
global script_path
global currentDesktop
currentDesktop=currentDesk("r")
directory = script_path + "\Desktops"
entries = os.scandir(directory) #scans "/Desktops" directory
directories = [entry.name for entry in entries if entry.is_dir()] #lists all folders
if printOnly == True:
'''
This effectively make a fake list because lists do not like ANSI escape sequences
'''
new_directories = []
for entry in directories:
new_directories.append(entry)
if entry == currentDesktop:
index = directories.index(entry)
directories[index] = '\033[4m' + entry + '\033[0m'
print("Current desktops: [",end="")
for entry in directories:
if entry is not directories[-1]:
print("\'" + entry + "\'", end=",")
else:
print("\'" + entry + "\'", end="")
print("]")
if printOnly == False:
return directories
# print('\033[4m' + ' entry ' + '\033[0m')
def save(word2):
global script_path
global saver_path
SatisfactoryExit= False
#word2 = filename (in this case)
while SatisfactoryExit== False:
if word2 is not False: #if the filename is not the False
if word2 in listDesks(): #if the file already exists (duplicate)
desks = listDesks()
desks_loop = 0
word2_base = word2
while word2 in desks: #if the itterated filename is STILL a duplicate
desks_loop += 1
word2 = word2_base + "("+ str(desks_loop) +")" #if the filename already exists make a new one like windows does save for the space between the base filename and iterated number.
os.mkdir(path=f"{script_path}\\Desktops\\{word2}") #makes directory in which the registry will be saved
print(f"Saved in:\"{script_path}\\Desktops\\{word2}\" as \"{word2}\" because \"{word2_base}\" was taken")
currentDesk("w",word2) #changes current desktop to the saved desktop
SatisfactoryExit= True
else:
os.mkdir(path=f"{script_path}\\Desktops\\{word2}") # creates folder
print(f"Saved in:\"{script_path}\\Desktops\\{word2}\" as \"{word2}\"")
currentDesk("w",word2) #changes current desktop to the saved desktop
SatisfactoryExit= True
else:
word2 = input("please specify a filename: ") #in case user has not given a filename at the start
#after a folder has been made
subprocess.call(saver_path) #calls upon the filesaver bat file
source = f"{script_path}\\DesktopIconLayoutSave.reg"
destination = f"{script_path}\\Desktops\\{word2}"
shutil.move(source, destination)
def load(word2):
global script_path
global saver_path
reg_file_directory = f"{script_path}\\Desktops\\{word2}\\DesktopIconLayoutSave.reg"
SatisfactoryExit= False
print("")
while SatisfactoryExit== False:
if word2 in listDesks():
print(reg_file_directory)
subprocess.call(['reg', 'import', reg_file_directory]) #merges reg file
# restarts Windows File Explorer
# os.system("taskkill /f /im explorer.exe")
# os.system("start explorer.exe")
currentDesk("w",word2) #changes current desktop in the data.txt file
SatisfactoryExit = True
else:
try: #checks if there are any desktops avalable, 99% better way to do it but good enough.
currentList = listDesks()[0]
except:
currentList = False
if currentList != False: #if a desktop does exist
# print(listDesks())
word2 = input("please specify which desktop you would like to load: ") #in case user has not given a filename at the start
else: #if there is no desktop
print("There are no desktops for you to load, use \"save\" to save your current desktop")
SatisfactoryExit = True
def move(word3):
"""
WARNING: STANDARDS CHANGE
:param word2: current desktop
:param word3: is actually word2 (the second word in the command)
was originally meant to do something else, kept word2 and word3 as is for because lazy
:return:
"""
global script_path
global saver_path
currentList = listDesks()
currentList_len = len(currentList)
word2= currentDesktop
SatisfactoryExit= False
print("")
if currentList_len == 0:
print("What are you exactly trying to move? you have no desktops, go make some (use the \"save\" functiion)")
SatisfactoryExit = True
if currentList_len == 1:
print("Move to what? You only have one desktop")
save(word3)
print("there... much better")
SatisfactoryExit = True
while SatisfactoryExit== False:
if word2 not in currentList:
print(f"your current desktop ({currentDesktop}) is not in the list (the desktop you will overwrite)")
print(f"Desktops: " + str(listDesks()))
word2 = input("Select a desktop to overwrite from the list above: ")
elif word3 == False:
print("you have not selected a desktop")
print(f"Desktops: " + str(listDesks()))
word3 = input("Select a desktop from the list above: ")
elif word3 not in currentList:
print(f"The desktop you have selected ({word3}) is not avalable")
print(f"Desktops: " + str(listDesks()))
word3 = input("Select a desktop from the list above: ")
elif word2 == word3:
print(f"The desktop you have selected ({word3}) is the same desktop as the currentDesktop ({currentDesktop}) ")
print(f"Desktops: " + str(listDesks()))
word3 = input("Please select another desktop: ")
else:
#this long ass if statement means, if both word2 and word3 exist, if both can be found in listDesks(), and they are not the same file
old_file_directory = f"{script_path}\\Desktops\\{word2}"
new_reg_file_directpry = f"{script_path}\\Desktops\\{word3}"
shutil.rmtree(old_file_directory) #Deletes the word2 directory and everything inside of it
save(word2) #makes the word2 directory again , saving the current desktop
load(word3) #loads the word3 directory
print(f"current desktop was saved to {word2} and now {word3} was loaded")
SatisfactoryExit= True
def helpprint():
print("Current commands are:")
print("+==========================================================+")
print("IMPORTANT: DESKTOP NAMES SHOULD NOT HAVE SPACES")
print("save [desktop name] - Saves the current desktop")
print("load [desktop name] - loads a desktop")
print("move [desktop name] - Overrides [currentDesktop] and loads [desktop name]")
print("help - prints the command list again")
print("(list/get) - lists the desktops and your currentDesktop without the formatting stuff without ASCII escape sequences, if "+ '\033[4m' + "this" + '\033[0m' " isn't underlined, use \"list\" and \"get\" to see your desktops")
print("+==========================================================+")
# currentDesktop = "Desk1test"
# print(f"Welcome to deskmanager, your current desktop is: \"{currentDesktop}\" ")
helpprint()
while 1:
print("\n")
print("████████████████████████████████████████████████████████")
desksCount = len(listDesks())
if desksCount != 0:
listDesks(printOnly=True) #prints out the desktops and underlines the current one
print("")
else:
print("There are no desktops, please make a desktop using the \"save\" function")
# print("")
currentinput = input("Command: ")
print("████████████████████████████████████████████████████████")
inputsplit = currentinput.split()
inputsplit_len = len(inputsplit)
word1 = inputsplit[0]
iterateInput = 0
for max in range(0, 3):
if iterateInput < inputsplit_len:
exec(f"word{iterateInput + 1} = '{inputsplit[iterateInput]}'")
else:
exec(f"word{iterateInput + 1} = {bool(False)}")
iterateInput += 1
#just checking how many items and assigning them to a variable, could have used
# try:
# word2 = inputsplit[1]
# except:
# word2 = False
# pass
#
# else:
# try:
# word3 = inputsplit[2]
# except:
# word3 = False
if word1 == "get" or word1 == "list":
currentDesk("r", word2)
print(f"Desktops: " + str(listDesks()))
print(f"your current desktop is: \"{currentDesktop}\" ")
if currentDesktop not in listDesks():
print("Note: the file to your current desktop does not exist, however its name is still saved in the data.txt file.")
elif word1 == "save":
save(word2)
elif word1 == "load":
load(word2)
elif word1 == "move":
move(word2)
elif word1 == "help":
helpprint()
else:
print("Command is invalid or a typo was made, try again...")