Skip to content

Commit 1fa37c8

Browse files
committed
✨: First simple working example of a GUI (streamlit local)
- can start streamlit when not package as exectuable from GUI - use grid to define layout ToDo: Move to class-based layout
1 parent 2387f23 commit 1fa37c8

File tree

3 files changed

+184
-1
lines changed

3 files changed

+184
-1
lines changed

gui/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# VueGen GUI
2+
3+
## Local execution of the GUI
4+
5+
Install required dependencies from package
6+
7+
```bash
8+
pip install 'vuegen[gui]'
9+
# or with local repo
10+
pip install '.[gui]'
11+
# or for local editable install
12+
pip install -e '.[gui]'
13+
```
14+
15+
Can be started locally with
16+
17+
```bash
18+
# from within gui directory
19+
python app.py
20+
```

gui/app.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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 sys
23+
import tkinter as tk
24+
25+
import customtkinter
26+
27+
from vuegen.__main__ import main
28+
from vuegen.report import ReportType
29+
30+
customtkinter.set_appearance_mode("system")
31+
customtkinter.set_default_color_theme("dark-blue")
32+
33+
34+
# callbacks
35+
def create_run_vuegen(is_dir, config_path, report_type, run_streamlit):
36+
def inner():
37+
args = ["vuegen"]
38+
if is_dir:
39+
args.append("--directory")
40+
else:
41+
args.append("--config")
42+
args.append(config_path.get())
43+
args.append("--report_type")
44+
args.append(report_type.get())
45+
if run_streamlit:
46+
args.append("--streamlit_autorun")
47+
print("args:", args)
48+
sys.argv = args
49+
main() # Call the main function from vuegen
50+
51+
return inner
52+
53+
54+
def optionmenu_callback(choice):
55+
"""Good for logging changes?"""
56+
print("optionmenu dropdown clicked:", choice)
57+
58+
59+
def radiobutton_event(value):
60+
def radio_button_callback():
61+
print("radiobutton toggled, current value:", value.get())
62+
63+
return radio_button_callback
64+
65+
66+
# Options
67+
68+
# get list of report types from Enum
69+
report_types = [report_type.value.lower() for report_type in ReportType]
70+
71+
72+
# APP
73+
app = customtkinter.CTk()
74+
app.geometry("460x400")
75+
app.title("VueGen GUI")
76+
77+
##########################################################################################
78+
# Config or directory input
79+
ctk_label_config = customtkinter.CTkLabel(
80+
app,
81+
text="Add path to config file or directory. Select radio button accordingly",
82+
)
83+
ctk_label_config.grid(row=0, column=0, columnspan=2, padx=20, pady=20)
84+
is_dir = tk.IntVar(value=1)
85+
callback_radio_config = radiobutton_event(is_dir)
86+
ctk_radio_config_0 = customtkinter.CTkRadioButton(
87+
app,
88+
text="Use config",
89+
command=callback_radio_config,
90+
variable=is_dir,
91+
value=0,
92+
)
93+
ctk_radio_config_0.grid(row=1, column=0, padx=20, pady=2)
94+
ctk_radio_config_1 = customtkinter.CTkRadioButton(
95+
app,
96+
text="Use dir",
97+
command=callback_radio_config,
98+
variable=is_dir,
99+
value=1,
100+
)
101+
ctk_radio_config_1.grid(row=1, column=1, padx=20, pady=2)
102+
103+
config_path = tk.StringVar()
104+
config_path_entry = customtkinter.CTkEntry(
105+
app,
106+
width=400,
107+
textvariable=config_path,
108+
)
109+
config_path_entry.grid(row=2, column=0, columnspan=2, padx=20, pady=10)
110+
111+
##########################################################################################
112+
# Report type dropdown
113+
ctk_label_report = customtkinter.CTkLabel(
114+
app,
115+
text="Select type of report to generate (use streamlit for now)",
116+
)
117+
ctk_label_report.grid(row=3, column=0, columnspan=2, padx=20, pady=20)
118+
report_type = tk.StringVar(value=report_types[0])
119+
report_dropdown = customtkinter.CTkOptionMenu(
120+
app,
121+
values=report_types,
122+
variable=report_type,
123+
command=optionmenu_callback,
124+
)
125+
report_dropdown.grid(row=4, column=0, columnspan=2, padx=20, pady=20)
126+
127+
_report_type = report_dropdown.get()
128+
print("report_type value:", _report_type)
129+
130+
##########################################################################################
131+
# Run Streamlit radio button
132+
run_streamlit = tk.IntVar(value=0)
133+
callback_radio_st_run = radiobutton_event(run_streamlit)
134+
ctk_radio_st_autorun_1 = customtkinter.CTkRadioButton(
135+
app,
136+
text="autorun streamlit",
137+
value=1,
138+
variable=run_streamlit,
139+
command=callback_radio_st_run,
140+
)
141+
ctk_radio_st_autorun_1.grid(row=5, column=0, padx=20, pady=20)
142+
ctk_radio_st_autorun_0 = customtkinter.CTkRadioButton(
143+
app,
144+
text="skip starting streamlit",
145+
value=0,
146+
variable=run_streamlit,
147+
command=callback_radio_st_run,
148+
)
149+
ctk_radio_st_autorun_0.grid(row=5, column=1, padx=20, pady=20)
150+
151+
##########################################################################################
152+
# Run VueGen button
153+
run_vuegen = create_run_vuegen(is_dir, config_path, report_type, run_streamlit)
154+
run_button = customtkinter.CTkButton(
155+
app,
156+
text="Run VueGen",
157+
command=run_vuegen,
158+
)
159+
run_button.grid(row=6, column=0, columnspan=2, padx=20, pady=20)
160+
161+
##########################################################################################
162+
# Run the app in the mainloop
163+
app.mainloop()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ build-backend = "poetry_dynamic_versioning.backend"
5555

5656
# https://stackoverflow.com/a/60990574/9684872
5757
[tool.poetry.extras]
58-
docs = ["sphinx", "sphinx-book-theme", "myst-nb", "ipywidgets", "sphinx-new-tab-link", "jupytext"]
58+
gui = ["customtkinter"]
5959

6060
[tool.poetry.scripts]
6161
# https://python-poetry.org/docs/pyproject/#scripts

0 commit comments

Comments
 (0)