Skip to content

Commit

Permalink
revert to radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Oct 5, 2023
1 parent e2984e0 commit a4f768c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 34 deletions.
26 changes: 0 additions & 26 deletions gooey_ui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,6 @@ def tabs(labels: list[str]) -> list[state.NestingCtx]:
return [state.NestingCtx(tab) for tab in parent.children]


def controllable_tabs(
labels: list[str], key: str
) -> tuple[list[state.NestingCtx], int]:
index = state.session_state.get(key, 0)
for i, label in enumerate(labels):
if button(
label,
key=f"tab-{i}",
type="primary",
className="replicate-nav",
style={
"background": "black" if i == index else "white",
"color": "white" if i == index else "black",
},
):
state.session_state[key] = index = i
state.experimental_rerun()
ctxs = []
for i, label in enumerate(labels):
if i == index:
ctxs += [div(className="tab-content")]
else:
ctxs += [div(className="tab-content", style={"display": "none"})]
return ctxs, index


def columns(
spec,
*,
Expand Down
24 changes: 16 additions & 8 deletions recipes/QRCodeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,25 @@ def render_form_v2(self):

st.session_state.setdefault(
"__qr_input_type_index",
0
"0"
if st.session_state.get("qr_code_data")
else 1
else "1"
if st.session_state.get("vcard_data")
else 2,
else "2",
)
(url, vCard, existing), index = st.controllable_tabs(
["πŸ–ŠοΈ Link or Text", "πŸ“‡ Contact vCard", "πŸ“· Existing QR Code"],
st.radio(
"",
options=["0", "1", "2"],
key="__qr_input_type_index",
format_func=lambda x: [
"πŸ–ŠοΈ Link or Text",
"πŸ“‡ Contact vCard",
"πŸ“· Existing QR Code",
][int(x)],
)
index = st.session_state.get("__qr_input_type_index", "0")

with url:
if index == "0":
st.text_area(
"""
### πŸ”— URL
Expand All @@ -180,7 +187,7 @@ def render_form_v2(self):
'A shortened URL enables the QR code to be more beautiful and less "QR-codey" with fewer blocky pixels.'
)

with existing:
if index == "2":
st.file_uploader(
"""
### πŸ“· QR Code Image
Expand All @@ -194,7 +201,8 @@ def render_form_v2(self):
'A shortened URL enables the QR code to be more beautiful and less "QR-codey" with fewer blocky pixels.'
)

with vCard:
if index == "1":
print("hi")
st.caption(
"We'll use the prompt above to create a beautiful QR code that when scanned on a phone, will add the info below as a contact. Great for conferences and geeky parties."
)
Expand Down

0 comments on commit a4f768c

Please sign in to comment.