more refactoring on flet webui(WIP)

This commit is contained in:
aedhcarrick 2022-12-11 16:06:09 -06:00
parent ae7b33279b
commit 79ac1b785f
4 changed files with 132 additions and 108 deletions

View File

@ -74,7 +74,7 @@ class GalleryDisplay(ft.Container):
)
)
return gallery_display
for i in range(len(gallery)):
image = gallery[i]
image_name = list(image.keys())[0]
@ -90,4 +90,69 @@ class GalleryDisplay(ft.Container):
)
)
return gallery_display
def refresh_gallery(name):
pass # placeholder
def add_as_new_layer(e):
pass
def save_to_disk(e):
pass
def remove_from_gallery(e):
pass
uploads_gallery = GalleryDisplay(
content = None,
clip_behavior = 'antiAlias',
)
outputs_gallery = GalleryDisplay(
content = None,
clip_behavior = 'antiAlias',
)
# GalleryWindow == ft.AlertDialog
gallery_window = GalleryWindow(
title = ft.Text('Gallery'),
content = ft.Container(
content = ft.Tabs(
selected_index = 0,
animation_duration = 300,
tabs = [
ft.Tab(
text = "Uploads",
content = uploads_gallery,
),
ft.Tab(
text = "Outputs",
content = outputs_gallery,
),
],
),
),
actions = [
ft.ElevatedButton(
text = "Add As New Layer",
icon = ft.icons.ADD_OUTLINED,
on_click = add_as_new_layer,
),
ft.ElevatedButton(
text = "Save",
icon = ft.icons.SAVE_OUTLINED,
on_click = save_to_disk,
),
ft.ElevatedButton(
text = "Discard",
icon = ft.icons.DELETE_OUTLINED,
on_click = remove_from_gallery,
),
],
actions_alignment="end",
)
gallery_window.uploads_gallery = uploads_gallery
gallery_window.outputs_gallery = outputs_gallery

View File

@ -6,21 +6,6 @@ from scripts import flet_utils
class LayerManager(ft.Container):
# first make a column to hold the layers
def make_layer_holder(self):
layer_holder = ft.DragTarget(
group = 'layer',
content = ft.Column(
spacing = 0,
scroll = 'auto',
controls = [],
),
on_will_accept = self.layer_will_accept,
on_accept = self.layer_accept,
on_leave = self.layer_leave,
)
return layer_holder
# make a slot for each layer to go in
def make_layer_slot(self):
layer_slot = LayerSlot(
@ -268,8 +253,6 @@ class LayerManager(ft.Container):
def layer_right_click(self,e):
pass
# make each layer slot a target
class LayerSlot(ft.DragTarget):
def set_layer_slot_name(self, name):
self.content.content.controls[1].content.controls[1].value = name
@ -286,3 +269,33 @@ class LayerSlot(ft.DragTarget):
self.content.content.controls[0].visible = False
self.update()
def layer_will_accept(e):
layer_manager.layer_will_accept(e)
def layer_accept(e):
layer_manager.layer_accept(e)
def layer_leave(e):
layer_manager.layer_leave(e)
layer_holder = ft.DragTarget(
group = 'layer',
content = ft.Column(
spacing = 0,
scroll = 'auto',
controls = [],
),
on_will_accept = layer_will_accept,
on_accept = layer_accept,
on_leave = layer_leave,
)
layer_manager = LayerManager(
content = layer_holder,
data = {
'layer_list': [],
'visible_layer_list': [],
'layer_being_moved': None,
'layer_last_index': -1,
},
)

View File

@ -4,6 +4,15 @@ import flet as ft
from scripts import flet_utils
def open_gallery(e):
e.control.page.open_gallery(e)
def blank_layer(e):
e.control.page.layer_manager.add_blank_layer(e)
def load_image(e):
e.control.page.file_picker.pick_files(file_type = 'image', allow_multiple = True)
def tool_select(e):
toolbox.clear_tools()
e.control.page.current_tool = e.control.data['label']
@ -19,9 +28,9 @@ class Action():
self.on_click = on_click
action_list = [
Action('gallery', ft.icons.DASHBOARD_OUTLINED, 'Gallery', None),
Action('blank layer', ft.icons.ADD_OUTLINED, 'Add blank layer', None),
Action('load image', ft.icons.IMAGE_OUTLINED, 'Load image as layer', None),
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),
]
class Tool():

