add possibility to change location
This commit is contained in:
parent
b9cf8d58ab
commit
2fe607cd4c
1 changed files with 41 additions and 0 deletions
|
@ -8,6 +8,8 @@ import time
|
|||
from typing import Optional, Iterable, Callable
|
||||
import nicegui
|
||||
from nicegui import ui
|
||||
|
||||
import location
|
||||
from part import Part
|
||||
import part_list_io
|
||||
|
||||
|
@ -242,6 +244,43 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
values = [value for value in values if value]
|
||||
vars(part)[member] = values
|
||||
|
||||
def update_location_element(location_ui_element):
|
||||
"""List location information with input fields."""
|
||||
location_ui_element.clear()
|
||||
with location_ui_element:
|
||||
location_info = part.location.json
|
||||
# ui.label(
|
||||
# next(part.location).name
|
||||
# )
|
||||
for level in part.location.schema.get_schema_hierachy(dict(iter(part.location))):
|
||||
try:
|
||||
levelname = level.levelname
|
||||
except location.InvalidLocation:
|
||||
# bottom most locotion (in hierachy) has no subs and therefore
|
||||
# needs no input
|
||||
continue
|
||||
ui.input(
|
||||
label=level.levelname,
|
||||
value=location_info.get(level.levelname, "")
|
||||
).props(
|
||||
'autogrow dense'
|
||||
).on_value_change(
|
||||
lambda event, s=level, ui_ele=location_ui_element: save_location(event, s, ui_ele)
|
||||
)
|
||||
|
||||
def save_location(event, schema: location.Schema, location_ui_element) -> None:
|
||||
"""Save location input if valid."""
|
||||
try:
|
||||
schema.get_subschema(event.value)
|
||||
except location.InvalidLocationSchema as error:
|
||||
print("InvalidLocationSchema: ", error)
|
||||
except location.InvalidLocation:
|
||||
print("Do not save")
|
||||
pass
|
||||
part.location.set(schema.levelname, event.value)
|
||||
update_location_element(location_ui_element)
|
||||
|
||||
|
||||
print(f"Try to let edit {part.name} with {id(ui_element)}.")
|
||||
ui_element.clear()
|
||||
with ui_element:
|
||||
|
@ -274,6 +313,8 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
).on_value_change(
|
||||
lambda e, m=sign_member: save_sign_value(e, m)
|
||||
)
|
||||
with ui.column() as location_column:
|
||||
update_location_element(location_column)
|
||||
|
||||
|
||||
if __name__ in {"__main__", "__mp_main__"}:
|
||||
|
|
Loading…
Reference in a new issue