@@ -85,7 +85,7 @@ def set_lightdiffusionflow_file():
8585再用json2js的onchange事件触发js来点击隐藏按钮开始触发设置图片的事件队列。
8686'''
8787def on_after_component (component , ** kwargs ):
88-
88+
8989 try :
9090 if (Webui_Comps .get (kwargs ["elem_id" ], None ) == None ):
9191 Webui_Comps [kwargs ["elem_id" ]] = component
@@ -419,13 +419,49 @@ class Script(scripts.Script):
419419
420420 def __init__ (self ) -> None :
421421 super ().__init__ ()
422+ #记录无id元素的id
423+ self .new_ids = {}
422424
423425 def title (self ):
424426 return "lightdiffusionflow plugin"
425427
426428 def show (self , is_img2img ):
427429 return scripts .AlwaysVisible
428430
431+ def after_component (self , component , ** kwargs ):
432+ #当前模式
433+ teb_mode = "img2img" if self .is_img2img else "txt2img"
434+ #空id补全方法
435+ def in_zone (dom ,id = "" ):
436+ if dom :
437+ if dom .elem_id :
438+ id += "-" + dom .elem_id
439+ return in_zone (dom .parent ,id )
440+ elif dom .elem_classes and dom .elem_classes [0 ]!= 'gradio-blocks' :
441+ if dom .elem_classes [0 ]== 'gradio-accordion' :
442+ id += '-' + dom .label + "?"
443+ return in_zone (dom .parent ,id )
444+ if re .search ('2img_(textual|hypernetworks|checkpoints|lora)_' ,id ):
445+ return False
446+ else :
447+ id = re .sub (r'\?[^\?]+$|[ \?]' ,'' ,id )
448+ if id in self .new_ids :
449+ self .new_ids [id ]+= 1
450+ else :
451+ self .new_ids [id ]= 1
452+ return id + '-' + str (self .new_ids [id ])
453+
454+ #记录组件
455+ try :
456+ #拉取id
457+ id = component .elem_id
458+ #若没有就重构
459+ if id == None :
460+ id = component .elem_id == in_zone (component .parent ,teb_mode )
461+ Webui_Comps [id ] = component
462+ except BaseException as e :
463+ pass
464+
429465 def ui (self , is_img2img ):
430466 global File_extension
431467
@@ -486,4 +522,4 @@ def on_before_reload():
486522api = StateApi ()
487523script_callbacks .on_app_started (api .start )
488524script_callbacks .on_after_component (on_after_component )
489- script_callbacks .on_before_reload (on_before_reload )
525+ script_callbacks .on_before_reload (on_before_reload )
0 commit comments