1+ import numpy as np
2+ import customtkinter as ctk
3+
4+ from .tgs_graph import TGS_Plot
5+ from .paramframe import Parameters
6+ from ..functions import pdd , dp
7+ from ..resources .language import Text
8+ from .profile import ProfileHandler
9+ from .scrollframe import ScrollFrame
10+
11+ class TXTMeasurement :
12+ def __init__ (self , path , direction , data ):
13+
14+ self .filename = path .split ("/" )[- 1 ][:- 4 ]
15+ self .direction = direction
16+ self .data = data
17+
18+ self .axis = self .data [:,0 ]
19+ self .dose = self .data [:,1 ]
20+ try : self .std_dev = self .data [:,2 ]
21+ except Exception : self .std_dev = np .array ([0.0 for i in range (len (self .dose ))])
22+
23+ def params (self ):
24+ if self .direction == "Z" :
25+ return pdd .calculate_parameters (
26+ np .array (self .axis ),
27+ self .dose / max (self .dose ),
28+ [],
29+ )
30+ else :
31+ params = dp .calculate_parameters (
32+ self .axis , self .dose / max (self .dose )
33+ )
34+ self .cax = params [1 ]
35+ return params
36+
37+
38+ class TXTImporter (ScrollFrame ):
39+ def __init__ (self , filepath , parent , plotlist , options ):
40+ super ().__init__ (parent = parent )
41+ try : self .data = np .loadtxt (filepath )
42+ except Exception :
43+ self .bell ()
44+ return
45+ self .text = Text ()
46+ self .lang = ProfileHandler ().get_attribute ("language" )
47+ self .plotlist = plotlist
48+ self .path = filepath
49+ self .options = options
50+ self .root = self .options .parent .master .master .parent
51+ self .pack_propagate (False )
52+ self .grid_propagate (False )
53+ self .canvas .pack_propagate (False )
54+ theme = ProfileHandler ().get_attribute ("color_scheme" )
55+ colors2 = {"light" : "#E5E5E5" , "dark" :"#212121" }
56+ colors3 = {"light" : "#DBDBDB" , "dark" :"#2B2B2B" }
57+ self .configure (fg_color = colors2 [theme ])
58+ self .canvas .configure (bg = colors3 [theme ], highlightbackground = colors3 [theme ])
59+ self .scrollbar .configure (fg_color = colors3 [theme ])
60+ self .options .dataframe2 .grid_remove ()
61+ self .options .dataframe1 .grid_remove ()
62+ self .grid (row = 0 , rowspan = 2 , column = 0 , sticky = "nsew" )
63+ self .label = ctk .CTkLabel (self .viewPort , text = Text ().direction [self .lang ], font = ("Bahnschrift" , 14 , "bold" ))
64+ self .label .pack (anchor = "n" , pady = 5 )
65+ directions = ["X" , "Y" , "Z" ]
66+ self .direction = ctk .StringVar ()
67+ self .directions = [ctk .CTkRadioButton (self .viewPort , text = direction , variable = self .direction , value = direction ) for direction in directions ]
68+ [button .pack (anchor = "w" , pady = 5 ) for button in self .directions ]
69+ self .submitbutton = ctk .CTkButton (
70+ self .viewPort ,
71+ text = Text ().submit [ProfileHandler ().get_attribute ("language" )],
72+ command = self .submit ,
73+ )
74+ self .submitbutton .pack (anchor = "s" , pady = 5 )
75+
76+ def submit (self ):
77+
78+ self .plotlist += [TGS_Plot (self .options , TXTMeasurement (self .path , self .direction .get (), self .data ))]
79+ self .options .parameters .append (Parameters (self .options .paramslist .viewPort , self .plotlist [- 1 ], self .lang ))
80+ self .options .parameters [- 1 ].grid (row = len (self .options .parameters )- 1 , sticky = "ew" , padx = 5 , pady = 5 )
81+ self .options .plotbuttons .append (ctk .CTkRadioButton (self .options .graphlist .viewPort , text = self .plotlist [- 1 ].label , variable = self .options .current_plot , text_color = self .plotlist [- 1 ].linecolor , value = self .plotlist [- 1 ].label , command = self .options .change_current_plot , font = ("Bahnschrift" , 14 , "bold" )))
82+ self .options .plotbuttons [- 1 ].grid (sticky = "w" , padx = 5 , pady = 5 )
83+ if len (self .options .parent .plots ) == 1 :
84+ self .options .enable_all_buttons ()
85+ try :
86+ self .options .current_plot .set (self .plotlist [- 1 ].label )
87+ self .options .filenames .append (self .path )
88+ self .options .parent .saved = False
89+ self .options .update_plotlist ()
90+ self .options .parent .update ()
91+ except IndexError :
92+ pass
93+
94+ self .canvas .unbind_all ("<MouseWheel>" )
95+ self .destroy ()
96+ self .options .dataframe1 .grid (row = 1 , column = 0 , sticky = "nsew" , padx = 5 , pady = 5 )
97+ self .options .dataframe2 .grid (row = 0 , column = 0 , sticky = "nsew" , padx = 5 , pady = 5 )
0 commit comments