-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_tkinter_app.py
271 lines (213 loc) · 10.6 KB
/
my_tkinter_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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import tkinter as tk
import pandas as pd
from tkinter import filedialog, messagebox
# from main import generate_gantt_chart, save_csv, extract_data_from_api
from op_efficiency import process_data_em, plot_employee_efficiency, process_data_op, plot_operation_efficiency
from gantt_chart import process_df, generate_gantt_chart
from idle_time_report import create_summary, generate_mean_chart
from item_efficiency import item_graph_efficiency, save_to_csv
class MyApp:
def __init__(self, root):
self.root = root
self.root.title("Meiban Jobs Data")
# Gantt Chart
self.gantt_button = tk.Button(root, text="Generate Gantt Chart", command=self.upload_gantt_file)
self.gantt_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Latest Job Activity File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
# white space
self.space_label = tk.Label(root, text="", height=1, bg="#0062A8") # Creates an empty label with some height
self.space_label.pack()
# Generate Item Efficiency Chart
self.csv_button = tk.Button(root, text="Generate Item Efficiency Chart",
command=self.upload_item_efficiency_graph_file)
self.csv_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Job Cost File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
# white space
self.space_label = tk.Label(root, text="", height=1, bg="#0062A8") # Creates an empty label with some height
self.space_label.pack()
# Generate Item Efficiency Summary
self.csv_button = tk.Button(root, text="Summarize Item Efficiency",
command=self.save_item_efficiency_csv)
self.csv_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Job Cost File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
# white space
self.space_label = tk.Label(root, text="", height=1, bg="#0062A8") # Creates an empty label with some height
self.space_label.pack()
# Operation & Operator Efficiency
self.upload_button = tk.Button(root, text="Operation & Operator Efficiency", command=self.upload_efficiency_file)
self.upload_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Job Costs File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
# white space
self.space_label = tk.Label(root, text="", height=1, bg="#0062A8") # Creates an empty label with some height
self.space_label.pack()
# Generate mean Idle Time Chart
self.upload_button = tk.Button(root, text="Generate Mean Idle Time Chart", command=self.upload_idle_file_meanChart)
self.upload_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Time Management File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
# white space
self.space_label = tk.Label(root, text="", height=1, bg="#0062A8") # Creates an empty label with some height
self.space_label.pack()
# Summarize Idl Time
self.csv_button = tk.Button(root, text="Summarize Idle Time", command=self.upload_idle_file_summary)
self.csv_button.pack(pady=1)
self.guideline_label = tk.Label(root, text="Please upload the Time Management File", bg="#0062A8",
fg="#cfcfcf")
self.guideline_label.pack(pady=5)
self.loading_screen = None
def show_loading_screen(self):
if not hasattr(self, 'loading_screen') or self.loading_screen is None:
self.loading_screen = tk.Toplevel(self.root)
self.loading_screen.title("Loading...")
self.loading_screen.geometry("200x100")
label = tk.Label(self.loading_screen, text="Processing, please wait...", padx=20, pady=20)
label.pack()
self.root.update_idletasks()
def hide_loading_screen(self):
if hasattr(self, 'loading_screen') and self.loading_screen:
self.loading_screen.destroy()
self.loading_screen = None
print("Loading screen hidden.")
def upload_efficiency_file(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx *.xls"), ("All files", "*.*")]
)
if file_path:
# Read and process the Excel file
df_em = pd.read_excel(file_path, sheet_name='Operator Time')
df_op = pd.read_excel(file_path, sheet_name='Operations')
# Process and plot data
if df_em is not None:
df_em_processed = process_data_em(df_em)
plot_employee_efficiency(df_em_processed)
if df_op is not None:
df_op_processed = process_data_op(df_op)
plot_operation_efficiency(df_op_processed)
except Exception as e:
messagebox.showinfo("Error", f"An error occurred: {str(e)}")
def upload_gantt_file(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx *.xls"), ("All files", "*.*")]
)
if file_path:
# Read and process the Excel file
df_job = pd.read_excel(file_path, sheet_name='Latest Job Activity')
df_op = pd.read_excel(file_path, sheet_name='Open Operations')
# Process and plot data
if df_job is not None and df_op is not None:
df_processed = process_df(df_job,df_op)
generate_gantt_chart(df_processed)
except Exception as e:
messagebox.showinfo("Error", f"An error occurred: {str(e)}")
def upload_item_efficiency_graph_file(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx"), ("All files", "*.*")]
)
if file_path:
# Read and process the Excel file
df_item = pd.read_excel(file_path, sheet_name='Operations')
if df_item is not None:
df_item_processed = item_graph_efficiency(df_item)
item_graph_efficiency(df_item_processed)
except Exception as e:
print(f"An error occurred: {str(e)}")
def save_item_efficiency_csv(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx *.xls"), ("All files", "*.*")])
if file_path:
# Read and process the Excel file
df = pd.read_excel(file_path, sheet_name='Operations')
# Process and plot data
if df is not None:
excel_file_path = filedialog.asksaveasfilename(defaultextension=".xlsx",
filetypes=[("Excel files", "*.xlsx")])
df_processed = save_to_csv(df, excel_file_path)
save_to_csv(df_processed, excel_file_path)
except Exception as e:
messagebox.showinfo("Error", f"An error occurred: {str(e)}")
def upload_idle_file_meanChart(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx *.xls"), ("All files", "*.*")]
)
if file_path:
# Read and process the Excel file
df = pd.read_excel(file_path)
# Process and plot data
if df is not None:
df_processed = generate_mean_chart(df)
generate_mean_chart(df_processed)
except Exception as e:
messagebox.showinfo("Error", f"An error occurred: {str(e)}")
def upload_idle_file_summary(self):
try:
file_path = filedialog.askopenfilename(
filetypes=[("Excel files", "*.xlsx *.xls"), ("All files", "*.*")])
if file_path:
# Read and process the Excel file
df = pd.read_excel(file_path)
# Process and plot data
if df is not None:
excel_file_path = filedialog.asksaveasfilename(defaultextension=".xlsx",
filetypes=[("Excel files", "*.xlsx")])
df_processed = create_summary(df, excel_file_path)
create_summary(df_processed, excel_file_path)
except Exception as e:
messagebox.showinfo("Error", f"An error occurred: {str(e)}")
#def save_csv_file(self):
# csv_file_path = filedialog.asksaveasfilename(defaultextension=".csv",
# filetypes=[("CSV files", "*.csv")])
# if csv_file_path:
# self.show_loading_screen()
# Thread(target=self.process_csv, args=(csv_file_path,)).start()
#def process_csv(self, csv_file_path):
# try:
# save_csv(csv_file_path)
# finally:
# self.hide_loading_screen()
#def show_gantt_chart(self):
# self.show_loading_screen()
# Thread(target=self.process_gantt_chart).start()
#def process_gantt_chart(self):
# try:
# upload_gantt_file()
# finally:
# self.hide_loading_screen()
#def extract_data(self):
# self.show_loading_screen()
# Thread(target=self.process_data_extraction).start()
#def process_data_extraction(self):
# try:
# api_url = "https://api.example.com/data"
# df = extract_data_from_api(api_url)
# print("Data extracted:", df.head())
# finally:
# self.hide_loading_screen()
def setup_and_start_app():
root = tk.Tk()
height = 550
width = 530
x = (root.winfo_screenwidth() // 2) - (width // 2)
y = (root.winfo_screenheight() // 2) - (height // 2)
root.geometry('{}x{}+{}+{}'.format(width, height, x, y))
root.config(background="#0062a8")
welcome_label = tk.Label(text="Meiban Jobs Data", bg="#0062a8", font=("Helvetica", 20, "bold"), fg="#FFFFFF")
welcome_label.pack(pady=20)
root.resizable(width=False, height=False)
app = MyApp(root)
root.mainloop()
if __name__ == "__main__":
setup_and_start_app()