forked from VoltaicHQ/Progress-Sheet-Updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
117 lines (107 loc) · 5.81 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
from tkinter import *
from tkinter import filedialog
import json
class Gui:
def __init__(self):
# Read config and initialize Variables for Gui
self.config = json.load(open('config.json', 'r'))
if self.config["open_config"]:
self.window = Tk()
self.window.title("Progress Sheet Updater - Configurator")
self.window.geometry("950x120")
self.path = StringVar()
self.sheet_id = StringVar()
self.calculate_averages = IntVar()
self.run_once = IntVar()
self.polling_interval = IntVar()
self.runs_to_average = IntVar()
self.open_config = IntVar()
self.file_watcher_mode = StringVar()
# Give startvalue to variables
self.calculate_averages.set(int(self.config["calculate_averages"]))
self.sheet_id.set(self.config["sheet_id"])
self.run_once.set(int(self.config["run_once"]))
self.polling_interval.set(int(self.config["polling_interval"]))
self.path.set(self.config["stats_path"])
self.runs_to_average.set(int(self.config["num_of_runs_to_average"]))
self.open_config.set(int(self.config["open_config"]))
self.file_watcher_mode.set(self.config["file_watcher_mode"])
self.file_watcher_options = ["watchdog",
"interval"]
def browse_path(self):
self.path.set(filedialog.askdirectory(initialdir=self.path.get(), title="Open Folder"))
def finished(self):
self.config["stats_path"] = self.path.get()
if self.sheet_id.get().find("docs.google.com") != -1:
full_link = self.sheet_id.get()
id_temp = full_link[full_link.find("/d/") + 3:]
id_temp = id_temp[:id_temp.find("/")]
self.sheet_id.set(id_temp)
self.config["sheet_id"] = self.sheet_id.get()
self.config["calculate_averages"] = (self.calculate_averages.get() == 1)
self.config["run_once"] = (self.run_once.get() == 1)
self.config["num_of_runs_to_average"] = self.runs_to_average.get()
self.config["polling_interval"] = self.polling_interval.get()
self.config["open_config"] = self.open_config.get() == 1
self.config["file_watcher_mode"] = self.file_watcher_mode.get()
with open("config.json", "w") as outfile:
json.dump(self.config, outfile, indent=4)
self.window.destroy()
def main(self):
if self.config["open_config"]:
# Gui for path
path_frame = Frame(self.window)
pre_path_label = Label(path_frame, text="Kovaak's Stats Path: ")
browse_path_button = Button(path_frame, text="Browse", command=self.browse_path)
path_label = Label(path_frame, textvariable=self.path)
pre_path_label.pack(side="left")
path_label.pack(side="left")
browse_path_button.pack(side="right")
# Gui for sheetid
sheet_id_frame = Frame(self.window)
sheet_id_entry = Entry(sheet_id_frame, textvariable=self.sheet_id)
pre_sheet_id_label = Label(sheet_id_frame, text="Progress Sheet ID: ")
pre_sheet_id_label.pack(side="left")
sheet_id_entry.pack(fill="x")
# Gui for advanced options
advanced_padding = 25
advanced_frame = Frame(self.window)
# Calculate Averages
calculate_averages_box = Checkbutton(advanced_frame, variable=self.calculate_averages,
text="Calculate Averages")
calculate_averages_box.pack(side="left", padx=advanced_padding)
# Run once
run_once_box = Checkbutton(advanced_frame, text="Run Once", variable=self.run_once)
run_once_box.pack(side="left", padx=advanced_padding)
# Open config
open_config_box = Checkbutton(advanced_frame, text="Open config", variable=self.open_config)
open_config_box.pack(side="left", padx=advanced_padding)
# Polling interval
polling_interval_frame = Frame(advanced_frame)
polling_interval_label = Label(polling_interval_frame, text="Polling Interval")
polling_interval_entry = Entry(polling_interval_frame, textvariable=self.polling_interval, width=5)
polling_interval_entry.pack(side="left")
polling_interval_label.pack(side="left")
polling_interval_frame.pack(side="left", padx=advanced_padding)
# Runs to average
runs_to_average_frame = Frame(advanced_frame)
runs_to_average_entry = Entry(runs_to_average_frame, textvariable=self.runs_to_average, width=3)
runs_to_average_label = Label(runs_to_average_frame, text="Number of runs to average")
runs_to_average_entry.pack(side="left")
runs_to_average_label.pack(side="left")
runs_to_average_frame.pack(side="left", padx=advanced_padding)
# File watcher mode
file_watcher_dropdown = OptionMenu(advanced_frame, self.file_watcher_mode, *self.file_watcher_options)
file_watcher_dropdown.pack(side="left")
# Finished button
finished_frame = Frame(self.window)
finished_button = Button(finished_frame, command=self.finished, text="Finish")
finished_button.pack()
# Pack all frames and run mainloop
path_frame.pack(fill="x")
sheet_id_frame.pack(fill="x")
advanced_label = Label(self.window, text="Advanced Settings")
advanced_label.pack()
advanced_frame.pack(fill="x")
finished_frame.pack(fill="x")
self.window.mainloop()