mirror of
https://github.com/Sygil-Dev/sygil-webui.git
synced 2024-12-14 22:13:41 +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.color = self.page.tertiary_color
|
||||
|
||||
def add_blank_layer(self):
|
||||
self.layer_panel.add_blank_layer()
|
||||
|
||||
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):
|
||||
self.layer_panel.add_images_as_layers(images)
|
||||
return self.layer_panel.add_images_as_layers(images)
|
||||
|
||||
def set_tab_text_size(self, size):
|
||||
for tab in self.tabs:
|
||||
@ -52,32 +49,34 @@ class AssetManager(ft.Container):
|
||||
self.width = self.page.left_panel_width
|
||||
self.page.update()
|
||||
|
||||
def refresh_layers(self):
|
||||
self.layer_panel.refresh_layers()
|
||||
|
||||
class AssetPanel(ft.Container):
|
||||
pass
|
||||
|
||||
|
||||
class LayerPanel(ft.Container):
|
||||
def update_layers(self):
|
||||
def refresh_layers(self):
|
||||
self.layers = self.content.content.controls
|
||||
self.update_layer_indexes()
|
||||
self.update_visible_layers()
|
||||
self.refresh_layer_indexes()
|
||||
self.refresh_visible_layers()
|
||||
self.update()
|
||||
|
||||
def update_layer_indexes(self):
|
||||
def refresh_layer_indexes(self):
|
||||
count = 0
|
||||
for layer in self.layers:
|
||||
layer.index = count
|
||||
count += 1
|
||||
|
||||
def update_visible_layers(self):
|
||||
self.visible_layers = []
|
||||
def refresh_visible_layers(self):
|
||||
self.page.visible_layers = []
|
||||
for layer in self.layers:
|
||||
if layer.visible:
|
||||
self.visible_layers.append(layer)
|
||||
self.page.visible_layers.append(layer)
|
||||
|
||||
def update_layer_properties(self,e):
|
||||
self.page.property_manager.refresh_layer_properties()
|
||||
def refresh_layer_name(self, e):
|
||||
self.page.refresh_layers()
|
||||
|
||||
def make_layer_active(self, index):
|
||||
for i, layer in enumerate(self.layers):
|
||||
@ -86,8 +85,7 @@ class LayerPanel(ft.Container):
|
||||
if i == index:
|
||||
layer.active = True
|
||||
layer.handle.color = self.page.tertiary_color
|
||||
self.page.active_layer = layer
|
||||
self.page.property_manager.refresh_layer_properties()
|
||||
self.page.set_active_layer(layer)
|
||||
|
||||
def add_layer_slot(self, image):
|
||||
label = ft.TextField(
|
||||
@ -96,7 +94,7 @@ class LayerPanel(ft.Container):
|
||||
text_size = self.page.text_size,
|
||||
content_padding = ft.padding.only(left = 12, top = 0, right = 0, bottom = 0),
|
||||
expand = True,
|
||||
on_submit = self.update_layer_properties,
|
||||
on_submit = self.refresh_layer_name,
|
||||
)
|
||||
handle = ft.Icon(
|
||||
name = ft.icons.DRAG_HANDLE,
|
||||
@ -121,27 +119,21 @@ class LayerPanel(ft.Container):
|
||||
layer_slot.visible = True
|
||||
layer_slot.active = False
|
||||
layer_slot.image = image
|
||||
layer_slot.layer_image = None
|
||||
self.content.content.controls.insert(0,layer_slot)
|
||||
self.layers = self.content.content.controls
|
||||
self.update_layer_indexes()
|
||||
self.refresh_layer_indexes()
|
||||
self.make_layer_active(0)
|
||||
self.page.property_manager.refresh_layer_properties()
|
||||
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")
|
||||
return layer_slot
|
||||
|
||||
def add_image_as_layer(self, image):
|
||||
self.add_layer_slot(image)
|
||||
self.page.canvas.add_layer_image(image)
|
||||
self.page.message(f'added "{image.filename}" as layer')
|
||||
return self.add_layer_slot(image)
|
||||
|
||||
def add_images_as_layers(self, images):
|
||||
layer_slots = []
|
||||
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):
|
||||
index = int(pos / self.page.layer_height)
|
||||
@ -155,7 +147,7 @@ class LayerPanel(ft.Container):
|
||||
index -= 1
|
||||
layer = self.layers.pop(layer.index)
|
||||
self.layers.insert(index, layer)
|
||||
self.update_layers()
|
||||
self.page.refresh_layers()
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def drop_layer(e: ft.DragEndEvent):
|
||||
e.page.refresh_layers()
|
||||
layer_panel.layer_being_moved = None
|
||||
|
||||
|
||||
@ -208,7 +201,6 @@ layer_panel = LayerPanel(
|
||||
)
|
||||
|
||||
layer_panel.layers = []
|
||||
layer_panel.visible_layers = []
|
||||
layer_panel.layer_being_moved = None
|
||||
layer_panel.layer_last_index = 0
|
||||
|
||||
|
@ -25,8 +25,8 @@ class Canvas(ft.Container):
|
||||
self.update()
|
||||
|
||||
def refresh_canvas(self):
|
||||
self.image_stack.refresh_stack()
|
||||
self.overlay.refresh_canvas_overlay()
|
||||
self.page.update()
|
||||
|
||||
def set_current_tool(self, tool):
|
||||
self.page.current_tool = tool
|
||||
@ -35,8 +35,7 @@ class Canvas(ft.Container):
|
||||
self.image_stack.add_canvas_background()
|
||||
|
||||
def add_layer_image(self, image):
|
||||
self.image_stack.add_layer_image(image)
|
||||
self.update()
|
||||
return self.image_stack.add_layer_image(image)
|
||||
|
||||
def get_image_stack_preview(self):
|
||||
return self.image_stack.get_preview()
|
||||
@ -167,15 +166,18 @@ class ImageStack(ft.Container):
|
||||
layer_image.offset_y = 0
|
||||
self.center_layer(layer_image)
|
||||
self.content.controls.append(layer_image)
|
||||
self.page.enable_tools()
|
||||
canvas.refresh_canvas()
|
||||
return layer_image
|
||||
|
||||
def get_preview(self):
|
||||
stack = []
|
||||
for layer in self.content.controls:
|
||||
stack.append(layer)
|
||||
stack = self.content.controls
|
||||
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):
|
||||
self.scaled_width = self.width * 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
|
||||
|
||||
def move_layer(self, e: ft.DragUpdateEvent):
|
||||
index = self.page.active_layer.index
|
||||
layer = self.content.controls[index+1]
|
||||
layer = self.page.active_layer.layer_image
|
||||
layer.offset_x += e.delta_x
|
||||
layer.offset_y += e.delta_y
|
||||
self.align_layer(layer)
|
||||
@ -228,7 +229,6 @@ class CanvasOverlay(ft.Stack):
|
||||
self.size_display.content.value = str(self.page.canvas_size)
|
||||
self.update()
|
||||
|
||||
|
||||
def clear_tools(self):
|
||||
for tool in canvas_tools.content.controls:
|
||||
tool.selected = False
|
||||
@ -353,6 +353,7 @@ pan_canvas_button = ft.IconButton(
|
||||
content = ft.Icon(ft.icons.PAN_TOOL_OUTLINED),
|
||||
tooltip = 'pan canvas',
|
||||
on_click = set_pan_tool,
|
||||
selected = True,
|
||||
data = {'label':'pan'},
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ class UploadWindow(ft.AlertDialog):
|
||||
self.progress_bars.clear()
|
||||
self.selected_files.controls.clear()
|
||||
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()
|
||||
e.page.message('File upload(s) complete.')
|
||||
|
||||
|
@ -85,7 +85,7 @@ class GalleryImage(ft.Container):
|
||||
|
||||
def add_as_new_layer(e):
|
||||
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()
|
||||
for tab in gallery_window.content.content.tabs:
|
||||
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.color = self.page.tertiary_color
|
||||
|
||||
self.page.refresh_canvas_preview()
|
||||
self.refresh_canvas_properties()
|
||||
|
||||
def set_tab_text_size(self, size):
|
||||
|
@ -13,8 +13,8 @@ def open_gallery(e):
|
||||
def blank_layer(e):
|
||||
e.page.add_blank_layer()
|
||||
|
||||
def load_image(e):
|
||||
e.page.load_image()
|
||||
def load_images(e):
|
||||
e.page.load_images()
|
||||
|
||||
def tool_select(e):
|
||||
e.page.set_current_tool(e)
|
||||
@ -31,7 +31,7 @@ class Action():
|
||||
action_list = [
|
||||
Action('gallery', ft.icons.DASHBOARD_OUTLINED, 'Gallery', open_gallery),
|
||||
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
|
||||
# returns single composite of all images
|
||||
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_height = size[1]
|
||||
for layer in stack:
|
||||
|
@ -117,17 +117,43 @@ def main(page: ft.Page):
|
||||
# asset manager
|
||||
page.asset_manager = asset_manager
|
||||
page.active_layer = None
|
||||
page.visible_layers = []
|
||||
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():
|
||||
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
|
||||
|
||||
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.load_image = load_image
|
||||
page.load_images = load_images
|
||||
|
||||
|
||||
# canvas
|
||||
page.canvas = canvas
|
||||
@ -136,16 +162,11 @@ def main(page: ft.Page):
|
||||
|
||||
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_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
|
||||
|
||||
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():
|
||||
page.canvas.align_canvas()
|
||||
@ -156,6 +177,20 @@ def main(page: ft.Page):
|
||||
# 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
|
||||
def load_settings():
|
||||
@ -358,6 +393,7 @@ def main(page: ft.Page):
|
||||
|
||||
page.title = "Stable Diffusion Playground"
|
||||
page.add(workspace)
|
||||
|
||||
page.settings_window.setup(page.session.get('settings'))
|
||||
page.gallery_window.setup()
|
||||
page.titlebar.setup()
|
||||
|
Loading…
Reference in New Issue
Block a user