From 29049876319eb13a1d51ddb99fb3d4a9b83d35db Mon Sep 17 00:00:00 2001 From: Henry Ruhs Date: Fri, 29 Mar 2024 13:49:43 +0100 Subject: [PATCH] Use release for every slider (#463) * Use release event handler for every slider * Move more sliders to release handler * Move more sliders to release handler * Add get_ui_components() to simplify code --- .../uis/components/execution_queue_count.py | 2 +- .../uis/components/execution_thread_count.py | 2 +- facefusion/uis/components/face_masker.py | 4 +- facefusion/uis/components/face_selector.py | 49 ++++++------- .../components/frame_processors_options.py | 4 +- facefusion/uis/components/memory.py | 10 +-- facefusion/uis/components/output_options.py | 21 +++--- facefusion/uis/components/preview.py | 73 ++++++++++--------- facefusion/uis/components/trim_frame.py | 4 +- facefusion/uis/components/webcam.py | 16 ++-- facefusion/uis/core.py | 20 +++-- 11 files changed, 105 insertions(+), 100 deletions(-) diff --git a/facefusion/uis/components/execution_queue_count.py b/facefusion/uis/components/execution_queue_count.py index 18456a51..1b6725e5 100644 --- a/facefusion/uis/components/execution_queue_count.py +++ b/facefusion/uis/components/execution_queue_count.py @@ -21,7 +21,7 @@ def render() -> None: def listen() -> None: - EXECUTION_QUEUE_COUNT_SLIDER.change(update_execution_queue_count, inputs = EXECUTION_QUEUE_COUNT_SLIDER) + EXECUTION_QUEUE_COUNT_SLIDER.release(update_execution_queue_count, inputs = EXECUTION_QUEUE_COUNT_SLIDER) def update_execution_queue_count(execution_queue_count : int = 1) -> None: diff --git a/facefusion/uis/components/execution_thread_count.py b/facefusion/uis/components/execution_thread_count.py index df0d5dfa..4a1f4646 100644 --- a/facefusion/uis/components/execution_thread_count.py +++ b/facefusion/uis/components/execution_thread_count.py @@ -21,7 +21,7 @@ def render() -> None: def listen() -> None: - EXECUTION_THREAD_COUNT_SLIDER.change(update_execution_thread_count, inputs = EXECUTION_THREAD_COUNT_SLIDER) + EXECUTION_THREAD_COUNT_SLIDER.release(update_execution_thread_count, inputs = EXECUTION_THREAD_COUNT_SLIDER) def update_execution_thread_count(execution_thread_count : int = 1) -> None: diff --git a/facefusion/uis/components/face_masker.py b/facefusion/uis/components/face_masker.py index fb111e03..bb1c28c9 100755 --- a/facefusion/uis/components/face_masker.py +++ b/facefusion/uis/components/face_masker.py @@ -92,11 +92,11 @@ def render() -> None: def listen() -> None: FACE_MASK_TYPES_CHECKBOX_GROUP.change(update_face_mask_type, inputs = FACE_MASK_TYPES_CHECKBOX_GROUP, outputs = [ FACE_MASK_TYPES_CHECKBOX_GROUP, FACE_MASK_BOX_GROUP, FACE_MASK_REGION_CHECKBOX_GROUP ]) - FACE_MASK_BLUR_SLIDER.change(update_face_mask_blur, inputs = FACE_MASK_BLUR_SLIDER) + FACE_MASK_BLUR_SLIDER.release(update_face_mask_blur, inputs = FACE_MASK_BLUR_SLIDER) FACE_MASK_REGION_CHECKBOX_GROUP.change(update_face_mask_regions, inputs = FACE_MASK_REGION_CHECKBOX_GROUP, outputs = FACE_MASK_REGION_CHECKBOX_GROUP) face_mask_padding_sliders = [ FACE_MASK_PADDING_TOP_SLIDER, FACE_MASK_PADDING_RIGHT_SLIDER, FACE_MASK_PADDING_BOTTOM_SLIDER, FACE_MASK_PADDING_LEFT_SLIDER ] for face_mask_padding_slider in face_mask_padding_sliders: - face_mask_padding_slider.change(update_face_mask_padding, inputs = face_mask_padding_sliders) + face_mask_padding_slider.release(update_face_mask_padding, inputs = face_mask_padding_sliders) def update_face_mask_type(face_mask_types : List[FaceMaskType]) -> Tuple[gradio.CheckboxGroup, gradio.Group, gradio.CheckboxGroup]: diff --git a/facefusion/uis/components/face_selector.py b/facefusion/uis/components/face_selector.py index df8c3037..3dc7c17b 100644 --- a/facefusion/uis/components/face_selector.py +++ b/facefusion/uis/components/face_selector.py @@ -10,8 +10,7 @@ from facefusion.vision import get_video_frame, read_static_image, normalize_fram from facefusion.filesystem import is_image, is_video from facefusion.face_analyser import get_many_faces from facefusion.typing import VisionFrame, FaceSelectorMode -from facefusion.uis.core import get_ui_component, register_ui_component -from facefusion.uis.typing import ComponentName +from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component FACE_SELECTOR_MODE_DROPDOWN : Optional[gradio.Dropdown] = None REFERENCE_FACE_POSITION_GALLERY : Optional[gradio.Gallery] = None @@ -59,42 +58,42 @@ def render() -> None: def listen() -> None: FACE_SELECTOR_MODE_DROPDOWN.change(update_face_selector_mode, inputs = FACE_SELECTOR_MODE_DROPDOWN, outputs = [ REFERENCE_FACE_POSITION_GALLERY, REFERENCE_FACE_DISTANCE_SLIDER ]) REFERENCE_FACE_POSITION_GALLERY.select(clear_and_update_reference_face_position) - REFERENCE_FACE_DISTANCE_SLIDER.change(update_reference_face_distance, inputs = REFERENCE_FACE_DISTANCE_SLIDER) - multi_component_names : List[ComponentName] =\ + REFERENCE_FACE_DISTANCE_SLIDER.release(update_reference_face_distance, inputs = REFERENCE_FACE_DISTANCE_SLIDER) + + for ui_component in get_ui_components( [ 'target_image', 'target_video' - ] - for component_name in multi_component_names: - component = get_ui_component(component_name) - if component: - for method in [ 'upload', 'change', 'clear' ]: - getattr(component, method)(update_reference_face_position) - getattr(component, method)(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) - change_one_component_names : List[ComponentName] =\ + ]): + for method in [ 'upload', 'change', 'clear' ]: + getattr(ui_component, method)(update_reference_face_position) + getattr(ui_component, method)(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) + + for ui_component in get_ui_components( [ 'face_analyser_order_dropdown', 'face_analyser_age_dropdown', 'face_analyser_gender_dropdown' - ] - for component_name in change_one_component_names: - component = get_ui_component(component_name) - if component: - component.change(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) - change_two_component_names : List[ComponentName] =\ + ]): + ui_component.change(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) + + for ui_component in get_ui_components( [ 'face_detector_model_dropdown', - 'face_detector_size_dropdown', + 'face_detector_size_dropdown' + ]): + ui_component.change(clear_and_update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) + + for ui_component in get_ui_components( + [ 'face_detector_score_slider', 'face_landmarker_score_slider' - ] - for component_name in change_two_component_names: - component = get_ui_component(component_name) - if component: - component.change(clear_and_update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) + ]): + ui_component.release(clear_and_update_reference_position_gallery, outputs=REFERENCE_FACE_POSITION_GALLERY) + preview_frame_slider = get_ui_component('preview_frame_slider') if preview_frame_slider: - preview_frame_slider.change(update_reference_frame_number, inputs = preview_frame_slider) + preview_frame_slider.release(update_reference_frame_number, inputs = preview_frame_slider) preview_frame_slider.release(update_reference_position_gallery, outputs = REFERENCE_FACE_POSITION_GALLERY) diff --git a/facefusion/uis/components/frame_processors_options.py b/facefusion/uis/components/frame_processors_options.py index 74dcdf7d..d7f8992b 100755 --- a/facefusion/uis/components/frame_processors_options.py +++ b/facefusion/uis/components/frame_processors_options.py @@ -84,10 +84,10 @@ def render() -> None: def listen() -> None: FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP.change(update_face_debugger_items, inputs = FACE_DEBUGGER_ITEMS_CHECKBOX_GROUP) FACE_ENHANCER_MODEL_DROPDOWN.change(update_face_enhancer_model, inputs = FACE_ENHANCER_MODEL_DROPDOWN, outputs = FACE_ENHANCER_MODEL_DROPDOWN) - FACE_ENHANCER_BLEND_SLIDER.change(update_face_enhancer_blend, inputs = FACE_ENHANCER_BLEND_SLIDER) + FACE_ENHANCER_BLEND_SLIDER.release(update_face_enhancer_blend, inputs = FACE_ENHANCER_BLEND_SLIDER) FACE_SWAPPER_MODEL_DROPDOWN.change(update_face_swapper_model, inputs = FACE_SWAPPER_MODEL_DROPDOWN, outputs = FACE_SWAPPER_MODEL_DROPDOWN) FRAME_ENHANCER_MODEL_DROPDOWN.change(update_frame_enhancer_model, inputs = FRAME_ENHANCER_MODEL_DROPDOWN, outputs = FRAME_ENHANCER_MODEL_DROPDOWN) - FRAME_ENHANCER_BLEND_SLIDER.change(update_frame_enhancer_blend, inputs = FRAME_ENHANCER_BLEND_SLIDER) + FRAME_ENHANCER_BLEND_SLIDER.release(update_frame_enhancer_blend, inputs = FRAME_ENHANCER_BLEND_SLIDER) LIP_SYNCER_MODEL_DROPDOWN.change(update_lip_syncer_model, inputs = LIP_SYNCER_MODEL_DROPDOWN, outputs = LIP_SYNCER_MODEL_DROPDOWN) frame_processors_checkbox_group = get_ui_component('frame_processors_checkbox_group') if frame_processors_checkbox_group: diff --git a/facefusion/uis/components/memory.py b/facefusion/uis/components/memory.py index fe0d9723..f67c27ae 100644 --- a/facefusion/uis/components/memory.py +++ b/facefusion/uis/components/memory.py @@ -6,15 +6,15 @@ import facefusion.choices from facefusion.typing import VideoMemoryStrategy from facefusion import wording -VIDEO_MEMORY_STRATEGY : Optional[gradio.Dropdown] = None +VIDEO_MEMORY_STRATEGY_DROPDOWN : Optional[gradio.Dropdown] = None SYSTEM_MEMORY_LIMIT_SLIDER : Optional[gradio.Slider] = None def render() -> None: - global VIDEO_MEMORY_STRATEGY + global VIDEO_MEMORY_STRATEGY_DROPDOWN global SYSTEM_MEMORY_LIMIT_SLIDER - VIDEO_MEMORY_STRATEGY = gradio.Dropdown( + VIDEO_MEMORY_STRATEGY_DROPDOWN = gradio.Dropdown( label = wording.get('uis.video_memory_strategy_dropdown'), choices = facefusion.choices.video_memory_strategies, value = facefusion.globals.video_memory_strategy @@ -29,8 +29,8 @@ def render() -> None: def listen() -> None: - VIDEO_MEMORY_STRATEGY.change(update_video_memory_strategy, inputs = VIDEO_MEMORY_STRATEGY) - SYSTEM_MEMORY_LIMIT_SLIDER.change(update_system_memory_limit, inputs = SYSTEM_MEMORY_LIMIT_SLIDER) + VIDEO_MEMORY_STRATEGY_DROPDOWN.change(update_video_memory_strategy, inputs = VIDEO_MEMORY_STRATEGY_DROPDOWN) + SYSTEM_MEMORY_LIMIT_SLIDER.release(update_system_memory_limit, inputs = SYSTEM_MEMORY_LIMIT_SLIDER) def update_video_memory_strategy(video_memory_strategy : VideoMemoryStrategy) -> None: diff --git a/facefusion/uis/components/output_options.py b/facefusion/uis/components/output_options.py index 0eefcf25..4919920a 100644 --- a/facefusion/uis/components/output_options.py +++ b/facefusion/uis/components/output_options.py @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, List +from typing import Optional, Tuple import gradio import facefusion.globals @@ -6,8 +6,7 @@ import facefusion.choices from facefusion import wording from facefusion.typing import OutputVideoEncoder, OutputVideoPreset, Fps from facefusion.filesystem import is_image, is_video -from facefusion.uis.typing import ComponentName -from facefusion.uis.core import get_ui_component, register_ui_component +from facefusion.uis.core import get_ui_components, register_ui_component from facefusion.vision import detect_image_resolution, create_image_resolutions, detect_video_fps, detect_video_resolution, create_video_resolutions, pack_resolution OUTPUT_PATH_TEXTBOX : Optional[gradio.Textbox] = None @@ -98,23 +97,21 @@ def render() -> None: def listen() -> None: OUTPUT_PATH_TEXTBOX.change(update_output_path, inputs = OUTPUT_PATH_TEXTBOX) - OUTPUT_IMAGE_QUALITY_SLIDER.change(update_output_image_quality, inputs = OUTPUT_IMAGE_QUALITY_SLIDER) + OUTPUT_IMAGE_QUALITY_SLIDER.release(update_output_image_quality, inputs = OUTPUT_IMAGE_QUALITY_SLIDER) OUTPUT_IMAGE_RESOLUTION_DROPDOWN.change(update_output_image_resolution, inputs = OUTPUT_IMAGE_RESOLUTION_DROPDOWN) OUTPUT_VIDEO_ENCODER_DROPDOWN.change(update_output_video_encoder, inputs = OUTPUT_VIDEO_ENCODER_DROPDOWN) OUTPUT_VIDEO_PRESET_DROPDOWN.change(update_output_video_preset, inputs = OUTPUT_VIDEO_PRESET_DROPDOWN) - OUTPUT_VIDEO_QUALITY_SLIDER.change(update_output_video_quality, inputs = OUTPUT_VIDEO_QUALITY_SLIDER) + OUTPUT_VIDEO_QUALITY_SLIDER.release(update_output_video_quality, inputs = OUTPUT_VIDEO_QUALITY_SLIDER) OUTPUT_VIDEO_RESOLUTION_DROPDOWN.change(update_output_video_resolution, inputs = OUTPUT_VIDEO_RESOLUTION_DROPDOWN) OUTPUT_VIDEO_FPS_SLIDER.release(update_output_video_fps, inputs = OUTPUT_VIDEO_FPS_SLIDER) - multi_component_names : List[ComponentName] =\ + + for ui_component in get_ui_components( [ 'target_image', 'target_video' - ] - for component_name in multi_component_names: - component = get_ui_component(component_name) - if component: - for method in [ 'upload', 'change', 'clear' ]: - getattr(component, method)(remote_update, outputs = [ OUTPUT_IMAGE_QUALITY_SLIDER, OUTPUT_IMAGE_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_ENCODER_DROPDOWN, OUTPUT_VIDEO_PRESET_DROPDOWN, OUTPUT_VIDEO_QUALITY_SLIDER, OUTPUT_VIDEO_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_FPS_SLIDER ]) + ]): + for method in [ 'upload', 'change', 'clear' ]: + getattr(ui_component, method)(remote_update, outputs = [ OUTPUT_IMAGE_QUALITY_SLIDER, OUTPUT_IMAGE_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_ENCODER_DROPDOWN, OUTPUT_VIDEO_PRESET_DROPDOWN, OUTPUT_VIDEO_QUALITY_SLIDER, OUTPUT_VIDEO_RESOLUTION_DROPDOWN, OUTPUT_VIDEO_FPS_SLIDER ]) def remote_update() -> Tuple[gradio.Slider, gradio.Dropdown, gradio.Dropdown, gradio.Dropdown, gradio.Slider, gradio.Dropdown, gradio.Slider]: diff --git a/facefusion/uis/components/preview.py b/facefusion/uis/components/preview.py index 5b6468ab..f470f1c5 100755 --- a/facefusion/uis/components/preview.py +++ b/facefusion/uis/components/preview.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional +from typing import Any, Dict, Optional from time import sleep import cv2 import gradio @@ -16,8 +16,7 @@ from facefusion.vision import get_video_frame, count_video_frame_total, normaliz from facefusion.filesystem import is_image, is_video, filter_audio_paths from facefusion.content_analyser import analyse_frame from facefusion.processors.frame.core import load_frame_processor_module -from facefusion.uis.typing import ComponentName -from facefusion.uis.core import get_ui_component, register_ui_component +from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component PREVIEW_IMAGE : Optional[gradio.Image] = None PREVIEW_FRAME_SLIDER : Optional[gradio.Slider] = None @@ -72,54 +71,54 @@ def listen() -> None: reference_face_position_gallery = get_ui_component('reference_face_position_gallery') if reference_face_position_gallery: reference_face_position_gallery.select(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) - multi_one_component_names : List[ComponentName] =\ + + for ui_component in get_ui_components( [ 'source_audio', 'source_image', 'target_image', 'target_video' - ] - for component_name in multi_one_component_names: - component = get_ui_component(component_name) - if component: - for method in [ 'upload', 'change', 'clear' ]: - getattr(component, method)(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) - multi_two_component_names : List[ComponentName] =\ + ]): + for method in [ 'upload', 'change', 'clear' ]: + getattr(ui_component, method)(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) + + for ui_component in get_ui_components( [ 'target_image', 'target_video' - ] - for component_name in multi_two_component_names: - component = get_ui_component(component_name) - if component: - for method in [ 'upload', 'change', 'clear' ]: - getattr(component, method)(update_preview_frame_slider, outputs = PREVIEW_FRAME_SLIDER) - change_one_component_names : List[ComponentName] =\ + ]): + for method in [ 'upload', 'change', 'clear' ]: + getattr(ui_component, method)(update_preview_frame_slider, outputs = PREVIEW_FRAME_SLIDER) + + for ui_component in get_ui_components( [ 'face_debugger_items_checkbox_group', + 'face_selector_mode_dropdown', + 'face_mask_types_checkbox_group', + 'face_mask_region_checkbox_group', + 'face_analyser_order_dropdown', + 'face_analyser_age_dropdown', + 'face_analyser_gender_dropdown' + ]): + ui_component.change(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) + + for ui_component in get_ui_components( + [ 'face_enhancer_blend_slider', 'frame_enhancer_blend_slider', 'trim_frame_start_slider', 'trim_frame_end_slider', - 'face_selector_mode_dropdown', 'reference_face_distance_slider', - 'face_mask_types_checkbox_group', 'face_mask_blur_slider', 'face_mask_padding_top_slider', 'face_mask_padding_bottom_slider', 'face_mask_padding_left_slider', 'face_mask_padding_right_slider', - 'face_mask_region_checkbox_group', - 'face_analyser_order_dropdown', - 'face_analyser_age_dropdown', - 'face_analyser_gender_dropdown', 'output_video_fps_slider' - ] - for component_name in change_one_component_names: - component = get_ui_component(component_name) - if component: - component.change(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) - change_two_component_names : List[ComponentName] =\ + ]): + ui_component.release(update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) + + for ui_component in get_ui_components( [ 'frame_processors_checkbox_group', 'face_enhancer_model_dropdown', @@ -127,14 +126,16 @@ def listen() -> None: 'frame_enhancer_model_dropdown', 'lip_syncer_model_dropdown', 'face_detector_model_dropdown', - 'face_detector_size_dropdown', + 'face_detector_size_dropdown' + ]): + ui_component.change(clear_and_update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) + + for ui_component in get_ui_components( + [ 'face_detector_score_slider', 'face_landmarker_score_slider' - ] - for component_name in change_two_component_names: - component = get_ui_component(component_name) - if component: - component.change(clear_and_update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) + ]): + ui_component.release(clear_and_update_preview_image, inputs = PREVIEW_FRAME_SLIDER, outputs = PREVIEW_IMAGE) def clear_and_update_preview_image(frame_number : int = 0) -> gradio.Image: diff --git a/facefusion/uis/components/trim_frame.py b/facefusion/uis/components/trim_frame.py index bce70e53..3a33b350 100644 --- a/facefusion/uis/components/trim_frame.py +++ b/facefusion/uis/components/trim_frame.py @@ -47,8 +47,8 @@ def render() -> None: def listen() -> None: - TRIM_FRAME_START_SLIDER.change(update_trim_frame_start, inputs = TRIM_FRAME_START_SLIDER) - TRIM_FRAME_END_SLIDER.change(update_trim_frame_end, inputs = TRIM_FRAME_END_SLIDER) + TRIM_FRAME_START_SLIDER.release(update_trim_frame_start, inputs = TRIM_FRAME_START_SLIDER) + TRIM_FRAME_END_SLIDER.release(update_trim_frame_end, inputs = TRIM_FRAME_END_SLIDER) target_video = get_ui_component('target_video') if target_video: for method in [ 'upload', 'change', 'clear' ]: diff --git a/facefusion/uis/components/webcam.py b/facefusion/uis/components/webcam.py index 9f9b967a..e49432a1 100644 --- a/facefusion/uis/components/webcam.py +++ b/facefusion/uis/components/webcam.py @@ -1,4 +1,4 @@ -from typing import Optional, Generator, Deque, List +from typing import Optional, Generator, Deque import os import platform import subprocess @@ -19,8 +19,8 @@ from facefusion.face_analyser import get_average_face from facefusion.processors.frame.core import get_frame_processors_modules, load_frame_processor_module from facefusion.ffmpeg import open_ffmpeg from facefusion.vision import normalize_frame_color, read_static_images, unpack_resolution -from facefusion.uis.typing import StreamMode, WebcamMode, ComponentName -from facefusion.uis.core import get_ui_component +from facefusion.uis.typing import StreamMode, WebcamMode +from facefusion.uis.core import get_ui_component, get_ui_components WEBCAM_CAPTURE : Optional[cv2.VideoCapture] = None WEBCAM_IMAGE : Optional[gradio.Image] = None @@ -76,7 +76,8 @@ def listen() -> None: if webcam_mode_radio and webcam_resolution_dropdown and webcam_fps_slider: start_event = WEBCAM_START_BUTTON.click(start, inputs = [ webcam_mode_radio, webcam_resolution_dropdown, webcam_fps_slider ], outputs = WEBCAM_IMAGE) WEBCAM_STOP_BUTTON.click(stop, cancels = start_event) - change_two_component_names : List[ComponentName] =\ + + for ui_component in get_ui_components( [ 'frame_processors_checkbox_group', 'face_swapper_model_dropdown', @@ -84,11 +85,8 @@ def listen() -> None: 'frame_enhancer_model_dropdown', 'lip_syncer_model_dropdown', 'source_image' - ] - for component_name in change_two_component_names: - component = get_ui_component(component_name) - if component: - component.change(update, cancels = start_event) + ]): + ui_component.change(update, cancels = start_event) def start(webcam_mode : WebcamMode, webcam_resolution : str, webcam_fps : Fps) -> Generator[VisionFrame, None, None]: diff --git a/facefusion/uis/core.py b/facefusion/uis/core.py index 68cdd86e..e5d2e6ff 100644 --- a/facefusion/uis/core.py +++ b/facefusion/uis/core.py @@ -51,14 +51,24 @@ def get_ui_layouts_modules(ui_layouts : List[str]) -> List[ModuleType]: return UI_LAYOUT_MODULES -def get_ui_component(name : ComponentName) -> Optional[Component]: - if name in UI_COMPONENTS: - return UI_COMPONENTS[name] +def get_ui_component(component_name : ComponentName) -> Optional[Component]: + if component_name in UI_COMPONENTS: + return UI_COMPONENTS[component_name] return None -def register_ui_component(name : ComponentName, component: Component) -> None: - UI_COMPONENTS[name] = component +def get_ui_components(component_names : List[ComponentName]) -> Optional[List[Component]]: + ui_components = [] + + for component_name in component_names: + component = get_ui_component(component_name) + if component: + ui_components.append(component) + return ui_components + + +def register_ui_component(component_name : ComponentName, component: Component) -> None: + UI_COMPONENTS[component_name] = component def launch() -> None: