-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgui.py
More file actions
171 lines (137 loc) · 5.41 KB
/
gui.py
File metadata and controls
171 lines (137 loc) · 5.41 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
import tkinter as tk
import tkinterdnd2 as tkdnd
from tkinter import ttk, messagebox
from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk
import pandas as pd
import matplotlib.pyplot as plt
from methods import(
find_correlations,
create_7d_histogram,
create_30d_histogram,
clear_plot_frame,
create_7d_matchrate_histogram,
)
import matchrate
import load_data
import zipfile
import shutil
import extract
# Constants
WINDOW_TITLE = 'Data Exploration'
WINDOW_SIZE = '800x600'
# Check if the folder 'Data' exists, and create it if it doesn't
if not os.path.exists('Data'):
os.makedirs('Data')
def calc_gui(selected_folder):
data = load_data.load(selected_folder)
# Create GUI window
window = tk.Tk()
window.title(WINDOW_TITLE)
window.geometry(WINDOW_SIZE)
#window.attributes('-fullscreen', True) # Open the GUI in full-screen mode
# Create the frame for the plot
plot_frame = tk.Frame(window)
plot_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
# Button actions
def display_correlation():
correlations = data.corr()
lbl_result.config(text=correlations)
find_correlations(data, lbl_result, plot_frame)
def display_7day_matchrate_histogram():
clear_plot_frame(plot_frame)
# Load the data from the file
data2 = data.copy()
# Call the calculate_match_rate function from matchrate.py to calculate the match rate
match_rate = matchrate.calculate_match_rate(data2)
# Call create_7d_matchrate_histogram function from methods.py to create the histogram
create_7d_matchrate_histogram(match_rate, plot_frame)
def display_7day_histogram():
clear_plot_frame(plot_frame)
create_7d_histogram(data, plot_frame)
def display_30day_histogram():
clear_plot_frame(plot_frame)
create_30d_histogram(data, plot_frame)
def calculate_total_swipes():
global data
data = calculate_total_swipes(data)
def close_window():
window.destroy()
# Helper function to destroy plots
def destroy_plots():
plt.close('all')
# Create GUI elements
btn_frame = tk.Frame(window)
btn_frame.pack(pady=20)
btn_correlation = ttk.Button(btn_frame, text="Find Correlations", command=display_correlation)
btn_correlation.pack(side=tk.LEFT, padx=10)
btn_histogram_7d = ttk.Button(btn_frame, text="Create 7D Histogram", command=display_7day_histogram)
btn_histogram_7d.pack(side=tk.LEFT, padx=10)
btn_histogram_30d = ttk.Button(btn_frame, text="Create 30D Histogram", command=display_30day_histogram)
btn_histogram_30d.pack(side=tk.LEFT, padx=10)
btn_calculate = ttk.Button(btn_frame, text="Calculate Swipes", command=calculate_total_swipes)
btn_calculate.pack(side=tk.LEFT, padx=10)
btn_exit = ttk.Button(window, text="Exit App", command=close_window)
btn_exit.pack(side=tk.BOTTOM, pady=20)
# Create the button to display the 7-day match rate histogram
btn_matchrate_histogram = ttk.Button(btn_frame, text="Calculate Match Rate Histogram", command=display_7day_matchrate_histogram)
btn_matchrate_histogram.pack(side=tk.LEFT, padx=10)
lbl_result = ttk.Label(window, text="")
lbl_result.pack()
return window
def explorer_gui():
def open_selected_item(event):
selected_item = tree.focus()
if selected_item:
item_type = tree.item(selected_item)['values'][1]
if item_type == 'Folder':
folder_path = tree.item(selected_item)['values'][0]
open_second_gui(folder_path)
def open_second_gui(selected_folder):
window.destroy() # Hide the first GUI window
calc_gui(selected_folder)
# Add your code for the second GUI window here
pass
def handle_drop(event):
print("handling drop")
zip_file = None
file = event.data
if os.path.isfile(file) and file.endswith('.zip'):
zip_file = file
else:
print("File is not a zip file")
if zip_file:
print(zip_file)
destination = os.path.join("Data", "myData.zip")
shutil.copy2(zip_file, destination)
extract.extract()
populate_treeview()
def populate_treeview():
tree.delete(*tree.get_children()) # Clear the treeview
base_path = "Data"
for item in os.listdir(base_path):
item_path = os.path.join(base_path, item)
if os.path.isdir(item_path):
tree.insert('', 'end', text=item, values=(item_path, 'Folder'))
window = tkdnd.TkinterDnD.Tk()
window.title('Explorer')
window.geometry('600x400')
# Create the treeview widget
tree = ttk.Treeview(window)
tree.pack(fill=tk.BOTH, expand=True)
tree.bind('<<TreeviewSelect>>', open_selected_item)
# Create the columns
tree['columns'] = ('path', 'type')
tree.column('path', width=300)
tree.column('type', width=50)
# Define the column headings
tree.heading('#0', text='Name')
tree.heading('path', text='Path')
tree.heading('type', text='Type')
# Enable drag and drop functionality
drop_label = tk.Label(window, text="Drop ZIP file here", justify=tk.CENTER)
drop_label.pack(fill=tk.BOTH, padx=10, pady=10)
drop_label.drop_target_register(tkdnd.DND_FILES)
drop_label.dnd_bind('<<Drop>>', handle_drop)
populate_treeview()
window.mainloop()