mirror of
https://github.com/thomasasfk/sd-webui-aspect-ratio-helper.git
synced 2026-01-26 19:19:58 +00:00
Add option to hide accordion by default (#29)
This commit is contained in:
@@ -38,7 +38,8 @@ https://user-images.githubusercontent.com/22506439/227396634-7a63671a-fd38-419a-
|
||||
|
||||
## Settings
|
||||
|
||||
- Expand by default (`False`)
|
||||
- Hide accordion by default (`False`)
|
||||
- Expand accordion by default (`False`)
|
||||
- Determines whether the 'Aspect Ratio Helper' accordion expands by default
|
||||
- UI Component order (`MaxDimensionScaler, PredefinedAspectRatioButtons, PredefinedPercentageButtons`)
|
||||
- Determines the order in which the UI components will render
|
||||
@@ -61,6 +62,9 @@ https://user-images.githubusercontent.com/22506439/227396634-7a63671a-fd38-419a-
|
||||
|
||||

|
||||
|
||||
|
||||
JavaScript & accordion aspect ratios _might_ not play well together - I don't think many users will use both simultaneously, but we'll see.
|
||||
|
||||
## Contributing
|
||||
|
||||
- Open an issue for suggestions
|
||||
|
||||
@@ -4,6 +4,7 @@ MAX_DIMENSION = 2048
|
||||
MIN_DIMENSION = 64
|
||||
|
||||
ARH_EXPAND_BY_DEFAULT_KEY = 'arh_expand_by_default'
|
||||
ARH_HIDE_ACCORDION_BY_DEFAULT_KEY = 'arh_hide_accordion_by_default'
|
||||
ARH_UI_COMPONENT_ORDER_KEY = 'arh_ui_component_order_key'
|
||||
ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY = 'arh_javascript_aspect_ratio_show'
|
||||
ARH_JAVASCRIPT_ASPECT_RATIOS_KEY = 'arh_javascript_aspect_ratio'
|
||||
|
||||
@@ -25,6 +25,7 @@ DEFAULT_UI_COMPONENT_ORDER_KEY = ', '.join(
|
||||
)
|
||||
OPT_KEY_TO_DEFAULT_MAP = {
|
||||
_constants.ARH_EXPAND_BY_DEFAULT_KEY: False,
|
||||
_constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY: False,
|
||||
_constants.ARH_UI_COMPONENT_ORDER_KEY:
|
||||
DEFAULT_UI_COMPONENT_ORDER_KEY,
|
||||
_constants.ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY: False,
|
||||
@@ -87,35 +88,7 @@ def sort_components_by_keys(
|
||||
|
||||
|
||||
def on_ui_settings():
|
||||
# default ui options
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_EXPAND_BY_DEFAULT_KEY,
|
||||
info=shared.OptionInfo(
|
||||
default=OPT_KEY_TO_DEFAULT_MAP.get(
|
||||
_constants.ARH_EXPAND_BY_DEFAULT_KEY,
|
||||
),
|
||||
label='Expand by default',
|
||||
section=_constants.SECTION,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_UI_COMPONENT_ORDER_KEY,
|
||||
info=shared.OptionInfo(
|
||||
default=OPT_KEY_TO_DEFAULT_MAP.get(
|
||||
_constants.ARH_UI_COMPONENT_ORDER_KEY,
|
||||
),
|
||||
label='UI Component order',
|
||||
component=gr.Dropdown,
|
||||
component_args=lambda: {
|
||||
'choices': [
|
||||
', '.join(p) for p in itertools.permutations(
|
||||
DEFAULT_UI_COMPONENT_ORDER_KEY_LIST,
|
||||
)
|
||||
],
|
||||
},
|
||||
section=_constants.SECTION,
|
||||
),
|
||||
)
|
||||
# javascript ui options
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_JAVASCRIPT_ASPECT_RATIO_SHOW_KEY,
|
||||
info=shared.OptionInfo(
|
||||
@@ -138,5 +111,45 @@ def on_ui_settings():
|
||||
),
|
||||
)
|
||||
|
||||
# accordion options
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
|
||||
info=shared.OptionInfo(
|
||||
default=OPT_KEY_TO_DEFAULT_MAP.get(
|
||||
_constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
|
||||
),
|
||||
label='Hide accordion by default',
|
||||
section=_constants.SECTION,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_EXPAND_BY_DEFAULT_KEY,
|
||||
info=shared.OptionInfo(
|
||||
default=OPT_KEY_TO_DEFAULT_MAP.get(
|
||||
_constants.ARH_EXPAND_BY_DEFAULT_KEY,
|
||||
),
|
||||
label='Expand accordion by default',
|
||||
section=_constants.SECTION,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key=_constants.ARH_UI_COMPONENT_ORDER_KEY,
|
||||
info=shared.OptionInfo(
|
||||
default=OPT_KEY_TO_DEFAULT_MAP.get(
|
||||
_constants.ARH_UI_COMPONENT_ORDER_KEY,
|
||||
),
|
||||
label='UI Component order',
|
||||
component=gr.Dropdown,
|
||||
component_args=lambda: {
|
||||
'choices': [
|
||||
', '.join(p) for p in itertools.permutations(
|
||||
DEFAULT_UI_COMPONENT_ORDER_KEY_LIST,
|
||||
)
|
||||
],
|
||||
},
|
||||
section=_constants.SECTION,
|
||||
),
|
||||
)
|
||||
|
||||
for component in COMPONENTS:
|
||||
component.add_options(shared)
|
||||
|
||||
@@ -33,7 +33,11 @@ class AspectRatioStepScript(scripts.Script):
|
||||
[component(self) for component in _settings.COMPONENTS],
|
||||
)
|
||||
|
||||
if not any(component.should_show() for component in components):
|
||||
hide_accordion: bool = _settings.safe_opt(
|
||||
_constants.ARH_HIDE_ACCORDION_BY_DEFAULT_KEY,
|
||||
)
|
||||
|
||||
if hide_accordion or not any(c.should_show() for c in components):
|
||||
return # no components should render, so just return.
|
||||
|
||||
start_expanded: bool = _settings.safe_opt(
|
||||
|
||||
Reference in New Issue
Block a user