feat(extra-networks): remove view dropdown

This commit is contained in:
Guillermo Moreno 2023-01-22 22:01:24 -03:00
parent 66eef11ce7
commit f80ff3c1e4
2 changed files with 9 additions and 13 deletions

View File

@ -6,13 +6,11 @@ function setupExtraNetworksForTab(tabname){
var search = gradioApp().querySelector('#'+tabname+'_extra_search textarea') var search = gradioApp().querySelector('#'+tabname+'_extra_search textarea')
var refresh = gradioApp().getElementById(tabname+'_extra_refresh') var refresh = gradioApp().getElementById(tabname+'_extra_refresh')
var close = gradioApp().getElementById(tabname+'_extra_close') var close = gradioApp().getElementById(tabname+'_extra_close')
var view = gradioApp().getElementById(tabname+'_extra_view')
search.classList.add('search') search.classList.add('search')
tabs.appendChild(search) tabs.appendChild(search)
tabs.appendChild(refresh) tabs.appendChild(refresh)
tabs.appendChild(close) tabs.appendChild(close)
tabs.appendChild(view)
search.addEventListener("input", function(evt){ search.addEventListener("input", function(evt){
searchTerm = search.value.toLowerCase() searchTerm = search.value.toLowerCase()

View File

@ -25,7 +25,8 @@ class ExtraNetworksPage:
def refresh(self): def refresh(self):
pass pass
def create_html(self, tabname, view=shared.opts.extra_networks_default_view): def create_html(self, tabname):
view = shared.opts.extra_networks_default_view
items_html = '' items_html = ''
for item in self.list_items(): for item in self.list_items():
@ -75,7 +76,6 @@ class ExtraNetworksUi:
self.button_save_preview = None self.button_save_preview = None
self.preview_target_filename = None self.preview_target_filename = None
self.view_dropdown = None
self.tabname = None self.tabname = None
@ -111,7 +111,6 @@ def create_ui(container, button, tabname):
filter = gr.Textbox('', show_label=False, elem_id=tabname+"_extra_search", placeholder="Search...", visible=False) filter = gr.Textbox('', show_label=False, elem_id=tabname+"_extra_search", placeholder="Search...", visible=False)
button_refresh = gr.Button('Refresh', elem_id=tabname+"_extra_refresh") button_refresh = gr.Button('Refresh', elem_id=tabname+"_extra_refresh")
button_close = gr.Button('Close', elem_id=tabname+"_extra_close") button_close = gr.Button('Close', elem_id=tabname+"_extra_close")
ui.view_dropdown = gr.Dropdown(['cards', 'thumbs'], elem_id=tabname+"_extra_view", label="View as", value=lambda: shared.opts.extra_networks_default_view)
ui.button_save_preview = gr.Button('Save preview', elem_id=tabname+"_save_preview", visible=False) ui.button_save_preview = gr.Button('Save preview', elem_id=tabname+"_save_preview", visible=False)
ui.preview_target_filename = gr.Textbox('Preview save filename', elem_id=tabname+"_preview_filename", visible=False) ui.preview_target_filename = gr.Textbox('Preview save filename', elem_id=tabname+"_preview_filename", visible=False)
@ -119,17 +118,16 @@ def create_ui(container, button, tabname):
button.click(fn=lambda: gr.update(visible=True), inputs=[], outputs=[container]) button.click(fn=lambda: gr.update(visible=True), inputs=[], outputs=[container])
button_close.click(fn=lambda: gr.update(visible=False), inputs=[], outputs=[container]) button_close.click(fn=lambda: gr.update(visible=False), inputs=[], outputs=[container])
def refresh(view): def refresh():
res = [] res = []
for pg in ui.stored_extra_pages: for pg in ui.stored_extra_pages:
pg.refresh() pg.refresh()
res.append(pg.create_html(ui.tabname, view)) res.append(pg.create_html(ui.tabname))
return res return res
ui.view_dropdown.change(fn=refresh, inputs=[ui.view_dropdown], outputs=ui.pages) button_refresh.click(fn=refresh, inputs=[], outputs=ui.pages)
button_refresh.click(fn=refresh, inputs=[ui.view_dropdown], outputs=ui.pages)
return ui return ui
@ -142,7 +140,7 @@ def path_is_parent(parent_path, child_path):
def setup_ui(ui, gallery): def setup_ui(ui, gallery):
def save_preview(index, images, filename, view): def save_preview(index, images, filename):
if len(images) == 0: if len(images) == 0:
print("There is no image in gallery to save as a preview.") print("There is no image in gallery to save as a preview.")
return [page.create_html(ui.tabname) for page in ui.stored_extra_pages] return [page.create_html(ui.tabname) for page in ui.stored_extra_pages]
@ -164,11 +162,11 @@ def setup_ui(ui, gallery):
image.save(filename) image.save(filename)
return [page.create_html(ui.tabname, view) for page in ui.stored_extra_pages] return [page.create_html(ui.tabname) for page in ui.stored_extra_pages]
ui.button_save_preview.click( ui.button_save_preview.click(
fn=save_preview, fn=save_preview,
_js="function(x, y, z, a){console.log(x, y, z, a); return [selected_gallery_index(), y, z, a]}", _js="function(x, y, z){console.log(x, y, z); return [selected_gallery_index(), y, z]}",
inputs=[ui.preview_target_filename, gallery, ui.preview_target_filename, ui.view_dropdown], inputs=[ui.preview_target_filename, gallery, ui.preview_target_filename],
outputs=[*ui.pages] outputs=[*ui.pages]
) )