2828
2929# from vuegen.__main__ import main
3030from vuegen .report import ReportType
31+ from vuegen .utils import get_logger
3132
3233customtkinter .set_appearance_mode ("system" )
3334customtkinter .set_default_color_theme ("dark-blue" )
34- from tkinter import filedialog
35+ import traceback
36+ from tkinter import filedialog , messagebox
3537
3638from vuegen import report_generator
3739from vuegen .utils import print_completion_message
3840
39- app_path = Path (__file__ ).absolute ()
41+ app_path = Path (__file__ ).absolute (). resolve ()
4042print ("app_path:" , app_path )
43+ output_dir = (Path .home () / "vuegen_gen" / "reports" ).resolve ()
44+ print ("output_dir:" , output_dir )
45+ output_dir .mkdir (exist_ok = True , parents = True )
4146
4247##########################################################################################
4348# Path to example data dependend on how the GUI is run
8287# return inner
8388
8489
85- def create_run_vuegen (is_dir , config_path , report_type , run_streamlit ):
90+ def create_run_vuegen (
91+ is_dir , config_path , report_type , run_streamlit , output_dir_entry
92+ ):
8693 def inner ():
8794 kwargs = {}
8895 print (f"{ is_dir .get () = } " )
8996 if is_dir .get ():
9097 kwargs ["dir_path" ] = config_path .get ()
98+ report_name = Path (config_path .get ()).stem
9199 else :
92100 kwargs ["config_path" ] = config_path .get ()
101+ report_name = Path (config_path .get ()).stem
93102 kwargs ["report_type" ] = report_type .get ()
94103 print (f"{ run_streamlit .get () = } " )
95104 kwargs ["streamlit_autorun" ] = run_streamlit .get ()
105+ kwargs ["output_dir" ] = output_dir_entry .get ()
96106 print ("kwargs:" )
97107 pprint (kwargs )
98- report_generator .get_report (** kwargs )
108+ try :
109+ # Define logger suffix based on report type and name
110+ logger_suffix = f"{ report_type .get ()} _report_{ str (report_name )} "
111+
112+ # Initialize logger
113+ kwargs ["logger" ], log_file = get_logger (
114+ f"{ logger_suffix } " ,
115+ folder = (Path (kwargs ["output_dir" ]) / "logs" ).as_posix (),
116+ )
117+ report_generator .get_report (** kwargs )
118+ messagebox .showinfo (
119+ "Success" ,
120+ "Report generation completed successfully." f"\n Logs at { log_file } " ,
121+ )
122+ except Exception as e :
123+ stacktrace = traceback .format_exc ()
124+ messagebox .showerror (
125+ "Error" ,
126+ f"An error occurred: { e } \n \n { stacktrace } "
127+ f"\n See logs for more details { log_file } " ,
128+ )
99129 print_completion_message (report_type .get ())
100130
101131 return inner
@@ -115,7 +145,7 @@ def radio_button_callback():
115145
116146def create_select_directory (string_var ):
117147 def select_directory ():
118- directory = filedialog .askdirectory ()
148+ directory = filedialog .askdirectory (initialdir = string_var . get () )
119149 string_var .set (directory )
120150
121151 return select_directory
@@ -124,7 +154,7 @@ def select_directory():
124154##########################################################################################
125155# APP
126156app = customtkinter .CTk ()
127- app .geometry ("600x400 " )
157+ app .geometry ("620x500 " )
128158app .title ("VueGen GUI" )
129159
130160##########################################################################################
@@ -207,15 +237,39 @@ def select_directory():
207237)
208238ctk_radio_st_autorun_0 .grid (row = 5 , column = 1 , padx = 20 , pady = 20 )
209239
240+ ##########################################################################################
241+ # output directory selection
242+ # ctk_label_outdir = customtkinter.CTkLabel
243+ output_dir_entry = tk .StringVar (value = str (output_dir ))
244+ select_output_dir = create_select_directory (output_dir_entry )
245+ select_output_dir_button = customtkinter .CTkButton (
246+ app , text = "Select Output Directory" , command = select_output_dir
247+ )
248+ select_output_dir_button .grid (row = 6 , column = 2 , columnspan = 2 , padx = 5 , pady = 10 )
249+
250+ ctk_entry_outpath = customtkinter .CTkEntry (
251+ app ,
252+ width = 400 ,
253+ textvariable = output_dir_entry ,
254+ )
255+ ctk_entry_outpath .grid (row = 6 , column = 0 , columnspan = 2 , padx = 10 , pady = 10 )
256+ ctk_label_appath = customtkinter .CTkLabel (
257+ app ,
258+ text = f"App path: { app_path } " ,
259+ )
260+ ctk_label_appath .grid (row = 7 , column = 0 , columnspan = 2 , padx = 20 , pady = 5 )
261+
210262##########################################################################################
211263# Run VueGen button
212- run_vuegen = create_run_vuegen (is_dir , config_path , report_type , run_streamlit )
264+ run_vuegen = create_run_vuegen (
265+ is_dir , config_path , report_type , run_streamlit , output_dir_entry
266+ )
213267run_button = customtkinter .CTkButton (
214268 app ,
215269 text = "Run VueGen" ,
216270 command = run_vuegen ,
217271)
218- run_button .grid (row = 6 , column = 0 , columnspan = 2 , padx = 20 , pady = 20 )
272+ run_button .grid (row = 8 , column = 0 , columnspan = 2 , padx = 20 , pady = 20 )
219273
220274##########################################################################################
221275# Run the app in the mainloop
0 commit comments