1919 report generation.
2020"""
2121
22+ import os
2223import sys
2324import tkinter as tk
2425from pathlib import Path
4344output_dir = (Path .home () / "vuegen_gen" / "reports" ).resolve ()
4445print ("output_dir:" , output_dir )
4546output_dir .mkdir (exist_ok = True , parents = True )
46-
47+ _PATH = f' { os . environ [ "PATH" ] } '
4748##########################################################################################
4849# Path to example data dependend on how the GUI is run
4950if getattr (sys , "frozen" , False ) and hasattr (sys , "_MEIPASS" ):
5051 # PyInstaller bundeled case
5152 path_to_dat = (
5253 app_path .parent / "example_data/Basic_example_vuegen_demo_notebook"
5354 ).resolve ()
55+ quarto_bin_path = os .path .join (sys ._MEIPASS , "quarto_cli" , "bin" )
56+ quarto_share_path = os .path .join (sys ._MEIPASS , "quarto_cli" , "share" )
57+ _PATH = os .pathsep .join ([quarto_bin_path , quarto_share_path , _PATH ])
58+ os .environ ["PATH" ] = _PATH
5459elif app_path .parent .name == "gui" :
5560 # should be always the case for GUI run from command line
5661 path_to_dat = (
6368else :
6469 path_to_dat = "docs/example_data/Basic_example_vuegen_demo_notebook"
6570
66-
71+ print ( f" { _PATH = } " )
6772##########################################################################################
6873# callbacks
74+ # using main entry point of vuegen
6975# def create_run_vuegen(is_dir, config_path, report_type, run_streamlit):
7076# def inner():
7177# args = ["vuegen"]
8894
8995
9096def create_run_vuegen (
91- is_dir , config_path , report_type , run_streamlit , output_dir_entry
97+ is_dir , config_path , report_type , run_streamlit , output_dir_entry , python_dir_entry
9298):
9399 def inner ():
94100 kwargs = {}
@@ -105,7 +111,21 @@ def inner():
105111 kwargs ["output_dir" ] = output_dir_entry .get ()
106112 print ("kwargs:" )
107113 pprint (kwargs )
114+ # os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
115+ if python_dir_entry .get ():
116+ # os.environ["PYTHONHOME"] = python_dir_entry.get()
117+ os .environ ["PATH" ] = python_dir_entry .get () + os .pathsep + _PATH
118+ if getattr (sys , "frozen" , False ) and hasattr (sys , "_MEIPASS" ):
119+ os .environ ["PATH" ] = os .pathsep .join (
120+ [
121+ quarto_bin_path ,
122+ quarto_share_path ,
123+ python_dir_entry .get (),
124+ _PATH ,
125+ ]
126+ )
108127 try :
128+ os .chdir (kwargs ["output_dir" ]) # Change the working directory
109129 # Define logger suffix based on report type and name
110130 logger_suffix = f"{ report_type .get ()} _report_{ str (report_name )} "
111131
@@ -114,6 +134,9 @@ def inner():
114134 f"{ logger_suffix } " ,
115135 folder = (Path (kwargs ["output_dir" ]) / "logs" ).as_posix (),
116136 )
137+ kwargs ["logger" ].info ("logfile: %s" , log_file )
138+ kwargs ["logger" ].debug ("sys.path: %s" , sys .path )
139+ kwargs ["logger" ].debug ("PATH (in app): %s " , os .environ ["PATH" ])
117140 report_generator .get_report (** kwargs )
118141 messagebox .showinfo (
119142 "Success" ,
@@ -127,7 +150,6 @@ def inner():
127150 f"An error occurred: { e } \n \n { stacktrace } "
128151 f"\n See logs for more details { log_file } " ,
129152 )
130- print_completion_message (report_type .get ())
131153
132154 return inner
133155
@@ -155,7 +177,7 @@ def select_directory():
155177##########################################################################################
156178# APP
157179app = customtkinter .CTk ()
158- app .geometry ("620x500 " )
180+ app .geometry ("620x600 " )
159181app .title ("VueGen GUI" )
160182
161183row_count = 0
@@ -206,6 +228,7 @@ def select_directory():
206228# Report type dropdown
207229# - get list of report types from Enum
208230report_types = [report_type .value .lower () for report_type in ReportType ]
231+ # report_types = report_types[:2] # only streamlit and html for now
209232ctk_label_report = customtkinter .CTkLabel (
210233 app ,
211234 text = "Select type of report to generate (using only streamlit for now)" ,
@@ -247,14 +270,16 @@ def select_directory():
247270row_count += 1
248271##########################################################################################
249272# output directory selection
250- # ctk_label_outdir = customtkinter.CTkLabel
273+ ctk_label_outdir = customtkinter .CTkLabel (app , text = "Select output directory:" )
274+ ctk_label_outdir .grid (row = row_count , column = 0 , columnspan = 1 , padx = 10 , pady = 5 )
275+ row_count += 1
276+ ##########################################################################################
251277output_dir_entry = tk .StringVar (value = str (output_dir ))
252278select_output_dir = create_select_directory (output_dir_entry )
253279select_output_dir_button = customtkinter .CTkButton (
254280 app , text = "Select Output Directory" , command = select_output_dir
255281)
256- select_output_dir_button .grid (row = row_count , column = 2 , columnspan = 2 , padx = 5 , pady = 10 )
257-
282+ select_output_dir_button .grid (row = row_count , column = 2 , columnspan = 1 , padx = 5 , pady = 10 )
258283ctk_entry_outpath = customtkinter .CTkEntry (
259284 app ,
260285 width = 400 ,
@@ -263,16 +288,54 @@ def select_directory():
263288ctk_entry_outpath .grid (row = row_count , column = 0 , columnspan = 2 , padx = 10 , pady = 10 )
264289row_count += 1
265290##########################################################################################
266- ctk_label_appath = customtkinter .CTkLabel (
291+ # Python binary selection
292+ # ctk_label_python = customtkinter.CTkLabel
293+ ctk_label_outdir = customtkinter .CTkLabel (app , text = "Select Python binary:" )
294+ ctk_label_outdir .grid (row = row_count , column = 0 , columnspan = 1 , padx = 10 , pady = 5 )
295+ row_count += 1
296+ ##########################################################################################
297+ python_dir_entry = tk .StringVar (value = "" )
298+ select_python_bin = create_select_directory (python_dir_entry )
299+ select_python_bin_button = customtkinter .CTkButton (
300+ app , text = "Select Python binary" , command = select_python_bin
301+ )
302+ select_python_bin_button .grid (row = row_count , column = 2 , columnspan = 1 , padx = 5 , pady = 5 )
303+
304+ ctk_entry_python = customtkinter .CTkEntry (
305+ app ,
306+ width = 400 ,
307+ textvariable = python_dir_entry ,
308+ )
309+ ctk_entry_python .grid (row = row_count , column = 0 , columnspan = 2 , padx = 10 , pady = 5 )
310+ row_count += 1
311+ ##########################################################################################
312+ ctk_label_env_path = customtkinter .CTkLabel (app , text = "PATH:" )
313+ ctk_label_env_path .grid (row = row_count , column = 0 , columnspan = 1 , padx = 2 , pady = 5 )
314+ env_path = tk .StringVar (value = os .environ .get ("PATH" , "not found" ))
315+ ctk_entry_path_env = customtkinter .CTkEntry (
267316 app ,
268- text = f"App path: { app_path } " ,
317+ width = 400 ,
318+ textvariable = env_path ,
269319)
270- ctk_label_appath .grid (row = row_count , column = 0 , columnspan = 2 , padx = 20 , pady = 5 )
320+ ctk_entry_path_env .grid (row = row_count , column = 1 , columnspan = 2 , padx = 10 , pady = 5 )
271321row_count += 1
272322##########################################################################################
323+ # ctk_label_appath = customtkinter.CTkLabel(
324+ # app,
325+ # text=f"App path: {app_path}",
326+ # wraplength=600,
327+ # )
328+ # ctk_label_appath.grid(row=row_count, column=0, columnspan=3, padx=10, pady=5)
329+ # row_count += 1
330+ ##########################################################################################
273331# Run VueGen button
274332run_vuegen = create_run_vuegen (
275- is_dir , config_path , report_type , run_streamlit , output_dir_entry
333+ is_dir = is_dir ,
334+ config_path = config_path ,
335+ report_type = report_type ,
336+ run_streamlit = run_streamlit ,
337+ output_dir_entry = output_dir_entry ,
338+ python_dir_entry = python_dir_entry ,
276339)
277340run_button = customtkinter .CTkButton (
278341 app ,
0 commit comments