-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoobydoo_csv_gui.py
204 lines (151 loc) · 8.27 KB
/
scoobydoo_csv_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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import tkinter as tk
from tkinter import filedialog, messagebox, simpledialog
from tkinter import ttk
import csvUtils
import jsonUtils
import textUtils # import the textUtils module
import pdfUtils # import the pdfUtils module
def generate_pdf_file():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
num_story_inputs = simpledialog.askinteger("Number of Story Inputs",
"Enter the number of story inputs to include (default: all CSV data):",
minvalue=1)
if not num_story_inputs:
return
pdfUtils.generate_pdf_file(input_file, num_story_inputs) # call the new function from the pdfUtils module
messagebox.showinfo("Success", "story_plots.pdf has been generated successfully.")
def generate_text_file():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
num_story_inputs = simpledialog.askinteger("Number of Story Inputs",
"Enter the number of story inputs to include (default: all CSV data):",
minvalue=1)
if not num_story_inputs:
return
textUtils.generate_text_file(input_file, num_story_inputs) # call the new function from the textUtils module
messagebox.showinfo("Success", "story_plots.txt has been generated successfully.")
def story_plots_data_preparation():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
num_json_objects = tk.simpledialog.askinteger("Number of JSON data objects",
"Enter the number of JSON data objects to generate (default: all CSV data):",
minvalue=1)
if not num_json_objects:
return
jsonUtils.prepare_story_plots(input_file, num_json_objects)
messagebox.showinfo("Success", "story_plots.json has been generated successfully.")
def remove_season_episode_indicators():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
output_file = filedialog.asksaveasfilename(title="Select the output CSV file")
if not output_file:
return
csvUtils.remove_season_episode_indicators(input_file, output_file)
messagebox.showinfo("Success", "Season and episode indicators have been removed successfully.")
def remove_custom_character():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
output_file = filedialog.asksaveasfilename(title="Select the output CSV file")
if not output_file:
return
custom_char = tk.simpledialog.askstring("Remove custom character", "Enter the custom character to remove:")
if not custom_char:
return
csvUtils.remove_custom_character(input_file, output_file, custom_char)
messagebox.showinfo("Success", f"Custom character '{custom_char}' has been removed successfully.")
def remove_nbsp():
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
output_file = filedialog.asksaveasfilename(title="Select the output CSV file")
if not output_file:
return
csvUtils.remove_nbsp(input_file, output_file)
messagebox.showinfo("Success", "Non-breaking spaces have been removed successfully.")
def split_long_plots():
# Define the dialog to get the input CSV file
input_file = filedialog.askopenfilename(title="Select the input CSV file")
if not input_file:
return
# Define the dialog to get the output CSV file
output_file = filedialog.asksaveasfilename(title="Select the output CSV file")
if not output_file:
return
# Ask for the maximum tokens per plot chunk
max_tokens = tk.simpledialog.askinteger("Maximum tokens",
"Enter the maximum tokens per plot chunk (default: 1000):", minvalue=1)
if not max_tokens:
return
csvUtils.split_long_plots(input_file, output_file, max_tokens)
messagebox.showinfo("Success", "Plots have been split successfully.")
class ScoobyDooCSVToolGUI(tk.Tk):
def __init__(self):
super().__init__()
self.title("ScoobyDoo CSV Tool")
self.geometry("600x400")
self.create_widgets()
def create_widgets(self):
# Create main frame
main_frame = ttk.Frame(self)
main_frame.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)
# Add the welcome label
welcome_label = ttk.Label(main_frame, text="Welcome to ScoobyDoo CSV Tool!", font=("Helvetica", 16, "bold"))
welcome_label.grid(row=0, column=0, columnspan=3, pady=10)
# Add the options label
options_label = ttk.Label(main_frame, text="Choose an option:", font=("Helvetica", 14))
options_label.grid(row=1, column=0, pady=10)
# Add the Split long plots button
split_long_plots_button = ttk.Button(main_frame, text="1. Split long plots", command=split_long_plots)
split_long_plots_button.grid(row=2, column=0, pady=5)
# Add the Remove specific characters button
remove_specific_characters_button = ttk.Button(main_frame, text="2. Remove specific characters",
command=self.remove_specific_characters)
remove_specific_characters_button.grid(row=3, column=0, pady=5)
# Add the Story plots data preparation to a JSON button
story_plots_data_preparation_button = ttk.Button(main_frame, text="3. Story plots data preparation to a JSON",
command=story_plots_data_preparation)
story_plots_data_preparation_button.grid(row=4, column=0, pady=5)
# Add the Generate Text File button
generate_text_file_button = ttk.Button(main_frame, text="4. Generate Text File", command=generate_text_file)
generate_text_file_button.grid(row=5, column=0, pady=5)
# Add the Generate PDF File button
generate_pdf_file_button = ttk.Button(main_frame, text="5. Generate PDF File", command=generate_pdf_file)
generate_pdf_file_button.grid(row=6, column=0, pady=5)
# Add the Exit button
exit_button = ttk.Button(main_frame, text="6. Exit", command=self.confirm_exit)
exit_button.grid(row=7, column=0, pady=5)
def remove_specific_characters(self):
# Create a new Top-level window
remove_characters_window = tk.Toplevel(self)
remove_characters_window.title("Remove specific characters")
remove_characters_frame = ttk.Frame(remove_characters_window)
remove_characters_frame.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)
# Add the options label
options_label = ttk.Label(remove_characters_frame, text="Choose an option:", font=("Helvetica", 14))
options_label.grid(row=0, column=0, pady=10)
# Add the Remove non-breaking spaces (NBSP) button
remove_nbsp_button = ttk.Button(remove_characters_frame, text="1. Remove non-breaking spaces (NBSP)",
command=remove_nbsp)
remove_nbsp_button.grid(row=1, column=0, pady=5)
# Add the Remove custom character button
remove_custom_character_button = ttk.Button(remove_characters_frame, text="2. Remove custom character",
command=remove_custom_character)
remove_custom_character_button.grid(row=2, column=0, pady=5)
# Add the Remove season and episode indicators button
remove_season_episode_indicators_button = ttk.Button(remove_characters_frame,
text="3. Remove season and episode indicators",
command=remove_season_episode_indicators)
remove_season_episode_indicators_button.grid(row=3, column=0, pady=5)
def confirm_exit(self):
answer = messagebox.askyesno("Exit", "Are you sure you want to exit?")
if answer:
self.quit()
if __name__ == "__main__":
app = ScoobyDooCSVToolGUI()
app.mainloop()