2222# SOFTWARE.
2323
2424from pathlib import Path
25+ import tkinter as tk
26+ from tkinter .font import Font
2527
2628import ansys .aedt .core
2729from ansys .aedt .core .generic .design_types import get_pyaedt_app
4951extension_description = "Transformer loss distribution"
5052
5153
54+ def _text_size (path , entry ): # pragma: no cover
55+ # Calculate the length of the text
56+ text_length = len (path )
57+
58+ # Adjust font size based on text length
59+ if text_length < 20 :
60+ font_size = 20
61+ elif text_length < 50 :
62+ font_size = 15
63+ else :
64+ font_size = 10
65+
66+ # Set the font size
67+ text_font = Font (size = font_size )
68+ entry .configure (font = text_font )
69+
70+ # Adjust the width of the Text widget based on text length
71+ entry .configure (width = max (20 , text_length // 2 ))
72+
73+ entry .insert (tk .END , path )
74+
75+
5276def frontend (): # pragma: no cover
53- import tkinter as tk
5477 from tkinter import filedialog
5578 from tkinter import messagebox
5679 import tkinter .ttk as ttk
@@ -278,8 +301,7 @@ def callback(button_id):
278301 elif button_id == 2 :
279302 master .flag = False
280303 setup_name = master .solution_option .split (":" )[0 ].strip ()
281- is_solved = [s .is_solved for s in maxwell .setups if s .name == setup_name ][0 ]
282- if not is_solved :
304+ if maxwell .get_setup (setup_name ) and not maxwell .get_setup (setup_name ).is_solved :
283305 messagebox .showerror ("Error" , "Selected setup is not solved." )
284306 return None
285307
@@ -309,9 +331,40 @@ def browse_files():
309331 master .file_path = sample_points_entry .get ("1.0" , tk .END ).strip ()
310332 # master.destroy()
311333
334+ def show_popup ():
335+ popup = tk .Toplevel (master )
336+ popup .title ("Select an Option" )
337+
338+ tk .Label (popup , text = "Choose an option:" ).pack (pady = 10 )
339+
340+ option_var = tk .StringVar (value = "Option 1" )
341+
342+ tk .Radiobutton (popup , text = "Generate mesh grid" , variable = option_var , value = "Option 1" ).pack (anchor = tk .W )
343+ number_points_label = tk .Label (popup , text = "Number of Points:" )
344+ number_points_label .pack (anchor = tk .W , pady = 5 , padx = 20 )
345+ points_entry = tk .Text (popup , wrap = tk .WORD , width = 20 , height = 1 )
346+ points_entry .pack (pady = 5 , padx = 20 )
347+ tk .Radiobutton (popup , text = "Import .pts file" , variable = option_var , value = "Option 2" ).pack (anchor = tk .W )
348+
349+ def submit ():
350+ if option_var .get () == "Option 1" :
351+ from ansys .aedt .core .workflows .project .points_cloud import main as points_main
352+
353+ selected_objects = objects_list_lb .curselection ()
354+ master .objects_list = [objects_list_lb .get (i ) for i in selected_objects ]
355+ points = points_entry .get ("1.0" , tk .END ).strip ()
356+ pts_path = points_main ({"is_test" : False , "choice" : master .objects_list , "points" : int (points )})
357+
358+ _text_size (pts_path , sample_points_entry )
359+ else :
360+ browse_files ()
361+ popup .destroy ()
362+
363+ tk .Button (popup , text = "OK" , command = submit ).pack (pady = 10 )
364+
312365 # Export points file button
313366 export_points_button = ttk .Button (
314- sample_points_frame , text = "..." , command = browse_files , width = 10 , style = "PyAEDT.TButton"
367+ sample_points_frame , text = "..." , command = show_popup , width = 10 , style = "PyAEDT.TButton"
315368 )
316369 export_points_button .pack (side = tk .RIGHT , padx = 10 )
317370
@@ -326,7 +379,7 @@ def save_as_files():
326379 ("Numpy array" , ".npy" ),
327380 ],
328381 )
329- export_file_entry . insert ( tk . END , filename )
382+ _text_size ( filename , export_file_entry )
330383 master .file_path = export_file_entry .get ("1.0" , tk .END ).strip ()
331384 # master.destroy()
332385
0 commit comments