-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
152 lines (123 loc) · 6.09 KB
/
app.py
File metadata and controls
152 lines (123 loc) · 6.09 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
# Tkinter is imported to be able to create the UI
import tkinter as tk
# Filedialog is imported to allow file/directory selection window
from tkinter import filedialog
# os is imported to allow communication with the operating system to launch the applications
import os
# variable root set for the root tk.TK()
root = tk.Tk()
# apps array declared
apps = []
if os.path.isfile('save.txt'):
with open('save.txt', 'r') as f:
tempApps = f.read()
tempApps = tempApps.split(',')
apps = [x for x in tempApps if x.strip()]
print(apps)
# function created for the addApp button
def addApp():
# this prevents the duplicated children widgets when adding new apps to the list
for widget in frame.winfo_children():
widget.destroy()
# line below will append the file name selected to the variable filename to be used later to append to apps list
filename = filedialog.askopenfilename(
initialdir="/", title="Select file", filetypes=(("executables", "*.exe"), ("all files", "*.*")))
# this line will append the application to the apps list if one is selected,
if filename:
apps.append(filename)
# this below is terminal output to confirm app added title
print("The app added is: ")
# this below is terminal output to confirm app added by displaying the filename
print(filename)
print("\n")
# if an app is appended than this following block of code will be executed to add labels
for app in apps:
# this below is used to display the frame title "app added to list",
# also will show the index position converted to string as part of title
labelTitle = tk.Label(frame, text="List item number: \n" + str(apps.index(app)+1), fg="black", font=1, bg="goldenrod1")
# this below is used to populate the filename which was appended to apps
labelFile = tk.Label(frame, text=app, font=1, bg="wheat")
labelTitle.pack()
labelFile.pack()
# if no app is appended then this block will be executed
else:
print("No file selected to add\n")
for app in apps:
# this below is used to display the frame title "app added to list",
# also will show the index position converted to string as part of title,
# it's not perfect, if duplicate it will return first index position of duplicate, need to fix
labelTitle = tk.Label(frame, text="List item number: \n" + str(apps.index(app)+1), fg="black", font=1, bg="goldenrod1")
labelFile = tk.Label(frame, text=app, font=1, bg="wheat")
labelTitle.pack()
labelFile.pack()
# Added the function for the remove button to remove the item at index[0] in apps array
# and also remove the labelFile/labelTitle associated will the app in index[0]
def removeApp():
# this will destroy all children frames upon refresh of the screen
for widget in frame.winfo_children():
widget.destroy()
# if there are apps stored in the apps array, then delete the app in index[0]
# then console log display the app which was removed
# then console log display all the remaining apps in the list
if apps:
deleteItem = apps.pop(0)
print("The file removed is:") # this line is just for console log neatness
print(deleteItem)
print("\nthe remaining file(s) are: ") # this line is just for console log neatness
print(apps)
print("\n") # this line is just for console log neatness
else:
print("\n No list items remain to delete")
# this below is used to display the frame title "app added to list".
# also will show the index position converted to string as part of title,
# it's not perfect, if duplicate it will return first index position of duplicate, need to fix
for app in apps:
labelTitle = tk.Label(frame, text="List item number: \n" + str(apps.index(app) + 1), fg="black", font=1, bg="goldenrod1")
labelFile = tk.Label(frame, text=app, font=1, bg="wheat")
labelTitle.pack()
labelFile.pack()
# function created to run the apps for the runnApps button
def runApps():
# following will check if there are any apps added to apps[], if so launch them all,
# if not display message to inform no items in list
if apps:
for app in apps:
os.startfile(app)
print("The following app was launched successfully: ")
print(app)
else:
print("Unable to launch, no apps in the list")
# Configure the ROOT color
root.configure(bg='tomato')
# Create label for Root Title
rootLabel = tk.Label(root, text="Remember Me App Launcher", font=1, bg="wheat2")
# add label to pack() to display on root
rootLabel.pack()
canvas = tk.Canvas(root, height=400, width=700, bg="tomato")
canvas.pack()
frame = tk.Frame(root, bg="tan1")
frame.place(relx=0.1, rely=0.1, relwidth=0.8, relheight=0.8)
openFile = tk.Button(root, text="Add File", padx=25,
pady=10, fg='white', bg="#263D42", command=addApp)
openFile.pack()
# Added a remove file button
removeFile = tk.Button(root, text="Remove File", padx=25,
pady=10, fg='white', bg="#263D42", command=removeApp)
# This will append the remove button to the root, which will display on the screen
removeFile.pack()
runApps = tk.Button(root, text="Run Apps", padx=25,
pady=10, fg='white', bg="#263D42", command=runApps)
runApps.pack()
# this displays the list after app is launched again, not a rerun, just a fresh new launch
for app in apps:
# this below is used to display the frame title "app added to list",
# also will show the index position converted to string as part of title,
# it's not perfect, if duplicate it will return first index position of duplicate, need to fix
labelTitle = tk.Label(frame, text="List item number: \n" + str(apps.index(app)+1), fg="black", font=1, bg="goldenrod1")
labelFile = tk.Label(frame, text=app, font=1, bg="wheat")
labelTitle.pack()
labelFile.pack()
root.mainloop()
with open('save.txt', 'w') as f:
for app in apps:
f.write(app + ',')