mirror of
https://github.com/sd-webui/stable-diffusion-webui.git
synced 2024-12-14 23:02:00 +03:00
added proto file uploader, began cleanup
This commit is contained in:
parent
18a3b80927
commit
b47974c985
3
.gitignore
vendored
3
.gitignore
vendored
@ -59,14 +59,15 @@ condaenv.*.requirements.txt
|
|||||||
!/src/components/*
|
!/src/components/*
|
||||||
!/src/pages/*
|
!/src/pages/*
|
||||||
/src/*
|
/src/*
|
||||||
/inputs
|
|
||||||
/outputs
|
/outputs
|
||||||
/model_cache
|
/model_cache
|
||||||
/log/**/*.png
|
/log/**/*.png
|
||||||
|
/log/webui/*
|
||||||
/log/log.csv
|
/log/log.csv
|
||||||
/flagged/*
|
/flagged/*
|
||||||
/gfpgan/*
|
/gfpgan/*
|
||||||
/models/*
|
/models/*
|
||||||
|
/assets/*
|
||||||
z_version_env.tmp
|
z_version_env.tmp
|
||||||
scripts/bridgeData.py
|
scripts/bridgeData.py
|
||||||
/user_data/*
|
/user_data/*
|
||||||
|
@ -176,7 +176,9 @@ performance_page:
|
|||||||
keep_all_models_loaded:
|
keep_all_models_loaded:
|
||||||
display: bool
|
display: bool
|
||||||
value: !!bool 'false'
|
value: !!bool 'false'
|
||||||
#no_verify_input: False
|
no_verify_input:
|
||||||
|
display: bool
|
||||||
|
value: !!bool 'false'
|
||||||
#no_half: False
|
#no_half: False
|
||||||
#use_float16: False
|
#use_float16: False
|
||||||
#precision: "autocast"
|
#precision: "autocast"
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
@ -12,7 +12,138 @@ import webui_flet_utils
|
|||||||
# for debugging
|
# for debugging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
# custom classes
|
||||||
|
class LayerManager(ft.Container):
|
||||||
|
def update_layer_indexes(self):
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
index = 0
|
||||||
|
for layer in layer_list:
|
||||||
|
if layer.data['type'] == 'slot':
|
||||||
|
layer.data['index'] = index
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
def update_active_layer_list(self):
|
||||||
|
self.data['active_layer_list'] = []
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
for layer in layer_list:
|
||||||
|
if layer.data['type'] == 'slot':
|
||||||
|
if layer.content.content.controls[1].data['visible']:
|
||||||
|
self.data['active_layer_list'].append(layer)
|
||||||
|
|
||||||
|
def move_layer_slot(self, index):
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
self.data['layer_being_moved'] = layer_list.pop(index)
|
||||||
|
self.data['layer_last_index'] = index
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
def insert_layer_slot(self, index):
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
layer_list.insert(index,self.data['layer_being_moved'])
|
||||||
|
self.data['layer_being_moved'] = None
|
||||||
|
self.data['layer_last_index'] = -1
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
def update_layers(self):
|
||||||
|
self.data['layer_list'] = self.content.content.controls
|
||||||
|
self.update_layer_indexes()
|
||||||
|
self.update_active_layer_list()
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def show_hide_layer(self, e):
|
||||||
|
parent = e.control.data['parent']
|
||||||
|
if parent.data['visible']:
|
||||||
|
parent.data['visible'] = False
|
||||||
|
parent.opacity = 0.5
|
||||||
|
e.control.icon = ft.icons.VISIBILITY_OFF
|
||||||
|
else:
|
||||||
|
parent.data['visible'] = True
|
||||||
|
parent.opacity = 1.0
|
||||||
|
e.control.icon = ft.icons.VISIBILITY
|
||||||
|
self.update_active_layer_list()
|
||||||
|
parent.update()
|
||||||
|
|
||||||
|
def layer_slot_will_accept(self, e):
|
||||||
|
if not self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
index = e.control.data['index']
|
||||||
|
e.control.show_layer_spacer()
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
def layer_slot_accept(self, e):
|
||||||
|
if not self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
index = e.control.data['index']
|
||||||
|
e.control.hide_layer_spacer()
|
||||||
|
self.insert_layer_slot(index)
|
||||||
|
|
||||||
|
def layer_slot_leave(self, e):
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
index = e.control.data['index']
|
||||||
|
e.control.hide_layer_spacer()
|
||||||
|
if self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
self.move_layer_slot(index)
|
||||||
|
|
||||||
|
## tab controls
|
||||||
|
def layer_will_accept(self, e):
|
||||||
|
if not self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
if layer_list:
|
||||||
|
if layer_list[-1].data['type'] != 'spacer':
|
||||||
|
layer_list.append(ft.Container(
|
||||||
|
content = ft.Divider(height = 10,color = ft.colors.BLACK),
|
||||||
|
data = {'type':'spacer'}
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
layer_list.append(ft.Container(
|
||||||
|
content = ft.Divider(height = 10,color = ft.colors.BLACK),
|
||||||
|
data = {'type':'spacer'}
|
||||||
|
))
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
def layer_accept(self, e):
|
||||||
|
if not self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
if layer_list:
|
||||||
|
if layer_list[-1].data['type'] == 'spacer':
|
||||||
|
layer_list.pop(-1)
|
||||||
|
layer_list.append(self.data['layer_being_moved'])
|
||||||
|
self.data['layer_being_moved'] = None
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
def layer_leave(self, e):
|
||||||
|
if not self.data['layer_being_moved']:
|
||||||
|
return
|
||||||
|
layer_list = self.data['layer_list']
|
||||||
|
if layer_list:
|
||||||
|
if layer_list[-1].data['type'] == 'spacer':
|
||||||
|
layer_list.pop(-1)
|
||||||
|
self.update_layers()
|
||||||
|
|
||||||
|
|
||||||
|
class LayerSlot(ft.DragTarget):
|
||||||
|
def set_layer_slot_name(self, name):
|
||||||
|
self.content.content.controls[1].content.controls[1].value = name
|
||||||
|
|
||||||
|
def show_layer_spacer(self):
|
||||||
|
if not self.data['has_spacer']:
|
||||||
|
self.data['has_spacer'] = True
|
||||||
|
self.content.content.controls[0].visible = True
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def hide_layer_spacer(self):
|
||||||
|
if self.data['has_spacer']:
|
||||||
|
self.data['has_spacer'] = False
|
||||||
|
self.content.content.controls[0].visible = False
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# main ###############################################################
|
||||||
@logger.catch(reraise=True)
|
@logger.catch(reraise=True)
|
||||||
def main(page: ft.Page):
|
def main(page: ft.Page):
|
||||||
|
|
||||||
@ -44,7 +175,8 @@ def main(page: ft.Page):
|
|||||||
if 'webui_page' in settings:
|
if 'webui_page' in settings:
|
||||||
if 'default_theme' in settings['webui_page']:
|
if 'default_theme' in settings['webui_page']:
|
||||||
page.theme_mode = settings['webui_page']['default_theme']['value']
|
page.theme_mode = settings['webui_page']['default_theme']['value']
|
||||||
MAX_MESSAGE_HISTORY = settings['webui_page']['max_message_history']['value']
|
if 'max_message_history' in settings['webui_page']:
|
||||||
|
MAX_MESSAGE_HISTORY = settings['webui_page']['max_message_history']['value']
|
||||||
|
|
||||||
page.session.set('layout','default')
|
page.session.set('layout','default')
|
||||||
|
|
||||||
@ -237,6 +369,7 @@ def main(page: ft.Page):
|
|||||||
#on_dismiss=lambda e: print("Modal dialog dismissed!"),
|
#on_dismiss=lambda e: print("Modal dialog dismissed!"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# gallery window #####################################################
|
# gallery window #####################################################
|
||||||
def close_gallery_window(e):
|
def close_gallery_window(e):
|
||||||
gallery_window.open = False
|
gallery_window.open = False
|
||||||
@ -274,6 +407,79 @@ def main(page: ft.Page):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# upload window ######################################################
|
||||||
|
def close_upload_window(e):
|
||||||
|
upload_window.open = False
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def open_upload_window(e):
|
||||||
|
page.dialog = upload_window
|
||||||
|
upload_window.open = True
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def upload_file(e):
|
||||||
|
if page.file_picker.result and page.file_picker.result.files:
|
||||||
|
file_list = []
|
||||||
|
for f in page.file_picker.result.files:
|
||||||
|
upload_url = page.get_upload_url(f.name, 600)
|
||||||
|
img = ft.FilePickerUploadFile(f.name,upload_url)
|
||||||
|
file_list.append(img)
|
||||||
|
page.file_picker.upload(file_list)
|
||||||
|
close_upload_window(e)
|
||||||
|
|
||||||
|
upload_window = ft.AlertDialog(
|
||||||
|
title = ft.Text("Confirm file upload"),
|
||||||
|
content = None,
|
||||||
|
#modal = True,
|
||||||
|
actions_alignment = "center",
|
||||||
|
actions = [
|
||||||
|
ft.ElevatedButton("UPLOAD", on_click = upload_file),
|
||||||
|
ft.TextButton("CANCEL", on_click = close_upload_window),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# import window ######################################################
|
||||||
|
def close_import_window(e):
|
||||||
|
import_window.open = False
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def open_import_window(e):
|
||||||
|
page.dialog = import_window
|
||||||
|
gallery_window.open = True
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def import_file(e):
|
||||||
|
close_import_window(e)
|
||||||
|
pass
|
||||||
|
|
||||||
|
import_window = ft.AlertDialog(
|
||||||
|
title=ft.Text("Confirm file import"),
|
||||||
|
content=ft.Text("import this file?"),
|
||||||
|
modal=True,
|
||||||
|
actions_alignment="center",
|
||||||
|
actions=[
|
||||||
|
ft.ElevatedButton("IMPORT", on_click = import_file),
|
||||||
|
ft.TextButton("CANCEL", on_click = close_import_window),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# progress bar #######################################################
|
||||||
|
def close_progress_bar(e):
|
||||||
|
page.splash.visible = False
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def open_progress_bar(e):
|
||||||
|
page.splash.visible = True
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
page.splash = ft.ProgressBar(
|
||||||
|
visible = False,
|
||||||
|
color = 'blue',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# layouts ############################################################
|
# layouts ############################################################
|
||||||
def change_layout(e):
|
def change_layout(e):
|
||||||
page.session.set('layout',e.control.value)
|
page.session.set('layout',e.control.value)
|
||||||
@ -422,15 +628,6 @@ def main(page: ft.Page):
|
|||||||
height = 50,
|
height = 50,
|
||||||
)
|
)
|
||||||
|
|
||||||
# menu_button = ft.PopupMenuButton(
|
|
||||||
#items = [
|
|
||||||
# #ft.PopupMenuItem(text="Settings", on_click=open_settings_modal),
|
|
||||||
# ft.PopupMenuItem(), # divider
|
|
||||||
# #ft.PopupMenuItem(text="Checked item", checked=False, on_click=check_item_clicked),
|
|
||||||
#],
|
|
||||||
#height = 50,
|
|
||||||
# )
|
|
||||||
|
|
||||||
option_list = ft.Row(
|
option_list = ft.Row(
|
||||||
controls = [
|
controls = [
|
||||||
#ft.Container(expand=True, content = current_layout_options),
|
#ft.Container(expand=True, content = current_layout_options),
|
||||||
@ -456,13 +653,34 @@ def main(page: ft.Page):
|
|||||||
|
|
||||||
|
|
||||||
# toolbar ############################################################
|
# toolbar ############################################################
|
||||||
def add_blank_layer(e):
|
file_path = None
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
layer_slot = make_layer_slot()
|
def pick_images(e: ft.FilePickerResultEvent):
|
||||||
layer_slot.data['image'] = webui_flet_utils.create_blank_image()
|
# check to see if on browser or running natively
|
||||||
layer_list.append(layer_slot)
|
if e.files is not None and e.path is None:
|
||||||
message("added blank layer to canvas")
|
if not e.page.web:
|
||||||
update_layer_manager()
|
file_path = e.files[0].path
|
||||||
|
open_import_window(e)
|
||||||
|
else:
|
||||||
|
open_upload_window(e)
|
||||||
|
|
||||||
|
def on_image_upload(e: ft.FilePickerUploadEvent):
|
||||||
|
if e.error:
|
||||||
|
message("Upload error occurred! Try again.",1)
|
||||||
|
return
|
||||||
|
open_progress_bar(e)
|
||||||
|
if e.progress == 1:
|
||||||
|
# add image as new layer here
|
||||||
|
message(f'Downloaded {e.file_name} successfully!')
|
||||||
|
close_progress_bar(e)
|
||||||
|
print('yay')
|
||||||
|
|
||||||
|
page.file_picker = ft.FilePicker(
|
||||||
|
on_result = pick_images,
|
||||||
|
on_upload = on_image_upload
|
||||||
|
)
|
||||||
|
|
||||||
|
page.overlay.append(page.file_picker)
|
||||||
|
|
||||||
def add_images_as_layers(images):
|
def add_images_as_layers(images):
|
||||||
layer_list = layer_manager.data['layer_list']
|
layer_list = layer_manager.data['layer_list']
|
||||||
@ -472,26 +690,15 @@ def main(page: ft.Page):
|
|||||||
layer_slot.data['image'] = img.data
|
layer_slot.data['image'] = img.data
|
||||||
layer_list.append(layer_slot)
|
layer_list.append(layer_slot)
|
||||||
message(f'added "{img.name}" as layer')
|
message(f'added "{img.name}" as layer')
|
||||||
update_layer_manager()
|
layer_manager.update_layers()
|
||||||
|
|
||||||
def pick_images(e: ft.FilePickerResultEvent):
|
def add_blank_layer(e):
|
||||||
images = {}
|
layer_list = layer_manager.data['layer_list']
|
||||||
for f in e.files:
|
layer_slot = make_layer_slot()
|
||||||
images.update({f.name:vars(f)})
|
layer_slot.data['image'] = webui_flet_utils.create_blank_image()
|
||||||
images_loaded, images_not_loaded = webui_flet_utils.load_images(images)
|
layer_list.append(layer_slot)
|
||||||
add_images_as_layers(images_loaded)
|
message("added blank layer to canvas")
|
||||||
if images_not_loaded:
|
layer_manager.update_layers()
|
||||||
for img in images_not_loaded:
|
|
||||||
message(f'image not loaded: {img}',1)
|
|
||||||
|
|
||||||
def load_images(e):
|
|
||||||
add_images_dialog.pick_files(file_type = 'image', allow_multiple = True)
|
|
||||||
|
|
||||||
add_images_dialog = ft.FilePicker(
|
|
||||||
on_result = pick_images,
|
|
||||||
)
|
|
||||||
|
|
||||||
page.overlay.append(add_images_dialog)
|
|
||||||
|
|
||||||
open_gallery_button = ft.IconButton(
|
open_gallery_button = ft.IconButton(
|
||||||
width = 50,
|
width = 50,
|
||||||
@ -511,7 +718,7 @@ def main(page: ft.Page):
|
|||||||
width = 50,
|
width = 50,
|
||||||
content = ft.Icon(ft.icons.IMAGE_OUTLINED),
|
content = ft.Icon(ft.icons.IMAGE_OUTLINED),
|
||||||
tooltip = 'load image(s) as new layer(s)',
|
tooltip = 'load image(s) as new layer(s)',
|
||||||
on_click = load_images,
|
on_click = lambda _: page.file_picker.pick_files(file_type = 'image', allow_multiple = True),
|
||||||
)
|
)
|
||||||
|
|
||||||
universal_tools = ft.Row(
|
universal_tools = ft.Row(
|
||||||
@ -565,147 +772,39 @@ def main(page: ft.Page):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# layer manager ######################################################
|
# layer manager ######################################################
|
||||||
def update_layer_manager():
|
layer_manager = LayerManager(
|
||||||
update_layer_indexes()
|
content = None,
|
||||||
update_active_layer_list()
|
padding = ft.padding.only(top = 4),
|
||||||
layer_manager.update()
|
bgcolor = ft.colors.WHITE10,
|
||||||
|
data = {
|
||||||
def update_active_layer_list():
|
'layer_list': [],
|
||||||
layer_manager.data['active_layer_list'] = []
|
'active_layer_list': [],
|
||||||
layer_list = layer_manager.data['layer_list']
|
'layer_being_moved': None,
|
||||||
for layer in layer_list:
|
'layer_last_index': -1,
|
||||||
if layer.data['type'] == 'slot':
|
},
|
||||||
if layer.content.content.controls[1].data['visible']:
|
)
|
||||||
layer_manager.data['active_layer_list'].append(layer)
|
|
||||||
|
|
||||||
def update_layer_indexes():
|
def layer_right_click():
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
index = 0
|
|
||||||
for layer in layer_list:
|
|
||||||
if layer.data['type'] == 'slot':
|
|
||||||
layer.data['index'] = index
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
def move_layer_slot(index):
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
layer_manager.data['layer_being_moved'] = layer_list.pop(index)
|
|
||||||
layer_manager.data['layer_last_index'] = index
|
|
||||||
update_layer_manager()
|
|
||||||
|
|
||||||
def insert_layer_slot(index):
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
layer_list.insert(index,layer_manager.data['layer_being_moved'])
|
|
||||||
layer_manager.data['layer_being_moved'] = None
|
|
||||||
layer_manager.data['layer_last_index'] = -1
|
|
||||||
update_layer_manager()
|
|
||||||
|
|
||||||
# layer slot controls
|
|
||||||
def set_layer_slot_name(slot, name):
|
|
||||||
slot.content.content.controls[1].content.controls[1].value = name
|
|
||||||
|
|
||||||
def show_hide_layer(e):
|
|
||||||
parent = e.control.data['parent']
|
|
||||||
if parent.data['visible']:
|
|
||||||
parent.data['visible'] = False
|
|
||||||
parent.opacity = 0.5
|
|
||||||
e.control.icon = ft.icons.VISIBILITY_OFF
|
|
||||||
else:
|
|
||||||
parent.data['visible'] = True
|
|
||||||
parent.opacity = 1.0
|
|
||||||
e.control.icon = ft.icons.VISIBILITY
|
|
||||||
update_active_layer_list()
|
|
||||||
parent.update()
|
|
||||||
|
|
||||||
def show_layer_spacer(e):
|
|
||||||
if not e.control.data['has_spacer']:
|
|
||||||
e.control.data['has_spacer'] = True
|
|
||||||
e.control.content.content.controls[0].visible = True
|
|
||||||
e.control.update()
|
|
||||||
|
|
||||||
def hide_layer_spacer(e):
|
|
||||||
if e.control.data['has_spacer']:
|
|
||||||
e.control.data['has_spacer'] = False
|
|
||||||
e.control.content.content.controls[0].visible = False
|
|
||||||
e.control.update()
|
|
||||||
|
|
||||||
def layer_right_click(e):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def layer_slot_will_accept(e):
|
def make_layer_holder():
|
||||||
if not layer_manager.data['layer_being_moved']:
|
layer_holder = ft.DragTarget(
|
||||||
return
|
group = 'layer',
|
||||||
layer_list = layer_manager.data['layer_list']
|
content = ft.Column(
|
||||||
index = e.control.data['index']
|
spacing = 0,
|
||||||
show_layer_spacer(e)
|
scroll = 'hidden',
|
||||||
update_layer_manager()
|
controls = [],
|
||||||
|
),
|
||||||
def layer_slot_accept(e):
|
on_will_accept = layer_manager.layer_will_accept,
|
||||||
if not layer_manager.data['layer_being_moved']:
|
on_accept = layer_manager.layer_accept,
|
||||||
return
|
on_leave = layer_manager.layer_leave,
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
index = e.control.data['index']
|
|
||||||
hide_layer_spacer(e)
|
|
||||||
insert_layer_slot(index)
|
|
||||||
|
|
||||||
def layer_slot_leave(e):
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
index = e.control.data['index']
|
|
||||||
hide_layer_spacer(e)
|
|
||||||
if layer_manager.data['layer_being_moved']:
|
|
||||||
return
|
|
||||||
move_layer_slot(index)
|
|
||||||
|
|
||||||
|
|
||||||
## tab layer controls
|
|
||||||
def layer_will_accept(e):
|
|
||||||
if not layer_manager.data['layer_being_moved']:
|
|
||||||
return
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
if layer_list:
|
|
||||||
if layer_list[-1].data['type'] != 'spacer':
|
|
||||||
layer_list.append(make_layer_spacer())
|
|
||||||
else:
|
|
||||||
layer_list.append(make_layer_spacer())
|
|
||||||
update_layer_manager()
|
|
||||||
|
|
||||||
def layer_accept(e):
|
|
||||||
if not layer_manager.data['layer_being_moved']:
|
|
||||||
return
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
if layer_list:
|
|
||||||
if layer_list[-1].data['type'] == 'spacer':
|
|
||||||
layer_list.pop(-1)
|
|
||||||
layer_list.append(layer_manager.data['layer_being_moved'])
|
|
||||||
layer_manager.data['layer_being_moved'] = None
|
|
||||||
update_layer_manager()
|
|
||||||
|
|
||||||
def layer_leave(e):
|
|
||||||
if not layer_manager.data['layer_being_moved']:
|
|
||||||
return
|
|
||||||
layer_list = layer_manager.data['layer_list']
|
|
||||||
if layer_list:
|
|
||||||
if layer_list[-1].data['type'] == 'spacer':
|
|
||||||
layer_list.pop(-1)
|
|
||||||
update_layer_manager()
|
|
||||||
|
|
||||||
def make_layer_spacer():
|
|
||||||
layer_spacer = ft.Container(
|
|
||||||
content = ft.Divider(
|
|
||||||
height = 10,
|
|
||||||
color = ft.colors.BLACK
|
|
||||||
),
|
|
||||||
data = {
|
|
||||||
'type':'spacer',
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
return layer_spacer
|
return layer_holder
|
||||||
|
|
||||||
|
|
||||||
# layer displays
|
|
||||||
def make_layer_display():
|
def make_layer_display():
|
||||||
try:
|
try:
|
||||||
make_layer_display.count += 1
|
make_layer_display.count += 1
|
||||||
except Exception:
|
except AttributeError:
|
||||||
make_layer_display.count = 1
|
make_layer_display.count = 1
|
||||||
|
|
||||||
layer_display = ft.Column(
|
layer_display = ft.Column(
|
||||||
@ -734,7 +833,7 @@ def main(page: ft.Page):
|
|||||||
layer_icon = ft.IconButton(
|
layer_icon = ft.IconButton(
|
||||||
icon = ft.icons.VISIBILITY,
|
icon = ft.icons.VISIBILITY,
|
||||||
tooltip = 'show/hide',
|
tooltip = 'show/hide',
|
||||||
on_click = show_hide_layer,
|
on_click = layer_manager.show_hide_layer,
|
||||||
data = {'parent':layer_display.controls[1]},
|
data = {'parent':layer_display.controls[1]},
|
||||||
)
|
)
|
||||||
layer_label = ft.TextField(
|
layer_label = ft.TextField(
|
||||||
@ -752,20 +851,20 @@ def main(page: ft.Page):
|
|||||||
tooltip = 'drag to move',
|
tooltip = 'drag to move',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
on_secondary_tap = layer_right_click,
|
on_secondary_tap = layer_right_click
|
||||||
)
|
)
|
||||||
layer_display.controls[1].content.controls.extend([layer_icon,layer_label,layer_handle])
|
layer_display.controls[1].content.controls.extend([layer_icon,layer_label,layer_handle])
|
||||||
return layer_display
|
return layer_display
|
||||||
|
|
||||||
def make_layer_slot():
|
def make_layer_slot():
|
||||||
layer_slot = ft.DragTarget(
|
layer_slot = LayerSlot(
|
||||||
group = 'layer',
|
group = 'layer',
|
||||||
content = ft.Container(
|
content = ft.Container(
|
||||||
content = make_layer_display(),
|
content = make_layer_display(),
|
||||||
),
|
),
|
||||||
on_will_accept = layer_slot_will_accept,
|
on_will_accept = layer_manager.layer_slot_will_accept,
|
||||||
on_accept = layer_slot_accept,
|
on_accept = layer_manager.layer_slot_accept,
|
||||||
on_leave = layer_slot_leave,
|
on_leave = layer_manager.layer_slot_leave,
|
||||||
data = {
|
data = {
|
||||||
'index': -1,
|
'index': -1,
|
||||||
'type': 'slot',
|
'type': 'slot',
|
||||||
@ -775,28 +874,7 @@ def main(page: ft.Page):
|
|||||||
)
|
)
|
||||||
return layer_slot
|
return layer_slot
|
||||||
|
|
||||||
layer_manager = ft.Container(
|
layer_manager.content = make_layer_holder()
|
||||||
content = ft.DragTarget(
|
|
||||||
group = 'layer',
|
|
||||||
content = ft.Column(
|
|
||||||
spacing = 0,
|
|
||||||
scroll = 'hidden',
|
|
||||||
controls = [],
|
|
||||||
),
|
|
||||||
on_will_accept = layer_will_accept,
|
|
||||||
on_accept = layer_accept,
|
|
||||||
on_leave = layer_leave,
|
|
||||||
),
|
|
||||||
padding = ft.padding.only(top = 4),
|
|
||||||
bgcolor = ft.colors.WHITE10,
|
|
||||||
data = {
|
|
||||||
'layer_list': [],
|
|
||||||
'active_layer_list': [],
|
|
||||||
'layer_being_moved': None,
|
|
||||||
'layer_last_index': -1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
layer_manager.data['layer_list'] = layer_manager.content.content.controls
|
|
||||||
|
|
||||||
|
|
||||||
# asset manager ######################################################
|
# asset manager ######################################################
|
||||||
@ -1201,7 +1279,9 @@ def main(page: ft.Page):
|
|||||||
# workspace ##########################################################
|
# workspace ##########################################################
|
||||||
def draggable_out_of_bounds(e):
|
def draggable_out_of_bounds(e):
|
||||||
if e.data == 'false':
|
if e.data == 'false':
|
||||||
layer_accept(e)
|
if layer_manager.data['layer_being_moved']:
|
||||||
|
index = layer_manager.data['layer_being_moved'].data['index']
|
||||||
|
layer_manager.insert_layer_slot(index)
|
||||||
|
|
||||||
catchall = ft.DragTarget(
|
catchall = ft.DragTarget(
|
||||||
group = 'catchall',
|
group = 'catchall',
|
||||||
@ -1231,9 +1311,7 @@ def main(page: ft.Page):
|
|||||||
)
|
)
|
||||||
|
|
||||||
page.title = "Stable Diffusion Playground"
|
page.title = "Stable Diffusion Playground"
|
||||||
page.theme_mode = "dark"
|
|
||||||
page.add(full_page)
|
page.add(full_page)
|
||||||
|
layer_manager.update_layers()
|
||||||
|
|
||||||
|
ft.app(target=main, port= 8505, assets_dir="assets", upload_dir="assets/uploads")
|
||||||
|
|
||||||
ft.app(target=main, port=8505)
|
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
# webui_utils.py
|
# webui_utils.py
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, yaml
|
import os, yaml, js2py
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from datetime import datetime
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
# logging
|
# logging
|
||||||
log_file = 'webui_flet.log'
|
|
||||||
|
|
||||||
def log_message(message):
|
def log_message(message):
|
||||||
|
log_file = None
|
||||||
|
# get time and format message
|
||||||
|
prefix = datetime.now()
|
||||||
|
msg_prefix = prefix.strftime("%Y/%m/%d %H:%M:%S")
|
||||||
|
message = msg_prefix + message
|
||||||
|
# check to see if we're appending to current logfile or making a new one'
|
||||||
|
try:
|
||||||
|
log_file = log_message.log
|
||||||
|
except AttributeError:
|
||||||
|
log_prefix = prefix.strftime("%Y%m%d_%H%M%S")
|
||||||
|
log_message.log = os.path.join('logs/webui/',log_prefix+'webui_flet.log')
|
||||||
|
log_file = log_message.log
|
||||||
|
# write message to logfile
|
||||||
with open(log_file,'a+') as log:
|
with open(log_file,'a+') as log:
|
||||||
log.write(message)
|
log.write(message)
|
||||||
|
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
path_to_default_config = 'configs/webui/webui_flet.yaml'
|
path_to_default_config = 'configs/webui/webui_flet.yaml'
|
||||||
path_to_user_config = 'configs/webui/userconfig_flet.yaml'
|
path_to_user_config = 'configs/webui/userconfig_flet.yaml'
|
||||||
@ -24,11 +35,22 @@ def get_default_settings_from_config():
|
|||||||
return default_settings
|
return default_settings
|
||||||
|
|
||||||
def get_user_settings_from_config():
|
def get_user_settings_from_config():
|
||||||
|
# get default settings
|
||||||
settings = get_default_settings_from_config()
|
settings = get_default_settings_from_config()
|
||||||
|
# check to see if userconfig exists
|
||||||
if os.path.exists(path_to_user_config):
|
if os.path.exists(path_to_user_config):
|
||||||
|
# compare to see which is newer
|
||||||
|
default_time = os.path.getmtime(path_to_default_config)
|
||||||
|
user_time = os.path.getmtime(path_to_user_config)
|
||||||
|
# if default is newer, save over userconfig and exit early
|
||||||
|
if (default_time > user_time):
|
||||||
|
save_user_settings_to_config(settings)
|
||||||
|
return settings
|
||||||
|
# else, load userconfig
|
||||||
with open(path_to_user_config) as f:
|
with open(path_to_user_config) as f:
|
||||||
user_settings = yaml.safe_load(f)
|
user_settings = yaml.safe_load(f)
|
||||||
settings.update(user_settings)
|
settings.update(user_settings)
|
||||||
|
# regardless, return settings
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
def save_user_settings_to_config(settings):
|
def save_user_settings_to_config(settings):
|
||||||
@ -36,26 +58,18 @@ def save_user_settings_to_config(settings):
|
|||||||
yaml.dump(settings, f, default_flow_style=False)
|
yaml.dump(settings, f, default_flow_style=False)
|
||||||
|
|
||||||
|
|
||||||
|
# file handling
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Image handling
|
# Image handling
|
||||||
|
|
||||||
def load_images(images): # just for testing, needs love to function
|
|
||||||
images_loaded = {}
|
|
||||||
images_not_loaded = []
|
|
||||||
for i in images:
|
|
||||||
try:
|
|
||||||
img = Image.open(images[i]['path'])
|
|
||||||
if img:
|
|
||||||
images_loaded.update({images[i].name:img})
|
|
||||||
except:
|
|
||||||
images_not_loaded.append(i)
|
|
||||||
|
|
||||||
return images_loaded, images_not_loaded
|
|
||||||
|
|
||||||
def create_blank_image():
|
def create_blank_image():
|
||||||
img = Image.new('RGBA',(512,512),(0,0,0,0))
|
img = Image.new('RGBA',(512,512),(0,0,0,0))
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Textual Inversion
|
# Textual Inversion
|
||||||
textual_inversion_grid_row_list = [
|
textual_inversion_grid_row_list = [
|
||||||
'model', 'medium', 'artist', 'trending', 'movement', 'flavors', 'techniques', 'tags',
|
'model', 'medium', 'artist', 'trending', 'movement', 'flavors', 'techniques', 'tags',
|
||||||
|
Loading…
Reference in New Issue
Block a user