Skip to content

Commit

Permalink
possible fix for reload button not appearing in some cases for extra …
Browse files Browse the repository at this point in the history
…networks.
  • Loading branch information
AUTOMATIC1111 committed Feb 22, 2024
1 parent 0a27193 commit 1da0529
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,15 @@ def _build_tree(data: Optional[dict[str, ExtraNetworksItem]] = None) -> Optional

return f"<ul class='tree-list tree-list--tree'>{res}</ul>"

def create_card_view_html(self, tabname: str) -> str:
def create_card_view_html(self, tabname: str, *, none_message) -> str:
"""Generates HTML for the network Card View section for a tab.
This HTML goes into the `extra-networks-pane.html` <div> with
`id='{tabname}_{extra_networks_tabname}_cards`.
Args:
tabname: The name of the active tab.
none_message: HTML text to show when there are no cards.
Returns:
HTML formatted string.
Expand All @@ -490,24 +491,28 @@ def create_card_view_html(self, tabname: str) -> str:

if res == "":
dirs = "".join([f"<li>{x}</li>" for x in self.allowed_directories_for_previews()])
res = shared.html("extra-networks-no-cards.html").format(dirs=dirs)
res = none_message or shared.html("extra-networks-no-cards.html").format(dirs=dirs)

return res

def create_html(self, tabname):
def create_html(self, tabname, *, empty=False):
"""Generates an HTML string for the current pane.
The generated HTML uses `extra-networks-pane.html` as a template.
Args:
tabname: The name of the active tab.
empty: create an empty HTML page with no items
Returns:
HTML formatted string.
"""
self.lister.reset()
self.metadata = {}
self.items = {x["name"]: x for x in self.list_items()}

items_list = [] if empty else self.list_items()
self.items = {x["name"]: x for x in items_list}

# Populate the instance metadata for each item.
for item in self.items.values():
metadata = item.get("metadata")
Expand Down Expand Up @@ -536,7 +541,7 @@ def create_html(self, tabname):
"tree_view_btn_extra_class": tree_view_btn_extra_class,
"tree_view_div_extra_class": tree_view_div_extra_class,
"tree_html": self.create_tree_view_html(tabname),
"items_html": self.create_card_view_html(tabname),
"items_html": self.create_card_view_html(tabname, none_message="Loading..." if empty else None),
}
)

Expand Down Expand Up @@ -655,7 +660,7 @@ def create_ui(interface: gr.Blocks, unrelated_tabs, tabname):
pass

elem_id = f"{tabname}_{page.extra_networks_tabname}_cards_html"
page_elem = gr.HTML('Loading...', elem_id=elem_id)
page_elem = gr.HTML(page.create_html(tabname, empty=True), elem_id=elem_id)
ui.pages.append(page_elem)
editor = page.create_user_metadata_editor(ui, tabname)
editor.create_ui()
Expand Down

0 comments on commit 1da0529

Please sign in to comment.