-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·51 lines (43 loc) · 1.64 KB
/
main.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
#!/usr/bin/python3
from tkinter import filedialog as fd, PhotoImage, messagebox
from tkinter.constants import END
from gui import window, button_1 as gen, button_2 as ex
from gui import button_3 as select_save
from gui import entry_1 as frames_entry, entry_2 as size_entry, entry_3 as output_loc
from center import center
center(window, size='320x350')
icon = PhotoImage(file='./icon.png')
window.iconphoto(False, icon)
window.title('Generate JSON')
def save_json_file():
s = fd.askdirectory(parent=window)
output_loc.delete(0, END)
output_loc.insert(0, s) # type: ignore
def generate():
images = fd.askopenfilenames(parent=window, title='Select all the images')
if not images:
return
frames = frames_entry.get()
size = size_entry.get()
output = output_loc.get()
if (len(frames) == 0 or len(size) == 0 or len(output) == 0 or
len(images) == 0):
messagebox.showerror(title='Error', message='Check inputs')
return
from generate import Anim
from lottie.utils import script
try:
anim = Anim(frames=frames, size=size,
images_location=images)
anim = anim.get()
except ValueError as err:
messagebox.showerror(title='Error', message=f'Error\n\n{err}')
return
script.script_main(anim, path=output, basename="my_anim", formats=['json'])
messagebox.showinfo(
'Done!', f'JSON file successfully generated\n{output}.')
gen.bind('<Button-1>', lambda _: generate())
ex.bind('<Button-1>', lambda _: window.quit())
select_save.bind('<Button-1>', lambda _: save_json_file())
if __name__ == "__main__":
window.mainloop()