feat: hide custom settings if custom not selected

This commit is contained in:
2026-07-05 17:29:56 +08:00
parent 0a10c61c59
commit 5df288b577
4 changed files with 84 additions and 2 deletions
+19
View File
@@ -610,6 +610,25 @@ class ConfigUpdater:
# yield 'Dungeon.Dungeon.NameAtDoubleRelic', value
pass
def iter_hidden_args(self, data) -> t.Iterator[str]:
"""
Args:
data (dict): config
Yields:
str: Arg path that should be hidden
"""
# if deep_get(data, 'Rogue.RoguePath.PresetResonanceFilter') != 'custom':
# yield 'Rogue.RoguePath.CustomResonanceFilter'
pass
def get_hidden_args(self, data) -> t.Set[str]:
"""
Return a set of hidden args
"""
out = list(self.iter_hidden_args(data))
return set(out)
def read_file(self, config_name, is_template=False):
"""
Read and update config file.
+12
View File
@@ -106,6 +106,7 @@ class AlasGUI(Frame):
self.alas_name = ""
self.alas_mod = "alas"
self.alas_config = AzurLaneConfig("template")
self.alas_config_hidden = set()
self.initial()
@use_scope("aside", clear=True)
@@ -236,6 +237,7 @@ class AlasGUI(Frame):
)
config = self.alas_config.read_file(self.alas_name)
self.alas_config_hidden = self.alas_config.get_hidden_args(config)
for group, arg_dict in deep_iter(self.ALAS_ARGS[task], depth=1):
if self.set_group(group, arg_dict, config, task):
self.set_navigator(group)
@@ -291,6 +293,9 @@ class AlasGUI(Frame):
if o is not None:
# output will inherit current scope when created, override here
o.spec["scope"] = f"#pywebio-scope-group_{group_name}"
# Add hidden-arg
if f"{task}.{group_name}.{arg_name}" in self.alas_config_hidden:
o.style("display:none")
output_list.append(o)
if not output_list:
@@ -507,6 +512,13 @@ class AlasGUI(Frame):
logger.warning(f"Invalid value {v} for key {k}, skip saving.")
self.pin_remove_invalid_mark(valid)
self.pin_set_invalid_mark(invalid)
new_hidden_args = config_updater.get_hidden_args(config)
for k in new_hidden_args - self.alas_config_hidden:
self.pin_set_hidden_arg(k, type_=deep_get(self.ALAS_ARGS, f"{k}.type"))
for k in self.alas_config_hidden - new_hidden_args:
self.pin_remove_hidden_arg(k, type_=deep_get(self.ALAS_ARGS, f"{k}.type"))
self.alas_config_hidden = new_hidden_args
if modified:
toast(
t("Gui.Toast.ConfigSaved"),
+31
View File
@@ -4,6 +4,7 @@ from pywebio.output import clear, put_html, put_scope, put_text, use_scope
from pywebio.session import defer_call, info, run_js
from module.webui.utils import Icon, WebIOTaskHandler, set_localstorage
from module.webui.widgets import type_to_html
class Base:
@@ -167,3 +168,33 @@ class Frame(Base):
run_js(js)
# for key in keys:
# pin_update(key, valid_status=0)
@staticmethod
def pin_set_hidden_arg(key, type_) -> None:
"""
Hide arg
Args:
key: Path
type_: Type in _widget_type_to_func
"""
type_ = type_to_html(type_)
key = "_".join(key.split("."))
key = f"pywebio-scope-arg_container-{type_}-{key}"
# This aims to be a typo, don't correct it, leave it as it is
if type_ == 'textarea':
key = key.replace('container', 'contianer')
js = f"""$("#{key}").css("display","none");"""
if js:
run_js(js)
@staticmethod
def pin_remove_hidden_arg(key, type_) -> None:
type_ = type_to_html(type_)
key = "_".join(key.split("."))
key = f"pywebio-scope-arg_container-{type_}-{key}"
if type_ == 'textarea':
key = key.replace('container', 'contianer')
js = f"""$("#{key}").removeAttr('style');"""
if js:
run_js(js)
+22 -2
View File
@@ -2,7 +2,7 @@ import copy
import json
import random
import string
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Optional, Union
from typing import Any, Callable, Dict, Generator, List, Optional, TYPE_CHECKING, Union
from pywebio.exceptions import SessionException
from pywebio.io_ctrl import Output
@@ -10,7 +10,7 @@ from pywebio.output import *
from pywebio.session import eval_js, local, run_js
from rich.console import ConsoleRenderable
from module.logger import WEB_THEME, Highlighter, HTMLConsole
from module.logger import HTMLConsole, Highlighter, WEB_THEME
from module.webui.lang import t
from module.webui.pin import put_checkbox, put_input, put_select, put_textarea
from module.webui.process_manager import ProcessManager
@@ -424,6 +424,7 @@ def put_arg_textarea(kwargs: T_Output_Kwargs) -> Output:
)
return put_scope(
# This aims to be a typo, don't correct it, leave it as it is
f"arg_contianer-textarea-{name}",
[
get_title_help(kwargs),
@@ -507,6 +508,25 @@ def put_output(output_kwargs: T_Output_Kwargs) -> Optional[Output]:
return _widget_type_to_func[output_kwargs["widget_type"]](output_kwargs)
def type_to_html(type_: str) -> str:
"""
Args:
type_: Type defined in _widget_type_to_func and argument.yaml
Returns:
str: Html element name
"""
if type_ == "checkbox":
return "checkbox"
if type_ in ["input", "lock", "datetime"]:
return "input"
if type_ in ["select", "state"]:
return "select"
if type_ in ["textarea", "storage"]:
return "textarea"
return type_
def get_loading_style(shape: str, fill: bool) -> str:
if fill:
return f"--loading-{shape}-fill--"