View File

@ -9,9 +9,9 @@ from loguru import logger
# utils imports
from scripts import flet_utils
from scripts.flet_settings_window import SettingsWindow
from scripts.flet_gallery_window import GalleryWindow, GalleryDisplay
from scripts.flet_gallery_window import gallery_window
from scripts.flet_tool_manager import toolbar
from scripts.flet_layer_manager import LayerManager
from scripts.flet_layer_manager import layer_manager
from scripts.flet_canvas import Canvas, ImageStack
# for debugging
@ -200,83 +200,28 @@ def main(page: ft.Page):
gallery_window.open = False
page.update()
page.close_gallery = close_gallery_window
def open_gallery_window(e):
page.dialog = gallery_window
gallery_window.open = True
page.update()
def refresh_gallery(name):
pass # placeholder
page.open_gallery = open_gallery_window
def add_as_new_layer(e):
pass
page.gallery = gallery_window
gallery_window.content.width = page.width * 0.5
gallery_window.content.bgcolor = page.primary_color
gallery_window.content.padding = page.container_padding
gallery_window.content.margin = page.container_margin
def save_to_disk(e):
pass
gallery_window.outputs_gallery.bgcolor = page.primary_color
gallery_window.outputs_gallery.padding = page.container_padding
gallery_window.outputs_gallery.margin = page.container_margin
def remove_from_gallery(e):
pass
# GalleryDisplay == ft.Container
uploads_gallery = GalleryDisplay(
content = None,
clip_behavior = 'antiAlias',
bgcolor = page.primary_color,
padding = page.container_padding,
margin = page.container_margin,
)
outputs_gallery = GalleryDisplay(
content = None,
clip_behavior = 'antiAlias',
bgcolor = page.primary_color,
padding = page.container_padding,
margin = page.container_margin,
)
# GalleryWindow == ft.AlertDialog
gallery_window = GalleryWindow(
title = ft.Text('Gallery'),
content = ft.Container(
width = page.width * 0.5,
bgcolor = page.primary_color,
padding = page.container_padding,
margin = page.container_margin,
content = ft.Tabs(
selected_index = 0,
animation_duration = 300,
tabs = [
ft.Tab(
text = "Uploads",
content = uploads_gallery,
),
ft.Tab(
text = "Outputs",
content = outputs_gallery,
),
],
),
),
actions = [
ft.ElevatedButton(
text = "Add As New Layer",
icon = ft.icons.ADD_OUTLINED,
on_click = add_as_new_layer,
),
ft.ElevatedButton(
text = "Save",
icon = ft.icons.SAVE_OUTLINED,
on_click = save_to_disk,
),
ft.ElevatedButton(
text = "Discard",
icon = ft.icons.DELETE_OUTLINED,
on_click = remove_from_gallery,
),
],
actions_alignment="end",
)
gallery_window.uploads_gallery.bgcolor = page.primary_color
gallery_window.uploads_gallery.padding = page.container_padding
gallery_window.uploads_gallery.margin = page.container_margin
# upload window ######################################################
@ -401,9 +346,11 @@ def main(page: ft.Page):
on_result = pick_images,
on_upload = on_image_upload
)
page.file_picker = file_picker
page.overlay.append(file_picker)
file_picker.pending = 0
file_picker.images = {}
page.overlay.append(file_picker)
# layouts ############################################################
@ -533,21 +480,11 @@ def main(page: ft.Page):
# layer manager ######################################################
# LayerManager == ft.Container
layer_manager = LayerManager(
content = None,
bgcolor = page.secondary_color,
padding = page.container_padding,
margin = page.container_margin,
data = {
'layer_list': [],
'visible_layer_list': [],
'layer_being_moved': None,
'layer_last_index': -1,
},
)
layer_manager.content = layer_manager.make_layer_holder()
page.layer_manager = layer_manager
layer_manager.bgcolor = page.secondary_color
layer_manager.padding = page.container_padding
layer_manager.margin = page.container_margin
# asset manager ######################################################