mirror of
https://github.com/sd-webui/stable-diffusion-webui.git
synced 2024-12-15 07:12:58 +03:00
moved more cross module calls to main(flet ui)
This commit is contained in:
parent
092d35e527
commit
5ef64a20ac
BIN
webui/flet/assets/icons/favicon.png
Normal file
BIN
webui/flet/assets/icons/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
35
webui/flet/assets/manifest.json
Normal file
35
webui/flet/assets/manifest.json
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "Sygil",
|
||||||
|
"short_name": "Sygil",
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#ffffff",
|
||||||
|
"theme_color": "#5175C2",
|
||||||
|
"description": "This is a customized Flet app description.",
|
||||||
|
"orientation": "natural",
|
||||||
|
"prefer_related_applications": false,
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "icons/icon-192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-maskable-192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "icons/icon-maskable-512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png",
|
||||||
|
"purpose": "maskable"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -22,14 +22,11 @@ class AssetManager(ft.Container):
|
|||||||
self.dragbar.content.width = self.page.vertical_divider_width
|
self.dragbar.content.width = self.page.vertical_divider_width
|
||||||
self.dragbar.content.color = self.page.tertiary_color
|
self.dragbar.content.color = self.page.tertiary_color
|
||||||
|
|
||||||
def add_blank_layer(self):
|
|
||||||
self.layer_panel.add_blank_layer()
|
|
||||||
|
|
||||||
def add_image_as_layer(self, image):
|
def add_image_as_layer(self, image):
|
||||||
self.layer_panel.add_image_as_layer(image)
|
return self.layer_panel.add_image_as_layer(image)
|
||||||
|
|
||||||
def add_images_as_layers(self, images):
|
def add_images_as_layers(self, images):
|
||||||
self.layer_panel.add_images_as_layers(images)
|
return self.layer_panel.add_images_as_layers(images)
|
||||||
|
|
||||||
def set_tab_text_size(self, size):
|
def set_tab_text_size(self, size):
|
||||||
for tab in self.tabs:
|
for tab in self.tabs:
|
||||||
@ -52,32 +49,34 @@ class AssetManager(ft.Container):
|
|||||||
self.width = self.page.left_panel_width
|
self.width = self.page.left_panel_width
|
||||||
self.page.update()
|
self.page.update()
|
||||||
|
|
||||||
|
def refresh_layers(self):
|
||||||
|
self.layer_panel.refresh_layers()
|
||||||
|
|
||||||
class AssetPanel(ft.Container):
|
class AssetPanel(ft.Container):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LayerPanel(ft.Container):
|
class LayerPanel(ft.Container):
|
||||||
def update_layers(self):
|
def refresh_layers(self):
|
||||||
self.layers = self.content.content.controls
|
self.layers = self.content.content.controls
|
||||||
self.update_layer_indexes()
|
self.refresh_layer_indexes()
|
||||||
self.update_visible_layers()
|
self.refresh_visible_layers()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update_layer_indexes(self):
|
def refresh_layer_indexes(self):
|
||||||
count = 0
|
count = 0
|
||||||
for layer in self.layers:
|
for layer in self.layers:
|
||||||
layer.index = count
|
layer.index = count
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
def update_visible_layers(self):
|
def refresh_visible_layers(self):
|
||||||
self.visible_layers = []
|
self.page.visible_layers = []
|
||||||
for layer in self.layers:
|
for layer in self.layers:
|
||||||
if layer.visible:
|
if layer.visible:
|
||||||
self.visible_layers.append(layer)
|
self.page.visible_layers.append(layer)
|
||||||
|
|
||||||
def update_layer_properties(self,e):
|
def refresh_layer_name(self, e):
|
||||||
self.page.property_manager.refresh_layer_properties()
|
self.page.refresh_layers()
|
||||||
|
|
||||||
def make_layer_active(self, index):
|
def make_layer_active(self, index):
|
||||||
for i, layer in enumerate(self.layers):
|
for i, layer in enumerate(self.layers):
|
||||||
@ -86,8 +85,7 @@ class LayerPanel(ft.Container):
|
|||||||
if i == index:
|
if i == index:
|
||||||
layer.active = True
|
layer.active = True
|
||||||
layer.handle.color = self.page.tertiary_color
|
layer.handle.color = self.page.tertiary_color
|
||||||
self.page.active_layer = layer
|
self.page.set_active_layer(layer)
|
||||||
self.page.property_manager.refresh_layer_properties()
|
|
||||||
|
|
||||||
def add_layer_slot(self, image):
|
def add_layer_slot(self, image):
|
||||||
label = ft.TextField(
|
label = ft.TextField(
|
||||||
@ -96,7 +94,7 @@ class LayerPanel(ft.Container):
|
|||||||
text_size = self.page.text_size,
|
text_size = self.page.text_size,
|
||||||
content_padding = ft.padding.only(left = 12, top = 0, right = 0, bottom = 0),
|
content_padding = ft.padding.only(left = 12, top = 0, right = 0, bottom = 0),
|
||||||
expand = True,
|
expand = True,
|
||||||
on_submit = self.update_layer_properties,
|
on_submit = self.refresh_layer_name,
|
||||||
)
|
)
|
||||||
handle = ft.Icon(
|
handle = ft.Icon(
|
||||||
name = ft.icons.DRAG_HANDLE,
|
name = ft.icons.DRAG_HANDLE,
|
||||||
@ -121,27 +119,21 @@ class LayerPanel(ft.Container):
|
|||||||
layer_slot.visible = True
|
layer_slot.visible = True
|
||||||
layer_slot.active = False
|
layer_slot.active = False
|
||||||
layer_slot.image = image
|
layer_slot.image = image
|
||||||
|
layer_slot.layer_image = None
|
||||||
self.content.content.controls.insert(0,layer_slot)
|
self.content.content.controls.insert(0,layer_slot)
|
||||||
self.layers = self.content.content.controls
|
self.layers = self.content.content.controls
|
||||||
self.update_layer_indexes()
|
self.refresh_layer_indexes()
|
||||||
self.make_layer_active(0)
|
self.make_layer_active(0)
|
||||||
self.page.property_manager.refresh_layer_properties()
|
return layer_slot
|
||||||
self.update()
|
|
||||||
|
|
||||||
def add_blank_layer(self):
|
|
||||||
image = flet_utils.create_blank_image(self.page.canvas_size)
|
|
||||||
self.add_layer_slot(image)
|
|
||||||
self.page.canvas.add_layer_image(image)
|
|
||||||
self.page.message("added blank layer to canvas")
|
|
||||||
|
|
||||||
def add_image_as_layer(self, image):
|
def add_image_as_layer(self, image):
|
||||||
self.add_layer_slot(image)
|
return self.add_layer_slot(image)
|
||||||
self.page.canvas.add_layer_image(image)
|
|
||||||
self.page.message(f'added "{image.filename}" as layer')
|
|
||||||
|
|
||||||
def add_images_as_layers(self, images):
|
def add_images_as_layers(self, images):
|
||||||
|
layer_slots = []
|
||||||
for image in images:
|
for image in images:
|
||||||
self.add_image_as_layer(image)
|
layer_slots.append(self.add_image_as_layer(image))
|
||||||
|
return layer_slots
|
||||||
|
|
||||||
def get_layer_index_from_position(self, pos):
|
def get_layer_index_from_position(self, pos):
|
||||||
index = int(pos / self.page.layer_height)
|
index = int(pos / self.page.layer_height)
|
||||||
@ -155,7 +147,7 @@ class LayerPanel(ft.Container):
|
|||||||
index -= 1
|
index -= 1
|
||||||
layer = self.layers.pop(layer.index)
|
layer = self.layers.pop(layer.index)
|
||||||
self.layers.insert(index, layer)
|
self.layers.insert(index, layer)
|
||||||
self.update_layers()
|
self.page.refresh_layers()
|
||||||
|
|
||||||
|
|
||||||
class LayerSlot(ft.Container):
|
class LayerSlot(ft.Container):
|
||||||
@ -186,6 +178,7 @@ def on_layer_drag(e: ft.DragUpdateEvent):
|
|||||||
layer_panel.move_layer(layer_panel.layer_being_moved, index)
|
layer_panel.move_layer(layer_panel.layer_being_moved, index)
|
||||||
|
|
||||||
def drop_layer(e: ft.DragEndEvent):
|
def drop_layer(e: ft.DragEndEvent):
|
||||||
|
e.page.refresh_layers()
|
||||||
layer_panel.layer_being_moved = None
|
layer_panel.layer_being_moved = None
|
||||||
|
|
||||||
|
|
||||||
@ -208,7 +201,6 @@ layer_panel = LayerPanel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
layer_panel.layers = []
|
layer_panel.layers = []
|
||||||
layer_panel.visible_layers = []
|
|
||||||
layer_panel.layer_being_moved = None
|
layer_panel.layer_being_moved = None
|
||||||
layer_panel.layer_last_index = 0
|
layer_panel.layer_last_index = 0
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ class Canvas(ft.Container):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def refresh_canvas(self):
|
def refresh_canvas(self):
|
||||||
|
self.image_stack.refresh_stack()
|
||||||
self.overlay.refresh_canvas_overlay()
|
self.overlay.refresh_canvas_overlay()
|
||||||
self.page.update()
|
|
||||||
|
|
||||||
def set_current_tool(self, tool):
|
def set_current_tool(self, tool):
|
||||||
self.page.current_tool = tool
|
self.page.current_tool = tool
|
||||||
@ -35,8 +35,7 @@ class Canvas(ft.Container):
|
|||||||
self.image_stack.add_canvas_background()
|
self.image_stack.add_canvas_background()
|
||||||
|
|
||||||
def add_layer_image(self, image):
|
def add_layer_image(self, image):
|
||||||
self.image_stack.add_layer_image(image)
|
return self.image_stack.add_layer_image(image)
|
||||||
self.update()
|
|
||||||
|
|
||||||
def get_image_stack_preview(self):
|
def get_image_stack_preview(self):
|
||||||
return self.image_stack.get_preview()
|
return self.image_stack.get_preview()
|
||||||
@ -167,15 +166,18 @@ class ImageStack(ft.Container):
|
|||||||
layer_image.offset_y = 0
|
layer_image.offset_y = 0
|
||||||
self.center_layer(layer_image)
|
self.center_layer(layer_image)
|
||||||
self.content.controls.append(layer_image)
|
self.content.controls.append(layer_image)
|
||||||
self.page.enable_tools()
|
return layer_image
|
||||||
canvas.refresh_canvas()
|
|
||||||
|
|
||||||
def get_preview(self):
|
def get_preview(self):
|
||||||
stack = []
|
stack = self.content.controls
|
||||||
for layer in self.content.controls:
|
|
||||||
stack.append(layer)
|
|
||||||
return flet_utils.get_preview_from_stack(self.page.canvas_size, stack)
|
return flet_utils.get_preview_from_stack(self.page.canvas_size, stack)
|
||||||
|
|
||||||
|
def refresh_stack(self):
|
||||||
|
self.content.controls.clear()
|
||||||
|
for slot in self.page.visible_layers:
|
||||||
|
self.content.controls.insert(0, slot.layer_image)
|
||||||
|
self.content.controls.insert(0, self.canvas_bg)
|
||||||
|
|
||||||
def get_scaled_size(self):
|
def get_scaled_size(self):
|
||||||
self.scaled_width = self.width * self.scale
|
self.scaled_width = self.width * self.scale
|
||||||
self.scaled_height = self.height * self.scale
|
self.scaled_height = self.height * self.scale
|
||||||
@ -191,8 +193,7 @@ class ImageStack(ft.Container):
|
|||||||
layer_image.top = ((self.height - layer_image.height) * 0.5) + layer_image.offset_y
|
layer_image.top = ((self.height - layer_image.height) * 0.5) + layer_image.offset_y
|
||||||
|
|
||||||
def move_layer(self, e: ft.DragUpdateEvent):
|
def move_layer(self, e: ft.DragUpdateEvent):
|
||||||
index = self.page.active_layer.index
|
layer = self.page.active_layer.layer_image
|
||||||
layer = self.content.controls[index+1]
|
|
||||||
layer.offset_x += e.delta_x
|
layer.offset_x += e.delta_x
|
||||||
layer.offset_y += e.delta_y
|
layer.offset_y += e.delta_y
|
||||||
self.align_layer(layer)
|
self.align_layer(layer)
|
||||||
@ -228,7 +229,6 @@ class CanvasOverlay(ft.Stack):
|
|||||||
self.size_display.content.value = str(self.page.canvas_size)
|
self.size_display.content.value = str(self.page.canvas_size)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
def clear_tools(self):
|
def clear_tools(self):
|
||||||
for tool in canvas_tools.content.controls:
|
for tool in canvas_tools.content.controls:
|
||||||
tool.selected = False
|
tool.selected = False
|
||||||
@ -353,6 +353,7 @@ pan_canvas_button = ft.IconButton(
|
|||||||
content = ft.Icon(ft.icons.PAN_TOOL_OUTLINED),
|
content = ft.Icon(ft.icons.PAN_TOOL_OUTLINED),
|
||||||
tooltip = 'pan canvas',
|
tooltip = 'pan canvas',
|
||||||
on_click = set_pan_tool,
|
on_click = set_pan_tool,
|
||||||
|
selected = True,
|
||||||
data = {'label':'pan'},
|
data = {'label':'pan'},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class UploadWindow(ft.AlertDialog):
|
|||||||
self.progress_bars.clear()
|
self.progress_bars.clear()
|
||||||
self.selected_files.controls.clear()
|
self.selected_files.controls.clear()
|
||||||
e.page.close_uploads(e)
|
e.page.close_uploads(e)
|
||||||
e.page.asset_manager.add_images_as_layers(file_picker.images)
|
e.page.add_images_as_layers(file_picker.images)
|
||||||
file_picker.images.clear()
|
file_picker.images.clear()
|
||||||
e.page.message('File upload(s) complete.')
|
e.page.message('File upload(s) complete.')
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ class GalleryImage(ft.Container):
|
|||||||
|
|
||||||
def add_as_new_layer(e):
|
def add_as_new_layer(e):
|
||||||
if gallery_window.selected_images:
|
if gallery_window.selected_images:
|
||||||
e.page.asset_manager.add_images_as_layers(gallery_window.selected_images)
|
e.page.add_images_as_layers(gallery_window.selected_images)
|
||||||
gallery_window.selected_images.clear()
|
gallery_window.selected_images.clear()
|
||||||
for tab in gallery_window.content.content.tabs:
|
for tab in gallery_window.content.content.tabs:
|
||||||
for image in tab.content.content.controls:
|
for image in tab.content.content.controls:
|
||||||
|
@ -27,6 +27,7 @@ class PropertyManager(ft.Container):
|
|||||||
self.property_panel.layer_properties_divider.content.height = self.page.divider_height
|
self.property_panel.layer_properties_divider.content.height = self.page.divider_height
|
||||||
self.property_panel.layer_properties_divider.content.color = self.page.tertiary_color
|
self.property_panel.layer_properties_divider.content.color = self.page.tertiary_color
|
||||||
|
|
||||||
|
self.page.refresh_canvas_preview()
|
||||||
self.refresh_canvas_properties()
|
self.refresh_canvas_properties()
|
||||||
|
|
||||||
def set_tab_text_size(self, size):
|
def set_tab_text_size(self, size):
|
||||||
|
@ -13,8 +13,8 @@ def open_gallery(e):
|
|||||||
def blank_layer(e):
|
def blank_layer(e):
|
||||||
e.page.add_blank_layer()
|
e.page.add_blank_layer()
|
||||||
|
|
||||||
def load_image(e):
|
def load_images(e):
|
||||||
e.page.load_image()
|
e.page.load_images()
|
||||||
|
|
||||||
def tool_select(e):
|
def tool_select(e):
|
||||||
e.page.set_current_tool(e)
|
e.page.set_current_tool(e)
|
||||||
@ -31,7 +31,7 @@ class Action():
|
|||||||
action_list = [
|
action_list = [
|
||||||
Action('gallery', ft.icons.DASHBOARD_OUTLINED, 'Gallery', open_gallery),
|
Action('gallery', ft.icons.DASHBOARD_OUTLINED, 'Gallery', open_gallery),
|
||||||
Action('blank layer', ft.icons.ADD_OUTLINED, 'Add blank layer', blank_layer),
|
Action('blank layer', ft.icons.ADD_OUTLINED, 'Add blank layer', blank_layer),
|
||||||
Action('load image', ft.icons.IMAGE_OUTLINED, 'Load image as layer', load_image),
|
Action('load image', ft.icons.IMAGE_OUTLINED, 'Load image as layer', load_images),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ def get_canvas_frame(canvas_size):
|
|||||||
# takes list of Image(s) as arg
|
# takes list of Image(s) as arg
|
||||||
# returns single composite of all images
|
# returns single composite of all images
|
||||||
def get_preview_from_stack(size, stack):
|
def get_preview_from_stack(size, stack):
|
||||||
preview = create_blank_image(size)
|
preview = Image.new('RGBA',size,(0,0,0,0))
|
||||||
canvas_width = size[0]
|
canvas_width = size[0]
|
||||||
canvas_height = size[1]
|
canvas_height = size[1]
|
||||||
for layer in stack:
|
for layer in stack:
|
||||||
|
@ -117,17 +117,43 @@ def main(page: ft.Page):
|
|||||||
# asset manager
|
# asset manager
|
||||||
page.asset_manager = asset_manager
|
page.asset_manager = asset_manager
|
||||||
page.active_layer = None
|
page.active_layer = None
|
||||||
|
page.visible_layers = []
|
||||||
page.layer_height = 50
|
page.layer_height = 50
|
||||||
|
|
||||||
|
def set_active_layer(layer_slot):
|
||||||
|
if page.active_layer == layer_slot:
|
||||||
|
return
|
||||||
|
page.active_layer = layer_slot
|
||||||
|
page.property_manager.refresh_layer_properties()
|
||||||
|
page.message(f"set {layer_slot.label.value} as active layer")
|
||||||
|
|
||||||
|
page.set_active_layer = set_active_layer
|
||||||
|
|
||||||
def add_blank_layer():
|
def add_blank_layer():
|
||||||
page.asset_manager.add_blank_layer()
|
image = flet_utils.create_blank_image(page.canvas_size)
|
||||||
|
layer_slot = page.asset_manager.add_image_as_layer(image)
|
||||||
|
layer_slot.layer_image = page.canvas.add_layer_image(image)
|
||||||
|
page.message("added blank layer to canvas")
|
||||||
|
page.enable_tools()
|
||||||
|
page.refresh_layers()
|
||||||
|
|
||||||
page.add_blank_layer = add_blank_layer
|
page.add_blank_layer = add_blank_layer
|
||||||
|
|
||||||
def load_image():
|
def add_images_as_layers(images):
|
||||||
|
layer_slots = page.asset_manager.add_images_as_layers(images)
|
||||||
|
for slot in layer_slots:
|
||||||
|
slot.layer_image = page.canvas.add_layer_image(slot.image)
|
||||||
|
page.message(f'added "{slot.image.filename}" as layer')
|
||||||
|
page.enable_tools()
|
||||||
|
page.refresh_layers()
|
||||||
|
|
||||||
|
page.add_images_as_layers = add_images_as_layers
|
||||||
|
|
||||||
|
def load_images():
|
||||||
page.file_picker.pick_files(file_type = 'image', allow_multiple = True)
|
page.file_picker.pick_files(file_type = 'image', allow_multiple = True)
|
||||||
|
|
||||||
page.load_image = load_image
|
page.load_images = load_images
|
||||||
|
|
||||||
|
|
||||||
# canvas
|
# canvas
|
||||||
page.canvas = canvas
|
page.canvas = canvas
|
||||||
@ -136,16 +162,11 @@ def main(page: ft.Page):
|
|||||||
|
|
||||||
def get_viewport_size():
|
def get_viewport_size():
|
||||||
viewport_width = page.width - (page.tool_manager_width + (page.vertical_divider_width * 3) + page.left_panel_width + page.right_panel_width)
|
viewport_width = page.width - (page.tool_manager_width + (page.vertical_divider_width * 3) + page.left_panel_width + page.right_panel_width)
|
||||||
viewport_height = page.height - (page.titlebar_height * 3) - page.bottom_panel_height
|
viewport_height = page.height - (page.titlebar_height * 2) - page.bottom_panel_height
|
||||||
return viewport_width, viewport_height
|
return viewport_width, viewport_height
|
||||||
|
|
||||||
page.get_viewport_size = get_viewport_size
|
page.get_viewport_size = get_viewport_size
|
||||||
|
|
||||||
def refresh_canvas_preview():
|
|
||||||
preview = page.canvas.get_image_stack_preview()
|
|
||||||
page.property_manager.set_preview_image(preview)
|
|
||||||
|
|
||||||
page.refresh_canvas_preview = refresh_canvas_preview
|
|
||||||
|
|
||||||
def align_canvas():
|
def align_canvas():
|
||||||
page.canvas.align_canvas()
|
page.canvas.align_canvas()
|
||||||
@ -156,6 +177,20 @@ def main(page: ft.Page):
|
|||||||
# property manager
|
# property manager
|
||||||
page.property_manager = property_manager
|
page.property_manager = property_manager
|
||||||
|
|
||||||
|
def refresh_canvas_preview():
|
||||||
|
preview = page.canvas.get_image_stack_preview()
|
||||||
|
page.property_manager.set_preview_image(preview)
|
||||||
|
|
||||||
|
page.refresh_canvas_preview = refresh_canvas_preview
|
||||||
|
|
||||||
|
def refresh_layers():
|
||||||
|
page.asset_manager.refresh_layers()
|
||||||
|
page.canvas.refresh_canvas()
|
||||||
|
page.refresh_canvas_preview()
|
||||||
|
page.property_manager.refresh_layer_properties()
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
page.refresh_layers = refresh_layers
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
def load_settings():
|
def load_settings():
|
||||||
@ -358,6 +393,7 @@ def main(page: ft.Page):
|
|||||||
|
|
||||||
page.title = "Stable Diffusion Playground"
|
page.title = "Stable Diffusion Playground"
|
||||||
page.add(workspace)
|
page.add(workspace)
|
||||||
|
|
||||||
page.settings_window.setup(page.session.get('settings'))
|
page.settings_window.setup(page.session.get('settings'))
|
||||||
page.gallery_window.setup()
|
page.gallery_window.setup()
|
||||||
page.titlebar.setup()
|
page.titlebar.setup()
|
||||||
|
Loading…
Reference in New Issue
Block a user