make pylint happier
This commit is contained in:
parent
45e6e740ad
commit
984c1a14ec
1 changed files with 11 additions and 15 deletions
|
@ -2,7 +2,6 @@
|
|||
import argparse
|
||||
import asyncio
|
||||
import itertools
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
from typing import Optional, Iterable, Callable, Union, Any, Literal
|
||||
|
@ -68,7 +67,7 @@ def antilen(string: str):
|
|||
return 1 / len(string) if string else 0
|
||||
|
||||
|
||||
async def find_parts(parts: list[Part], search_string: str, max_number: int=10) -> Iterable[Part]:
|
||||
async def find_parts(parts: list[Part], search_string: str, max_number: int = 10) -> Iterable[Part]:
|
||||
"""Gives parts that the user might have searched for.
|
||||
|
||||
Args:
|
||||
|
@ -239,7 +238,6 @@ def search_page() -> None:
|
|||
if end - start > 0.01:
|
||||
print(f"Query {event.value}: {end - start} seconds")
|
||||
except asyncio.exceptions.CancelledError:
|
||||
print("Search cancelled")
|
||||
pass
|
||||
else:
|
||||
if results:
|
||||
|
@ -261,7 +259,6 @@ def search_page() -> None:
|
|||
results = ui.column()
|
||||
|
||||
|
||||
|
||||
def try_conversion(value: str,
|
||||
conversions: tuple[Union[Callable[[str], Any], Literal["bool"]]]) -> Any:
|
||||
"""Try to convert value into other values.
|
||||
|
@ -293,31 +290,32 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
part: the part to change
|
||||
"""
|
||||
input_fields = {}
|
||||
|
||||
def save_value(event, member):
|
||||
"""Copy input field value to part member."""
|
||||
if not event.value:
|
||||
del(vars(part)[member])
|
||||
del vars(part)[member]
|
||||
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])
|
||||
del vars(part.sign)[member]
|
||||
else:
|
||||
vars(part.sign)[member] = try_conversion(event.value, (int, float, "bool"))
|
||||
|
||||
def save_list_value(event, member):
|
||||
"""Split input field at '; ' and save ta part member."""
|
||||
if not event.value:
|
||||
del(vars(part)[member])
|
||||
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
|
||||
|
||||
def update_location_element(location_ui_element, focus: Optional[str]=None):
|
||||
def update_location_element(location_ui_element, focus: Optional[str] = None):
|
||||
"""List location information with input fields.
|
||||
|
||||
Args:
|
||||
|
@ -344,19 +342,19 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
).props(
|
||||
'autogrow dense' + (' autofocus' if levelname == focus else '')
|
||||
).on_value_change(
|
||||
lambda event, s=level, ui_ele=location_ui_element: save_location(event, s, ui_ele)
|
||||
lambda event, s=level, ui_ele=location_ui_element: save_location(event,
|
||||
s, ui_ele)
|
||||
).tooltip(
|
||||
", ".join(level.get_valid_subs(shortcuts='()')) if level.get_valid_subs()
|
||||
else "Any value is valid. Probably integers are reasonable."
|
||||
)
|
||||
additional_info = [(key, value) for key, value in location_info.items()
|
||||
if not any(key == schema.levelname for schema in schema_hierachy)]
|
||||
if not any(key == schema.levelname for schema in schema_hierachy)]
|
||||
if additional_info:
|
||||
ui.label("Unused location information:")
|
||||
for key, value in additional_info:
|
||||
ui.label(f"{key}: {value}")
|
||||
|
||||
|
||||
def save_location(event, schema: location.Schema, location_ui_element) -> None:
|
||||
"""Save location input if valid."""
|
||||
value = try_conversion(event.value, (int, "bool"))
|
||||
|
@ -370,7 +368,6 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
part.location.set(schema.levelname, value)
|
||||
update_location_element(location_ui_element, focus=schema.levelname)
|
||||
|
||||
|
||||
print(f"Try to let edit {part.name} with {id(ui_element)}.")
|
||||
ui_element.clear()
|
||||
with ui_element:
|
||||
|
@ -393,9 +390,8 @@ def show_part_changer(ui_element: nicegui.ui.element, part: Part) -> None:
|
|||
).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"):
|
||||
# todo: convert to int/float/... where it makes sense
|
||||
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, "")
|
||||
|
|
Loading…
Reference in a new issue