-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.py
217 lines (181 loc) · 10 KB
/
GUI.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
import tkinter as tk
from tkinter import filedialog
import variable_container as vc
import api_work
import os
import requests
background_color = 'light green'
def generateKey():
def submitted(subRoot, subRoot2, email, root, no_credentials = False):
subRoot2.destroy()
subRoot2 = tk.LabelFrame(subRoot, border=0)
subRoot2.grid(padx=10, pady=5)
lab = tk.Label(subRoot2, text="Generating key....Please Wait...")
lab.grid(row=1, column=1, padx=10)
root.update()
#--------------------Key generation center--------------------------------------
if no_credentials:
pass
else:
if requests.post('https://tinify.com/web/api', json = {'fullName':'noone', 'mail':email}).status_code == 200:
lab.config(text="Now, check your email for the key and paste it in the empty API field", height=5)
else:
lab.config(text="Unable to generate key.\nEither the internet is down or too many requests have been made from this network.", height=5)
#-----------------------------------------------------------------------------
tk.Button(subRoot2, text="Ok", command=root.destroy, width=10).grid(row=2, columnspan=2, pady=5)
root.update()
root = tk.Tk()
root.title('Key Generator')
subRoot = tk.LabelFrame(root, border=0)
subRoot.grid(padx=10, pady=0)
subRoot2 = tk.LabelFrame(subRoot, border=0)
subRoot2.grid()
tk.Label(subRoot2, text="Enter your email:").grid(row=1, column=1, padx=5, pady=5)
ent = tk.Entry(subRoot2, width=30)
ent.grid(row=1, column=2, padx=5)
tk.Button(subRoot2, text='Submit', command=lambda: submitted(subRoot, subRoot2, ent.get(), root)).grid(row=2, columnspan=10, padx=3)
#tk.Button(subRoot2, text='Generate with no credentials.', command=lambda: submitted(subRoot, subRoot2, ent.get(), root, no_credentials = True)).grid(row=2, column=2, padx=3)
root.mainloop()
def reset_all_data():
reset_image_list()
reset_log_screen()
entry.delete(0, tk.END)
vc.optimization_number_entry.delete(0, tk.END)
update_destination_path(False)
height_entry.delete(0,tk.END)
width_entry.delete(0,tk.END)
def update_destination_path(stat):
def button_pressed():
vc.destination_directory = catch_here.get()
vc.files_log_dialog.insert(tk.END, '\nOutput image path updated to: ' + vc.destination_directory)
temp_window.destroy()
if stat:
temp_window = tk.Tk()
temp_window.title('Set Output Path')
tk.Label(temp_window, height = 3, text = 'Enter path to store images').pack(anchor = 'w')
catch_here = tk.Entry(temp_window, width = 50, border = 2)
catch_here.pack()
catch_here.insert(0, os.getcwd())
tk.Button(temp_window, height = 2, width = 10, text = 'Set Path', command = button_pressed).pack(pady = 10)
else:
try:
vc.destination_directory = os.path.dirname(vc.var_images[0])
except:
raise
vc.current_directory = os.getcwd()
def reset_log_screen():
vc.files_log_dialog.delete(2.0,tk.END)
def reset_image_list():
vc.var_images = None
vc.files_log_dialog.insert(tk.END, '\nNo Images selected currently.. Select Images before begining optimization')
entry.delete(0, tk.END)
def import_images():
# update_compression_counter()
vc.files_log_dialog.insert(tk.END, '\nAdding Images')
vc.var_images = filedialog.askopenfilenames(parent = root, title = "Select your images", filetypes = (vc.filetypes))
for i in vc.var_images:
entry.insert(0, i + ', ')
vc.files_log_dialog.insert(tk.END, '\n' + 'Added Image: ' + i)
vc.files_log_dialog.update_idletasks()
update_destination_path(False)
def update_extension_status():
vc.files_log_dialog.insert(tk.END, '\n"' + vc.var_extension.get().upper() + '" selected as output format')
def optimizing_animation():
pass
def metadata_log_update(metadata_to_delete):
if vc.metadata_list.get(metadata_to_delete)[1].get() == 1:
vc.files_log_dialog.insert(tk.END, ('\n' + metadata_to_delete + '\'s metadata is marked to be deleted'))
if vc.metadata_list.get(metadata_to_delete)[1].get() == 0:
vc.files_log_dialog.insert(tk.END, ('\n' + metadata_to_delete + ' is unmarked and it\'s metadata now is to be preserved'))
if __name__ == "__main__":
rootPrime = tk.Tk()
#rootPrime.call('wm', 'iconbitmap', rootPrime, os.getcwd()+"/favicon.pngn")
rootPrime.geometry('1125x700')
rootPrime.configure(bg = background_color)
rootPrime.title('Image Resizer')
root = tk.LabelFrame(rootPrime, bg=background_color)
root.grid(padx=10, pady=10)
#----------------------------------------------GUI FROM HERE---------------------------------------------
entry_frame = tk.LabelFrame(root, text = 'Add Images', height = 65, font = ' Arial, 13', bg = background_color)
entry = tk.Entry(entry_frame, width = 50)
entry.grid(row = 0, column = 0, sticky = 'ew', padx = 10)
entry_button = tk.Button(entry_frame, text = 'Add Images', height = 1, width = 10, command = import_images).grid(row = 0, column = 1, pady = 5)
entry_frame.grid(row = 0, column = 0, pady = 5)
files_frame = tk.LabelFrame(root, text = 'Files Log', font = "Arial, 13", bg = background_color)
vc.files_log_dialog = tk.Text(files_frame, width = 70, height = 35, bg = 'black', fg= 'light green')
vc.files_log_dialog.insert(tk.END, '---------------------------Operation Log----------------------------')
vc.files_log_dialog.grid(row = 0, column = 0)
files_frame.grid(row = 1, column = 0, columnspan = 2, padx = 10)
# Extension checkboxes
output_file_frame = tk.LabelFrame(root, text = 'Output Format', bg = background_color)
vc.var_extension = tk.StringVar()
for key, i in vc.extension_list.items():
tk.Checkbutton(output_file_frame, text = key.upper(), onvalue = key, offvalue = None, variable = vc.var_extension, bg = background_color, command = update_extension_status).grid(row = i[0], column = i[1], padx = 2, pady = 2)
output_file_frame.grid(row = 0, column = 1)
# Left parent frame
left_frame_wrapper = tk.LabelFrame(root, bg = background_color, border = 0)
# Height and width options
dimension_frame = tk.LabelFrame(left_frame_wrapper, text = 'Output file dimension', bg = background_color)
vc.var_height = tk.IntVar()
vc.var_width = tk.IntVar()
tk.Label(dimension_frame, text = 'Height', bg = background_color).grid(row = 0, column = 0)
tk.Label(dimension_frame, text = 'Width', bg = background_color).grid(row = 0, column = 1)
height_entry = tk.Entry(dimension_frame, textvariable = vc.var_height)
width_entry = tk.Entry(dimension_frame, textvariable = vc.var_width)
height_entry.grid(row = 1, column = 0, padx = 5, pady = 5)
width_entry.grid(row = 1, column = 1, padx = 5, pady = 5)
dimension_frame.grid(row = 0, sticky = 'n')
# Metadata options
metadata_frame = tk.LabelFrame(left_frame_wrapper, text = 'Delete Image Metadata(Checked = Delete Metadata)', bg = background_color)
for key, i in vc.metadata_list.items():
i[1] = tk.IntVar()
tk.Checkbutton(metadata_frame, text = key.upper(), bg = background_color, variable = i[1], command = lambda param = key: metadata_log_update(param)).grid(row = i[0])
metadata_frame.grid(row = 1, sticky = 'n', pady = 10)
# Frame to provide API Key
api_frame = tk.LabelFrame(left_frame_wrapper, text = 'API Key Field', bg = background_color)
vc.api_entry = tk.Entry(api_frame, width = 50)
vc.api_entry.grid(row=0, column = 0)
try:
vc.api_entry.insert(0, vc.var_api_key)
vc.files_log_dialog.insert(tk.END, '\nAdded API key: {}'.format(vc.api_entry.get()))
#Hide function for key
def hideKey(var):
if var:
hide_key.configure(text='Show Key')
vc.api_entry.delete(0,tk.END)
vc.api_entry.insert(0, vc.var_api_key)
else:
hide_key.configure(text='Hide Key')
var_hide_key = tk.IntVar()
hide_key = tk.Checkbutton(api_frame, text='Hide Key', bg=background_color, variable = var_hide_key, command = lambda param = var_hide_key: hideKey(param))
hide_key.grid(row = 0, column = 1, padx = 10)
except AttributeError:
generateButton = tk.Button(api_frame, text='Generate API Key', command=generateKey, bg=background_color)
generateButton.grid(row=1)
vc.files_log_dialog.insert(tk.END, "\nInsert API key or generate one from the API Key Field....")
pass
vc.files_log_dialog.update_idletasks()
api_frame.grid(row = 2)
left_frame_wrapper.grid(row = 0, column = 2, rowspan = 2, sticky = 'n')
# Left Parent frame ends
# Left Bottom Buttons Frame
bottom_frame = tk.LabelFrame(root, bg = background_color, border=0)
tk.Button(bottom_frame, text = 'Reset Image List', height = 1, width = 20, command = reset_image_list).grid(row = 1, column = 0, padx = 5, pady = 5)
tk.Button(bottom_frame, text = 'Reset All Data', height = 1, width = 20, command = reset_all_data).grid(row = 1, column = 1, padx = 5, pady = 5)
tk.Button(bottom_frame, text = 'Reset Log Screen', height = 1, width = 20, command = reset_log_screen).grid(row = 2, column = 0, padx = 5, pady = 5)
tk.Button(bottom_frame, text = 'Set Image Output Path', height = 1, width = 20, command = lambda: update_destination_path(True)).grid(row = 2, column = 1, padx = 5, pady = 5)
tk.Button(bottom_frame, text = "Optimize for one time", height = 3, width = 30, command = lambda: api_work.convert_the_images(1)).grid(row = 3, column = 0, pady = 10, columnspan = 2)
tk.Button(bottom_frame, text = "Optimize Multiple Times", height = 3, width = 30, command = lambda: api_work.convert_the_images(int(vc.optimization_number_entry.get()))).grid(row = 4, column = 0, pady = 10, columnspan = 2)
tk.Label(bottom_frame, width = 30, height = 2, text = 'Enter the no of optimizations', anchor = 'n', bg = background_color).grid(row = 6, columnspan = 2)
vc.optimization_number_entry = tk.Entry(bottom_frame, width = 15, border = 1)
vc.optimization_number_entry.grid(row = 5, columnspan = 2, sticky = 's')
compression_count = tk.LabelFrame(bottom_frame, text = 'Compression Counter', bg = background_color)
vc.compression_status_container = tk.Text(compression_count, height = 4, width = 45, bg = 'black', fg = 'light green')
vc.compression_status_container.pack()
compression_count.grid(row = 0, columnspan = 2, pady = 10)
bottom_frame.grid(row = 1, column = 2, padx = 5, pady = 5, sticky = 's')
try:
vc.update_compression_counter()
except:
vc.files_log_dialog.insert(tk.END, 'Something is wrong...\nCheck Internet Connection')
root.mainloop()