-
Notifications
You must be signed in to change notification settings - Fork 0
/
first_pass.py
121 lines (108 loc) · 4.53 KB
/
first_pass.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
import tkinter as tk
import data_manager as dm
import html_compiler as hc
import confirm_dialogue as cd
import info_dialogue as id
import os
from PIL import Image, ImageTk
def main(old_window=None, return_function=lambda *_: None):
if old_window:
old_window.destroy()
window = tk.Tk()
window.state('zoomed')
greeting = tk.Label(master=window, text="Fill in the information for the following picture:")
greeting.pack()
frame = tk.Frame(master=window, borderwidth=5)
frame.pack()
data_manager = dm.Data_manager()
try:
data_manager.load_data()
except:
pass
name_frame = tk.Frame(master=frame, borderwidth=5)
name_frame.pack(side=tk.LEFT)
name_label = tk.Label(master=name_frame, text="Name:")
name_entry = tk.Entry(master=name_frame, width=50)
name_label.pack()
name_entry.pack()
number_frame = tk.Frame(master=frame, borderwidth=5)
number_frame.pack(side=tk.LEFT)
number_label = tk.Label(master=number_frame, text="Number:")
number_entry = tk.Entry(master=number_frame, width=20)
number_label.pack()
number_entry.pack()
picture_frame = tk.Frame(master=frame, borderwidth=5)
picture_frame.pack(side=tk.LEFT)
try:
img = os.path.join("pictures", data_manager.get_next_picture())
except EOFError:
id.info_dialogue("No images remain, redirecting to catalog creator", hc.main, old_window=window, return_function=return_function)
return
load = Image.open(img)
load = load.resize((250, 250), Image.ANTIALIAS)
render = ImageTk.PhotoImage(load)
picture_label_text = tk.Label(master=picture_frame, text=img)
picture_label = tk.Label(master=picture_frame, image=render)
picture_label_text.pack()
picture_label.pack()
description_frame = tk.Frame(master=frame, borderwidth=5)
description_frame.pack(side=tk.LEFT)
description_label = tk.Label(master=description_frame, text="Description:")
description_entry = tk.Text(master=description_frame, width=100)
description_label.pack()
description_entry.pack()
error_label = tk.Label(master=window, text="", fg="red")
error_label.pack()
def submit_call():
nonlocal img
data = {}
data["name"] = name_entry.get()
data["number"] = number_entry.get()
data["description"] = description_entry.get("1.0", tk.END)
data["picture"] = img
errors = check_errors(data)
error_label.configure(text=errors)
error_label.text = errors
if errors:
return
data_manager.collect_data(data)
data_manager.save_data()
name_entry.delete(0, tk.END)
number_entry.delete(0, tk.END)
description_entry.delete("1.0", tk.END)
try:
new_img = os.path.join("pictures", data_manager.get_next_picture())
except EOFError:
id.info_dialogue("No images remain, redirecting to catalog creator", hc.main, old_window=window, return_function=return_function)
return
load = Image.open(new_img)
load = load.resize((250, 250), Image.ANTIALIAS)
render = ImageTk.PhotoImage(load)
picture_label.configure(image=render)
picture_label.image = render
picture_label_text.configure(text=new_img)
picture_label_text.text = new_img
img = new_img
def check_errors(data):
if not data["name"]:
return "Please provide a name for the picture."
if not data["number"] or not data["number"].isnumeric() or int(data["number"]) < 1:
return "Please provide a valid number for the picture."
dataset_numbers = [entry["number"] for entry in data_manager.database]
if data["number"] in dataset_numbers:
return "A picture in the dataset already uses this number."
if not data["description"] or data["description"] == "\n":
return "Please provide a description for the picture."
if not data["picture"]:
return "Something went wrong with the picture. Please restart the program."
return ""
button = tk.Button(master=window, command=submit_call, text="Save and load next picture")
button.pack()
def main_menu_call():
nonlocal window
cd.confirm_dialogue("Return to main menu and discard unsaved changes?", return_function, window)
main_menu_frame = tk.Frame(master=window, borderwidth=50)
main_menu_frame.pack()
main_menu_button = tk.Button(master=main_menu_frame, command=main_menu_call, text="Main menu")
main_menu_button.pack()
window.mainloop()