-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsites_app.py
90 lines (73 loc) · 3.06 KB
/
websites_app.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
"""
websites_app.py
Code for Mohammad's experiment
"""
import tkinter as tk
from tkinter import filedialog, messagebox
from tkinter.ttk import Button, Frame, Label
from multimotions.dataprocessor import DataProcessor
def run_web_app(root):
"""Main method called from the application entry point to run the GUI."""
root.title("Website Heatmap Experiment")
def select_file(entry):
filepath = filedialog.askopenfilename(
filetypes=[("CSV Files", "*.csv"), ("All Files", "*.*")]
)
if filepath:
entry.delete(0, tk.END)
entry.insert(0, filepath)
def select_directory(entry):
directory = filedialog.askdirectory()
if directory:
entry.delete(0, tk.END)
entry.insert(0, directory)
def generate_heatmap():
imotions_csv = imotions_entry.get()
scroll_csv = scroll_entry.get()
output_path = output_path_entry.get()
screenshot_path = screenshot_entry.get()
if not imotions_csv or not scroll_csv or not output_path:
messagebox.showerror(
"Error", "Please select all required files and output directory"
)
return
processor = DataProcessor(scroll_csv, imotions_csv, output_path)
processor.process_data()
fig = processor.plot_heatmap(screenshot_path)
# save plot to file and save in output_path
fig.savefig(f"{output_path}/heatmap.png", dpi=1000)
# Open the file in the ouptut path
messagebox.showinfo("Success", "Heatmap generated successfully")
fig.show()
# File selection UI
frame = Frame(root)
frame.pack(pady=20)
Label(frame, text="iMotions CSV:").grid(row=0, column=0, padx=5, pady=5)
imotions_entry = tk.Entry(frame)
imotions_entry.grid(row=0, column=1, padx=5, pady=5)
Button(frame, text="Browse", command=lambda: select_file(imotions_entry)).grid(
row=0, column=2, padx=5, pady=5
)
Label(frame, text="Scroll CSV:").grid(row=1, column=0, padx=5, pady=5)
scroll_entry = tk.Entry(frame)
scroll_entry.grid(row=1, column=1, padx=5, pady=5)
Button(frame, text="Browse", command=lambda: select_file(scroll_entry)).grid(
row=1, column=2, padx=5, pady=5
)
Label(frame, text="Output Path:").grid(row=2, column=0, padx=5, pady=5)
output_path_entry = tk.Entry(frame)
output_path_entry.grid(row=2, column=1, padx=5, pady=5)
Button(
frame, text="Browse", command=lambda: select_directory(output_path_entry)
).grid(row=2, column=2, padx=5, pady=5)
# screenshot file input
Label(frame, text="Website Screenshot:").grid(row=3, column=0, padx=5, pady=5)
screenshot_entry = tk.Entry(frame)
screenshot_entry.grid(row=3, column=1, padx=5, pady=5)
Button(frame, text="Browse", command=lambda: select_file(screenshot_entry)).grid(
row=3, column=2, padx=5, pady=5
)
Button(root, text="Generate Heatmap", command=generate_heatmap).pack(pady=10)
# Frame for plotting
plot_frame = Frame(root)
plot_frame.pack(fill=tk.BOTH, expand=True)