|
| 1 | +"""GUI for vuegen command-line tool. |
| 2 | +
|
| 3 | +usage: VueGen [-h] [-c CONFIG] [-dir DIRECTORY] [-rt REPORT_TYPE] |
| 4 | + [-st_autorun] |
| 5 | +
|
| 6 | +optional arguments: |
| 7 | + -h, --help show this help message and exit |
| 8 | + -c CONFIG, --config CONFIG |
| 9 | + Path to the YAML configuration file. |
| 10 | + -dir DIRECTORY, --directory DIRECTORY |
| 11 | + Path to the directory from which the YAML |
| 12 | + config will be inferred. |
| 13 | + -rt REPORT_TYPE, --report_type REPORT_TYPE |
| 14 | + Type of the report to generate (streamlit, |
| 15 | + html, pdf, docx, odt, revealjs, pptx, or |
| 16 | + jupyter). |
| 17 | + -st_autorun, --streamlit_autorun |
| 18 | + Automatically run the Streamlit app after |
| 19 | + report generation. |
| 20 | +""" |
| 21 | + |
| 22 | +import pathlib |
| 23 | +import sys |
| 24 | +import tkinter as tk |
| 25 | + |
| 26 | +import customtkinter |
| 27 | + |
| 28 | +from vuegen.__main__ import main |
| 29 | +from vuegen.report import ReportType |
| 30 | + |
| 31 | +customtkinter.set_appearance_mode("system") |
| 32 | +customtkinter.set_default_color_theme("dark-blue") |
| 33 | + |
| 34 | + |
| 35 | +print(pathlib.Path(".").absolute()) |
| 36 | + |
| 37 | + |
| 38 | +# callbacks |
| 39 | +def create_run_vuegen(is_dir, config_path, report_type, run_streamlit): |
| 40 | + def inner(): |
| 41 | + args = ["vuegen"] |
| 42 | + if is_dir: |
| 43 | + args.append("--directory") |
| 44 | + else: |
| 45 | + args.append("--config") |
| 46 | + args.append(config_path.get()) |
| 47 | + args.append("--report_type") |
| 48 | + args.append(report_type.get()) |
| 49 | + if run_streamlit: |
| 50 | + args.append("--streamlit_autorun") |
| 51 | + print("args:", args) |
| 52 | + sys.argv = args |
| 53 | + main() # Call the main function from vuegen |
| 54 | + |
| 55 | + return inner |
| 56 | + |
| 57 | + |
| 58 | +def optionmenu_callback(choice): |
| 59 | + """Good for logging changes?""" |
| 60 | + print("optionmenu dropdown clicked:", choice) |
| 61 | + |
| 62 | + |
| 63 | +def radiobutton_event(value): |
| 64 | + def radio_button_callback(): |
| 65 | + print("radiobutton toggled, current value:", value.get()) |
| 66 | + |
| 67 | + return radio_button_callback |
| 68 | + |
| 69 | + |
| 70 | +# Options |
| 71 | + |
| 72 | +# get list of report types from Enum |
| 73 | +report_types = [report_type.value.lower() for report_type in ReportType] |
| 74 | + |
| 75 | + |
| 76 | +# APP |
| 77 | +app = customtkinter.CTk() |
| 78 | +app.geometry("800x600") |
| 79 | +app.title("CustomTkinter Demo") |
| 80 | + |
| 81 | +# Config or directory input |
| 82 | +ctk_label_config = customtkinter.CTkLabel( |
| 83 | + app, text="Add path to config file or directory. Select radio button accordingly" |
| 84 | +).pack(pady=2) |
| 85 | +is_dir = tk.IntVar(value=1) |
| 86 | +callback_radio_config = radiobutton_event(is_dir) |
| 87 | +ctk_radio_config_0 = customtkinter.CTkRadioButton( |
| 88 | + app, |
| 89 | + text="Use config", |
| 90 | + command=callback_radio_config, |
| 91 | + variable=is_dir, |
| 92 | + value=0, |
| 93 | +) |
| 94 | +ctk_radio_config_0.pack(pady=2) |
| 95 | +ctk_radio_config_1 = customtkinter.CTkRadioButton( |
| 96 | + app, |
| 97 | + text="Use dir", |
| 98 | + command=callback_radio_config, |
| 99 | + variable=is_dir, |
| 100 | + value=1, |
| 101 | +) |
| 102 | +ctk_radio_config_1.pack(pady=2) |
| 103 | + |
| 104 | +config_path = tk.StringVar() |
| 105 | +config_path_entry = customtkinter.CTkEntry( |
| 106 | + app, |
| 107 | + width=400, |
| 108 | + textvariable=config_path, |
| 109 | +) |
| 110 | +config_path_entry.pack(pady=10) |
| 111 | + |
| 112 | + |
| 113 | +report_type = tk.StringVar(value=report_types[0]) |
| 114 | +report_dropdown = customtkinter.CTkOptionMenu( |
| 115 | + app, |
| 116 | + values=report_types, |
| 117 | + variable=report_type, |
| 118 | + command=optionmenu_callback, |
| 119 | +) |
| 120 | +report_dropdown.pack(pady=20) |
| 121 | + |
| 122 | +_report_type = report_dropdown.get() |
| 123 | +print("report_type value:", _report_type) |
| 124 | + |
| 125 | +run_streamlit = tk.IntVar(value=0) |
| 126 | +callback_radio_st_run = radiobutton_event(run_streamlit) |
| 127 | +ctk_radio_st_autorun_1 = customtkinter.CTkRadioButton( |
| 128 | + app, |
| 129 | + text="autorun streamlit", |
| 130 | + value=1, |
| 131 | + variable=run_streamlit, |
| 132 | + command=callback_radio_st_run, |
| 133 | +) |
| 134 | +ctk_radio_st_autorun_1.pack(pady=2) |
| 135 | +ctk_radio_st_autorun_0 = customtkinter.CTkRadioButton( |
| 136 | + app, |
| 137 | + text="skip starting streamlit", |
| 138 | + value=0, |
| 139 | + variable=run_streamlit, |
| 140 | + command=callback_radio_st_run, |
| 141 | +) |
| 142 | +ctk_radio_st_autorun_0.pack(pady=2) |
| 143 | + |
| 144 | +run_vuegen = create_run_vuegen(is_dir, config_path, report_type, run_streamlit) |
| 145 | +run_button = customtkinter.CTkButton( |
| 146 | + app, |
| 147 | + text="Run VueGen", |
| 148 | + command=run_vuegen, |
| 149 | +) |
| 150 | +run_button.pack(pady=20) |
| 151 | + |
| 152 | +app.mainloop() |
0 commit comments