-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalGUI.py
More file actions
1580 lines (1043 loc) · 53.6 KB
/
Copy pathFinalGUI.py
File metadata and controls
1580 lines (1043 loc) · 53.6 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import io
import tkinter as tk
from tkinter import messagebox,ttk,filedialog
import pandas as pd
import os
import yaml
from PIL import Image, ImageTk
import Improved as im
import traceback
# Logo based on name
# Add more about about info
# Add settings to change x lims
import sys
if sys.platform == "win32":
import win32clipboard
import ctypes
elif sys.platform == "darwin":
import subprocess
class App(tk.Tk): # Basic App blueprint. Tabs with features are added to it
def __init__(self):
super().__init__()
self.report_callback_exception = self.show_error
try:
self.iconbitmap("final_icon.ico")
self.title("Materials Analysis")
style = ttk.Style() #Use to change the style of the tabs
style.configure("Notebook.Tab", padding=[20,0,20,0])
self.notebook = ttk.Notebook()
self.geometry("700x700")
self.minsize(700, 700)
self.notebook.pack(fill="both", expand=True)
material_result=obtain_materials()
if material_result[0]:
pass
else:
messagebox.showerror("Error","Can't find any Excel files")
self.buffer=BufferStorage()
def cause_error():
raise RuntimeError("money!")
# All tabs. Get sent proper materials
# self.simul_tab=SimulationTab(self,self.notebook,material_result[3],self.buffer)
self.ref_tab = RefTab(self,self.notebook,material_result[1],self.buffer)
self.plas_tab = PlasTab(self,self.notebook,material_result[2],self.buffer)
self.ani_tab = AnisTab(self,self.notebook,material_result[2],self.buffer)
self.comp_tab = CompTab(self,self.notebook,material_result[2],self.buffer)
self.frac_tab = FracTab(self,self.notebook,material_result[1],self.buffer)
self.calc_tab = CalcTab(self,self.notebook,material_result[1])
self.mainloop()
except Exception as e:
self.show_error(type(e), e, e.__traceback__)
self.destroy()
def show_error(self, exc_type, exc_value, exc_traceback):
error_message = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
messagebox.showerror("Error", f"An error occurred:\n\n{error_message}")
# Stores photos while shown in the gallery
# Later store data
class BufferStorage:
def __init__(self):
self.photo_buffer = [] # To store photos
self.data_buffer = [] # To store x,y values
def add_photo(self, photo):
self.photo_buffer.append(photo)
def add_data(self, data):
self.data_buffer.append(data)
def get_photos(self):
return self.photo_buffer
def get_data(self):
return self.data_buffer
def clear_photos(self):
self.photo_buffer.clear()
def clear_data(self):
self.data_buffer.clear()
# Misc functions
def address():
return ("Excel_raw","Excel_processed","Excel_modeling")
def obtain_materials():
Excel_raw,Excel_processed,Excel_modeling=address()
materials_raw = [os.path.splitext(f)[0] for f in os.listdir(Excel_raw) if f.endswith((".xlsx", ".xls"))]
materials_processed = [os.path.splitext(f)[0] for f in os.listdir(Excel_processed) if f.endswith((".xlsx", ".xls"))]
materials_modeling = [os.path.splitext(f)[0] for f in os.listdir(Excel_modeling) if f.endswith((".xlsx", ".xls"))]
if not materials_raw or not materials_processed:
return False,materials_raw,materials_processed,materials_modeling
else:
return True,materials_raw,materials_processed,materials_modeling
def validate_input(new_value): #Ensures only numbers can be entered
if new_value == "" or new_value.replace(".", "", 1).isdigit():
return True
return False
def send_to_clipboard(name):
image = Image.open(name)
output = io.BytesIO()
image.convert("RGB").save(output, "BMP") #Take image as rgb buffer
data = output.getvalue()[14:] # Cut Header
output.close()
if sys.platform == "win32": # For winodws
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
win32clipboard.CloseClipboard()
elif sys.platform == "darwin": #Test ON MAC
output = io.BytesIO()
image.save(output, format="PNG")
output.seek(0)
process = subprocess.Popen(
["pbcopy"], stdin=subprocess.PIPE
)
process.communicate(output.getvalue())
## Add linux version
class ImageGrid(tk.Toplevel):
existing_instance = None
def __init__(self, parent, image_buffers):
if ImageGrid.existing_instance is not None: # Ensures only one (latest) window exists
ImageGrid.existing_instance.destroy()
super().__init__(parent)
self.title("Graphs")
self.geometry("1480x1600")
ImageGrid.existing_instance = self
self.canvas = tk.Canvas(self, highlightthickness=0)
self.scrollbar = ttk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.canvas.configure(yscrollcommand=self.scrollbar.set)
self.image_frame = ttk.Frame(self.canvas)
self.canvas.pack(side="left", fill="both", expand=True)
self.scrollbar.pack(side="right", fill="y")
self.canvas.create_window((0, 0), window=self.image_frame, anchor="nw")
self.menubar = tk.Menu(self)
self.config(menu=self.menubar)
self.file_menu = tk.Menu(self.menubar,tearoff=False)
self.file_menu.add_command(
label="Save all",
command=self.saveall,
)
self.menubar.add_cascade(
label="File",
menu=self.file_menu,
underline=0
)
self.images = self.load_images(image_buffers)
self.display_images()
self.image_frame.update_idletasks()
self.canvas.config(scrollregion=self.canvas.bbox("all"))
def cleanup():
image_buffers.clear_photos()
self.destroy()
if ImageGrid.existing_instance == self:
ImageGrid.existing_instance = None
self.protocol("WM_DELETE_WINDOW", cleanup)
def saveall(self):
for img in self.images:
self.save_image(img, True)
def load_images(self, image_buffers):
images = []
tem_image = image_buffers.get_photos()
if tem_image.__len__() >1:
for buffer in tem_image:
img = Image.open(io.BytesIO(buffer))
img = img.resize((180*4, 180*3))
images.append(ImageTk.PhotoImage(img))
else:
img = Image.open(io.BytesIO(tem_image[0]))
img = img.resize((220*4, 220*3))
self.geometry("910x750")
images.append(ImageTk.PhotoImage(img))
return images
def display_images(self):
print(len(self.images))
# For single graph
if len(self.images) == 1:
img=self.images[0]
container = ttk.Frame(self.image_frame)
container.pack(side="top")
label = tk.Label(container, image=img)
label.pack()
button_container = ttk.Frame(container)
button_container.pack(pady=5,anchor="e")
label.image = img
save_button = ttk.Button(button_container, text="Save As ", command=lambda img=img: self.save_image(img))
save_button.pack(padx=5,side="left")
save_as_button = ttk.Button(button_container, text="Save Image", command=lambda img=img: self.save_image(img,True))
save_as_button.pack(padx=5,side="left")
copy_button = ttk.Button(button_container, text="Copy",command=lambda img=img:self.save_image(img,True,True))
copy_button.pack(padx=5,side="left")
else:
for i, img in enumerate(self.images):
container = ttk.Frame(self.image_frame)
container.grid(row=i // 2, column=i % 2, pady=10, sticky="nsew")
label = tk.Label(container, image=img)
label.pack()
button_container = ttk.Frame(container)
button_container.pack(pady=5,anchor="center")
label.image = img # Keep a reference to avoid garbage collection
save_button = ttk.Button(button_container, text="Save As ", command=lambda img=img: self.save_image(img))
save_button.pack(padx=5,side="left")
save_as_button = ttk.Button(button_container, text="Save Image", command=lambda img=img: self.save_image(img,True))
save_as_button.pack(side="left",padx=5)
copy_button = ttk.Button(button_container, text="Copy",command=lambda img=img: self.save_image(img,True,True))
copy_button.pack(padx=5,side="left")
def save_image(self, img,location=False,clipboard=False):
if location:
if not os.path.exists("Saved"):
os.makedirs("Saved", exist_ok=True)
save_path = f"Saved{os.sep}Graph.png"
base, ext = os.path.splitext(save_path)
counter = 1
while os.path.exists(save_path):
save_path = f"{base}_{counter}{ext}"
counter += 1
img._PhotoImage__photo.write(save_path)
if clipboard:
send_to_clipboard(save_path)
os.remove(save_path)
else:
file_path = filedialog.asksaveasfilename(defaultextension=".png",
filetypes=[("PNG files", "*.png"),
("JPEG files", "*.jpg"),
("All files", "*.*")])
if file_path:
img._PhotoImage__photo.write(file_path)
class Settings(tk.Toplevel):
def __init__(self, parent):
super().__init__(parent)
self.title("Settings")
self.geometry("500x700")
self.iconbitmap("final_icon.ico")
notebook = ttk.Notebook(self)
settings_tab = ttk.Frame(notebook)
about_tab = ttk.Frame(notebook)
notebook.add(settings_tab, text="Settings")
notebook.add(about_tab, text="About")
notebook.pack(expand=True, fill="both")
# Variables
self.validate_numeric = self.register(validate_input)
self.font_family_var = tk.StringVar()
self.font_size_var = tk.DoubleVar()
self.axes_labelsize_var = tk.DoubleVar()
self.axes_titlesize_var = tk.DoubleVar()
self.legend_on_var = tk.BooleanVar()
self.legend_fontsize_var = tk.DoubleVar()
self.normalize_var = tk.BooleanVar()
self.xlim_min_var = tk.DoubleVar()
self.xlim_max_var = tk.DoubleVar()
self.ylim_min_var = tk.DoubleVar()
self.ylim_max_var = tk.DoubleVar()
self.xlim_enabled_var = tk.BooleanVar()
self.ylim_enabled_var = tk.BooleanVar()
# Load settings from YAML
with open("config.yaml", "r") as file:
self.settings = yaml.safe_load(file)
# Set initial values
self.font_family_var.set(
self.settings.get("matplotlib", {}).get("font", {}).get("family", "Arial"))
self.font_size_var.set(
str(self.settings.get("matplotlib", {}).get("font", {}).get("size", 12)))
self.axes_labelsize_var.set(
str(self.settings.get("matplotlib", {}).get("axes", {}).get("labelsize", 10)))
self.axes_titlesize_var.set(
str(self.settings.get("matplotlib", {}).get("axes", {}).get("titlesize", 12)))
self.legend_on_var.set(
self.settings.get("matplotlib", {}).get("legend", {}).get("on", False))
self.legend_fontsize_var.set(
str(self.settings.get("matplotlib", {}).get("legend", {}).get("fontsize", 10)))
self.normalize_var.set(
self.settings.get("misc", {}).get("normalized", False))
self.xlim_enabled_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("xlim_enabled", False))
self.ylim_enabled_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("ylim_enabled", False))
self.xlim_min_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("xlim", [0, 1])[0])
self.xlim_max_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("xlim", [0, 1])[1])
self.ylim_min_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("ylim", [0, 1])[0])
self.ylim_max_var.set(
self.settings.get("matplotlib", {}).get("limits", {}).get("ylim", [0, 1])[1])
# Settings Layout
label_frame = ttk.Frame(settings_tab)
label_frame.pack(side='left',anchor='n', pady=7)
option_frame = ttk.Frame(settings_tab)
option_frame.pack(side='left',anchor='n', pady=7)
ttk.Label(label_frame, text="Font Family:").pack(padx=10, pady=5, anchor='n')
font_families = ["Arial", "Times New Roman", "Cursive", "Comic Sans"]
ttk.Combobox(option_frame, textvariable=self.font_family_var,
values=font_families, state="readonly").pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Font Size:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.font_size_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Axes Label Size:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.axes_labelsize_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Legend On:").pack(padx=10, pady=5, anchor='n')
ttk.Checkbutton(option_frame, variable=self.legend_on_var).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Legend Font Size:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.legend_fontsize_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Normalization:").pack(padx=10, pady=5, anchor='n')
ttk.Checkbutton(option_frame, variable=self.normalize_var).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="X Lim Min:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.xlim_min_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="X Lim Max:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.xlim_max_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Enable X Lim:").pack(padx=10, pady=5, anchor='n')
ttk.Checkbutton(option_frame, variable=self.xlim_enabled_var).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Y Lim Min:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.ylim_min_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Y Lim Max:").pack(padx=10, pady=5, anchor='n')
ttk.Entry(option_frame, textvariable=self.ylim_max_var,
validate="key", validatecommand=(self.validate_numeric, "%P")).pack(padx=10, pady=5, anchor='n')
ttk.Label(label_frame, text="Enable Y Lim:").pack(padx=10, pady=5, anchor='n')
ttk.Checkbutton(option_frame, variable=self.ylim_enabled_var).pack(padx=10, pady=5, anchor='n')
for var in self.__dict__.values():
if isinstance(var, (tk.StringVar, tk.DoubleVar)):
var.trace_add("write", self.check_entries)
# About Layout
title_frame=ttk.Frame(about_tab)
icon= Image.open("final_icon.ico")
photo = ImageTk.PhotoImage(icon.resize((80, 80)))
label = ttk.Label(title_frame, image=photo)
label.image = photo
label.grid(row=0, column=0,sticky="w")
ttk.Label(title_frame, text="MA-DAPT:\nMaterial Design, Analysis,\nProcessing, and Testing\n\n ", font=("TkDefaultFont", 11, "bold")).grid(row=0,column=1,sticky="w",padx=34)
title_frame.pack(padx=10,pady=10,anchor="w")
ttk.Label(about_tab, text="Version: 0.45", font=("TkDefaultFont", 11)).pack(pady=5,padx=5,anchor="w")
creation = """ Created by Guijia Li and Saad Zia
Developed as part of the Aalto University Materials
to Products Department, led by Lian junhe."""
ttk.Label(about_tab, text=creation).pack(pady=10,anchor="w")
ttk.Label(about_tab, text="License: MIT License", font=("TkDefaultFont", 11, "bold")).pack(pady=10,padx=5,anchor="w")
ttk.Label(about_tab, text="This software is open-source and provided 'as-is'\nwithout warranty of any kind, express or implied.").pack(pady=10)
#Save Button
self.save_button = ttk.Button(label_frame, text="Save", command=self.save_settings, state="enabled")
self.save_button.pack()
def save_settings(self):
"""Save the updated settings to the YAML file."""
self.settings["matplotlib"]["font"]["family"] = self.font_family_var.get()
self.settings["matplotlib"]["font"]["size"] = int(self.font_size_var.get())
self.settings["matplotlib"]["axes"]["labelsize"] = int(self.axes_labelsize_var.get())
self.settings["matplotlib"]["legend"]["on"] = self.legend_on_var.get()
self.settings["matplotlib"]["legend"]["fontsize"] = int(self.legend_fontsize_var.get())
self.settings["misc"]["normalized"] = self.normalize_var.get()
self.settings["matplotlib"]["limits"]["xlim_enabled"] = self.xlim_enabled_var.get()
self.settings["matplotlib"]["limits"]["ylim_enabled"] = self.ylim_enabled_var.get()
self.settings["matplotlib"]["limits"]["xlim"] = [self.xlim_min_var.get(), self.xlim_max_var.get()]
self.settings["matplotlib"]["limits"]["ylim"] = [self.ylim_min_var.get(), self.ylim_max_var.get()]
self.save_yaml(self.settings)
print("Settings saved successfully!")
def save_yaml(self, data):
"""Save data to the YAML file."""
with open("config.yaml", "w") as file:
yaml.safe_dump(data, file)
def check_entries(self, *args):
for var in self.__dict__.values():
if isinstance(var, (tk.StringVar, tk.DoubleVar)):
try:
value = str(var.get()).strip()
print(value)
if value == "" or value == ".":
self.save_button.config(state="disabled")
return
except (ValueError, tk.TclError):
self.save_button.config(state="disabled")
return
self.save_button.config(state="normal")
# Calculation Tab
class CalcTab(ttk.Frame):
def __init__(self,parent, notebook,materials):
super().__init__(parent)
notebook.add(self, text="Calculation")
#Enables buttons
def validate():
if self.selected_calc_mat.get() != "" and entry.get() != "":
calculate_button.config(state=tk.NORMAL)
modified_button.config(state=tk.NORMAL)
else:
calculate_button.config(state=tk.DISABLED)
modified_button.config(state=tk.DISABLED)
canvas=tk.Canvas(self,scrollregion=(0,0,0,len(materials)*52),width=10,highlightthickness=0)
canvas.pack(side="left",expand=True,fill="both")
# For scrolling
left_frame=ttk.Frame(canvas)
canvas.create_window((30,100), window=left_frame, anchor="nw")
mat_title = ttk.Label(canvas, text="Materials", font=("Arial", 15))
mat_title.pack(pady=20,anchor="nw",padx=37)
self.selected_calc_mat = tk.StringVar(value="")
for material in (materials):
radio = ttk.Radiobutton(left_frame,
text=material,
value=material,
variable=self.selected_calc_mat,
command=validate)
radio.pack(anchor="w",pady=3)
settings_button = ttk.Button(left_frame, text="Settings", command=lambda:Settings(self))
settings_button.pack(pady=30)
"""Right frame"""
right_frame=ttk.Frame(self)
right_frame.pack(side="left",padx=20,anchor="s")
top_right_frame=ttk.Frame(right_frame)
top_right_frame.pack(pady=200)
mat_title = ttk.Label(top_right_frame, text="Enter critical stress:",)
mat_title.pack(anchor="s")
validate_cmd = top_right_frame.register(validate_input)
entry = ttk.Entry(top_right_frame, validate="key", validatecommand=(validate_cmd, "%P"))
entry.pack(pady=10,side="top")
entry.bind("<KeyRelease>", lambda event: validate())
"""Bottom right frame"""
bottom_right_frame=ttk.Frame(right_frame)
bottom_right_frame.pack(pady=20,padx=20)
calculate_button = ttk.Button(bottom_right_frame, text="Calculate",state=tk.DISABLED,command= lambda :calculate(False,int(entry.get())))
calculate_button.pack(side="left")
modified_button = ttk.Button(bottom_right_frame, text="Modified",state=tk.DISABLED,command= lambda :calculate(True,int(entry.get())))
modified_button.pack(padx=10 ,side="left")
scrollbar=ttk.Scrollbar(self,orient="vertical",command=canvas.yview)
scrollbar.pack(side="right", fill="y")
canvas.configure(yscrollcommand=scrollbar.set)
def calculate(modification,critical_stress:int):
Excel_raw =address()[0]
path = f"{Excel_raw}{os.sep}{self.selected_calc_mat.get()}.xlsx"
search_string = "SDB"
excel_file = pd.ExcelFile(path, engine="openpyxl")
matching_sheets = [sheet for sheet in excel_file.sheet_names if search_string in sheet]
if modification:
for sheet_name in matching_sheets:
print("sheet_name")
im.calculation(path, sheet_name, critical_stress,True)
else:
for sheet_name in matching_sheets:
im.calculation(path, sheet_name, critical_stress)
return
class PlasTab(ttk.Frame):
def __init__(self,parent, notebook,materials,buffer):
super().__init__(parent)
Excel_processed=address()[1]
notebook.add(self, text="Plasticity")
mat_title = ttk.Label(self, text="Materials", font=("Arial", 15))
mat_title.pack(pady=20,anchor="nw",padx=37)
canvas=tk.Canvas(self,
scrollregion=(0,0,0,len(materials)*45),
width=10,
highlightthickness=0)
canvas.pack(side="left",expand=True,fill="both")
def validate():
if self.selected_mat.get():
if any(var.get() for var in self.property_vars.values()):
repeat_button.config(state=tk.NORMAL)
custom_plot_button.config(state=tk.NORMAL)
summary_button.config(state=tk.NORMAL)
else:
repeat_button.config(state=tk.DISABLED)
custom_plot_button.config(state=tk.DISABLED)
summary_button.config(state=tk.DISABLED)
uts_button.config(state=tk.NORMAL)
yts_button.config(state=tk.NORMAL)
R_button.config(state=tk.NORMAL)
else:
repeat_button.config(state=tk.DISABLED)
custom_plot_button.config(state=tk.DISABLED)
uts_button.config(state=tk.DISABLED)
yts_button.config(state=tk.DISABLED)
R_button.config(state=tk.DISABLED)
summary_button.config(state=tk.DISABLED)
left_frame=ttk.Frame(canvas)
canvas.create_window((20,20), window=left_frame, anchor="nw")
self.selected_mat = tk.StringVar(value="")
for material in (materials):
radio = ttk.Radiobutton(left_frame,
text=material,
value=material,
variable=self.selected_mat
,command=validate)
radio.pack(anchor="sw",pady=3)
settings_button = ttk.Button(left_frame, text="Settings", command=lambda:Settings(self))
settings_button.pack(pady=30)
"""Middle Frame"""
properties_frame=ttk.Frame(self)
properties_frame.pack(side="left",padx=15,expand=True,anchor="n")
prop_title = ttk.Label(properties_frame, text="Graphs", font=("Arial", 15))
prop_title.pack(pady=20)
prop_separator = ttk.Separator(properties_frame, orient="horizontal")
prop_separator.pack(pady=1)
properties = ["engineering", "true", "effective plastic strain","r-value"]
self.property_vars = {}
for prop in (properties):
var = tk.BooleanVar(value=False)
chk = ttk.Checkbutton(properties_frame, text=prop, variable=var,command=validate)
self.property_vars[prop] = var
chk.pack(anchor="sw", pady=2)
prop_separator = ttk.Separator(properties_frame, orient="horizontal")
prop_separator.pack(pady=1)
def repeatablity_caller():
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
selected = [prop for prop, var in self.property_vars.items() if var.get()]
for p in selected:
bufs=im.repeatablity(path,"Sheet1",p)
for b in bufs:
buffer.add_photo(b.getvalue())
#buffer.add_photo(im.repeatablity(path,"Sheet1",p))
ImageGrid(self,buffer) # type: ignore
def size_effect():
selected_indices = [idx for idx, var in self.property_vars.items() if var.get()]
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
selected = [prop for prop, var in self.property_vars.items() if var.get()]
data_frame=pd.read_excel(path,sheet_name="Sheet1",header=([0,1,2]))
tests_list = data_frame.columns.get_level_values(0).unique().tolist()
# create a new window
new_window = tk.Toplevel(self)
new_window.title("Select test number")
# build a frame to display checkboxes
check_frame = ttk.Frame(new_window)
check_frame.pack (pady=10)
#generate a list of checkboxes with all tests list in the processed excel.
selected_tests = {}
for idx, prop in enumerate(tests_list):
var = tk.BooleanVar(value=False)
chk = ttk.Checkbutton(check_frame, text=prop, variable=var)
chk.grid(row=idx+1, column=1, sticky="w")
selected_tests[prop] = var
def on_confirm():
selected_options = [opt for opt, var in selected_tests.items() if var.get()]
print((path, selected_options,selected_indices[0]))
for opts in selected:
buffer.add_photo(im.custom_plot(path, selected_options,opts))
ImageGrid(self,buffer) # type: ignore
confirm_button = ttk.Button(new_window, text="Confirm", command=on_confirm)
confirm_button.pack(pady=10)
def summary(letters=False):
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
selected = [prop for prop, var in self.property_vars.items() if var.get()]
for p in selected:
buffer.add_photo(im.summary(path,"Sheet1",p,letters) )
ImageGrid(self,buffer)
def uts():
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
buffer.add_photo(im.uts_plot(path,"Sheet1"))
ImageGrid(self,buffer)
def yts():
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
buffer.add_photo(im.yield_stress_plot(path,"Sheet1"))
ImageGrid(self,buffer)
def yieldr():
path = f"{Excel_processed}{os.sep}{self.selected_mat.get()}.xlsx"
buffer.add_photo(im.yield_stress_plot(path,"Sheet1",True))
ImageGrid(self,buffer)
button_frame = ttk.Frame(properties_frame)
button_frame.pack(pady=5)
repeat_button = ttk.Button(button_frame, text="Repeat", state=tk.DISABLED, command=repeatablity_caller)
repeat_button.grid(row=0, column=0, padx=5, pady=5)
custom_plot_button = ttk.Button(button_frame, text="Custom Plot", command=size_effect, state=tk.DISABLED)
custom_plot_button.grid(row=0, column=1, padx=5, pady=5)
short_var = tk.BooleanVar(value=False)
short_check=ttk.Checkbutton(button_frame,text="DD,RD,TD",variable=short_var)
summary_button=ttk.Button(button_frame,text="Summary",state=tk.DISABLED,command=lambda :summary(short_var.get()))
short_check.grid(row=1,column=0, padx=5, pady=5)
summary_button.grid(row=1,column=1, padx=5, pady=5)
uts_button=ttk.Button(button_frame, text="UTS", command=uts,state=tk.DISABLED)
uts_button.grid(row=2,column=0, padx=5, pady=5)
yts_button=ttk.Button(button_frame, text="YTS", command=yts,state=tk.DISABLED)
yts_button.grid(row=2,column=1, padx=5, pady=5)
R_button=ttk.Button(button_frame, text="R values", command=yieldr,state=tk.DISABLED)
R_button.grid(row=3,column=0, padx=5, pady=5,columnspan=2)
scrollbar=ttk.Scrollbar(self,orient="vertical",command=canvas.yview)
scrollbar.pack(side="right", fill="y")
canvas.configure(yscrollcommand=scrollbar.set)
class FracTab(ttk.Frame):
def __init__(self, parent,notebook,materials,buffer):
super().__init__(parent)
notebook.add(self, text="Fracture")
self.material_vars = {}
canvas=tk.Canvas(self,scrollregion=(0,0,0,len(materials)*52),width=10,highlightthickness=0)
canvas.pack(side="left",expand=True,fill="both")
"""Left frame"""
left_frame=ttk.Frame(canvas)
canvas.create_window((20,100), window=left_frame, anchor="nw")
mat_title = ttk.Label(canvas, text="Materials", font=("Arial", 15))
mat_title.pack(pady=20,anchor="nw",padx=37)
self.selected_calc_mat = tk.StringVar(value="")
right_frame=ttk.Frame(self)
right_frame.pack(side="left")
self.selected_calc_mat = tk.StringVar(value="")
def frac_calculate(path,var):
for header in var:
bufs=(im.fracture_repeat(path, header))
for b in bufs:
buffer.add_photo(b.getvalue())
ImageGrid(self,buffer)
def frac_summary(path,var):
for header in var:
buffer.add_photo(im.fracture_summary(path, header).getvalue())
ImageGrid(self,buffer)
def frac_summary_multiple(path,var):
buffer.add_photo(im.fracture_compare_summary(path, var).getvalue())
ImageGrid(self,buffer)
def frac_one_name(path,var):
print("cake",var)
ans=im.fracture_normal_compare(path, var)
for i in ans:
buffer.add_photo(i.getvalue())
ImageGrid(self,buffer)
def frac_repeat(): #Add list for every selected matertial
for widget in right_frame.winfo_children():
widget.pack_forget()
Excel_raw=address()[0]
print(self.selected_calc_mat.get())
path = f"{Excel_raw}{os.sep}{self.selected_calc_mat.get()}.xlsx"
all_sheets = pd.ExcelFile(path).sheet_names
# filtered_sheets = [sheet for sheet in all_sheets if "SDB" not in sheet and "Tests" not in sheet]
filtered_sheets = [sheet for sheet in all_sheets if "Tests" not in sheet]
sheet_list = list(filtered_sheets)
self.checkbox_vars = {}
for header in sheet_list:
var = tk.BooleanVar(value=False)
checkbox = ttk.Checkbutton(right_frame, text=header, variable=var)
self.checkbox_vars[header] = var
checkbox.pack(anchor="center", pady=2,padx=50)
def get_selected(): # Collect the ticked boxses
selected = [header for header, var in self.checkbox_vars.items() if var.get()]
return selected
def frac_compare(path,var):
compare_materials=[]
for material in materials:
path = f"{Excel_raw}{os.sep}{material}.xlsx"
all_sheets = pd.ExcelFile(path).sheet_names
filtered_sheets = [sheet for sheet in all_sheets if "SDB" not in sheet and "Tests" not in sheet]
sheet_list = list(filtered_sheets)
if (all(item in sheet_list for item in get_selected())):
compare_materials.append(material)
compare_materials.remove((self.selected_calc_mat.get()))
print(compare_materials)
window = tk.Toplevel()
window.title("Select Other Materials")
self.bvars = {}
for material in compare_materials:
bvar = tk.BooleanVar(value=False)
chk = ttk.Checkbutton(window, text=material, variable=bvar, onvalue=True, offvalue=False)
self.bvars[material]=bvar
#chk.pack(anchor='w')
chk.pack(anchor="w")
def get_selected_checks():
selected = [header for header, var in self.bvars.items() if var.get()]
selected.append(self.selected_calc_mat.get())
return selected
btn = ttk.Button(window, text="OK", command=lambda:frac_compare_caller(var,get_selected_checks()))
btn.pack()
def frac_compare_caller(var,materials):
print(materials)
bufs=[]
for header in var:
bufs.append(im.fracture_compare(path, header,materials))
for b in bufs:
buffer.add_photo(b)
ImageGrid(self,buffer)
def force_displacement(path,quality):
buffer.add_photo(im.Normalized_plot(path,quality))
ImageGrid(self,buffer)
button_frame = ttk.Frame(right_frame) # Give better names
button_frame.pack(padx=50, pady=5)
confirm_button = ttk.Button(button_frame, text="Confirm", command=lambda: frac_calculate(path, get_selected()))
compare_button = ttk.Button(button_frame, text="Compare", command=lambda: frac_compare(path, get_selected()))
summary_button = ttk.Button(button_frame, text="Summary", command=lambda: frac_summary(path, get_selected()))
summary_button_compare = ttk.Button(button_frame, text="Diection Comp", command=lambda: frac_summary_multiple(path, get_selected()))
confirm_compare_button = ttk.Button(button_frame, text="ForceComp", command=lambda: frac_one_name(path, get_selected()))
force_direction_button = ttk.Button(button_frame, text="Force/Dir", command=lambda: force_displacement(path, "Force"))
displacement_direction_button = ttk.Button(button_frame, text="Displacement/Dir", command=lambda: force_displacement(path, "Displacement"))
confirm_button.grid(row=0, column=0, padx=5, pady=5)
compare_button.grid(row=3, column=0, columnspan=2, padx=5, pady=5)
summary_button.grid(row=0, column=1, padx=5, pady=5)
summary_button_compare.grid(row=1, column=1, padx=5, pady=5)
confirm_compare_button.grid(row=1, column=0, padx=5, pady=5)
force_direction_button.grid(row=2, column=1, padx=5, pady=5)
displacement_direction_button.grid(row=2, column=0, padx=5, pady=5)
for material in (materials): #Add materials
radio = ttk.Radiobutton(left_frame, text=material, value=material, variable=self.selected_calc_mat, command=frac_repeat)
radio.pack(anchor="w")
settings_button = ttk.Button(left_frame, text="Settings", command=lambda:Settings(self))
settings_button.pack(pady=30)
scrollbar=ttk.Scrollbar(self,orient="vertical",command=canvas.yview)
scrollbar.pack(side="right", fill="y")
canvas.configure(yscrollcommand=scrollbar.set)