show more input fields

This commit is contained in:
flukx 2024-08-16 16:19:43 +02:00
parent 3b67d128e6
commit c64f2e4232

View file

@ -216,9 +216,6 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
part: the part to change
save_function: what to call when changing is done
"""
def delete_member(member, updated: nicegui.ui.input):
del vars(part)[member]
updated.set_value("")
input_fields = {}
def save_value(event, member):
"""Copy input field value to part member."""
@ -227,17 +224,54 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
else:
vars(part)[member] = event.value
def save_sign_value(event, member):
"""Copy input field value to sign member."""
if not event.value:
del(vars(part.sign)[member])
else:
vars(part.sign)[member] = event.value
def save_list_value(event, member):
"""Split input field at '; ' and save ta part member."""
if not event.value:
del(vars(part)[member])
else:
values = event.value.split(";")
values = [value.strip() for value in values]
values = [value for value in values if value]
vars(part)[member] = values
print(f"Try to let edit {part.name} with {id(ui_element)}.")
ui_element.clear()
with ui_element:
for member in ("name_de", "name_en", "description_de", "description_en"):
with ui.row():
ui.label(member + ":")
input_fields[member] = ui.input(part.get(member, "")).on_value_change(
lambda e, m=member: save_value(e, m))
ui.button("").on_click(
lambda m=member, i=input_fields[member]:
delete_member(m, i))
with ui.row():
with ui.column():
for member in ("name_de", "name_en", "description_de", "description_en"):
input_fields[member] = ui.input(
label=member,
value=part.get(member, "")
).props(
'autogrow dense'
).on_value_change(
lambda e, m=member: save_value(e, m))
for member in ("name_alt_de", "name_alt_en"):
input_fields[member] = ui.input(
label=member + " (;-seperated):",
value="; ".join(part.get(member, []))
).props(
'autogrow dense'
).on_value_change(
lambda e, m=member: save_list_value(e, m))
with ui.column():
for sign_member in ("width", "height", "name_de", "name_en", "fontsize_de", "fontsize_en",
"location_shift_down"):
input_fields[f"sign.{sign_member}"] = ui.input(
label="sign: " + sign_member,
value=vars(part.sign).get(sign_member, "")
).props('autogrow dense'
).on_value_change(
lambda e, m=sign_member: save_sign_value(e, m)
)
if __name__ in {"__main__", "__mp_main__"}: