Skip to content

Conversation

@w-e-w
Copy link
Collaborator

@w-e-w w-e-w commented Nov 27, 2023

Description

allow insert components using on_before/after_component_elem_id or before/after_component from extensions to before / after a Block
this is not previously possible because the callback is not called for Blocks
this PR allows this

Example

insert befor and after txt2img_hires_fix_row4

with FormRow(elem_id="txt2img_hires_fix_row4", variant="compact", visible=opts.hires_fix_show_prompts) as hr_prompts_container:

insert hear
image

like so

image

Demo extention script

from modules import scripts
import gradio as gr


class Script(scripts.Script):
    before_cb = None
    after_cb = None
    
    def title(self):
        return "block insert component demo"

    def show(self, is_img2img):
        if not is_img2img:
            self.on_before_component_elem_id = [
                ('txt2img_hires_fix_row4', self.before_hires_fix_extended_ui),
            ]
            self.on_after_component_elem_id = [
                ('txt2img_hires_fix_row4', self.after_hires_fix_extended_ui),
            ]
            return scripts.AlwaysVisible

    def ui(self, is_img2img):
        if self.before_cb and self.after_cb:
            return [self.before_cb, self.after_cb]

    def before_process(self, p, *args):
        print(*args)

    def before_hires_fix_extended_ui(self, *args, **kwargs):
        with gr.Accordion(label='Before'):
            self.before_cb = gr.Checkbox(label='Before Checkbox')

    def after_hires_fix_extended_ui(self, *args, **kwargs):
        with gr.Accordion(label='After'):
            self.after_cb = gr.Checkbox(label='After Checkbox')

Checklist:

@AUTOMATIC1111 AUTOMATIC1111 merged commit 97c8e7e into dev Dec 2, 2023
@AUTOMATIC1111 AUTOMATIC1111 deleted the add-Block-component-creation-callback branch December 2, 2023 06:45
@w-e-w w-e-w mentioned this pull request Dec 4, 2023
@w-e-w w-e-w mentioned this pull request Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants