mirror of
https://github.com/Sygil-Dev/sygil-webui.git
synced 2024-12-14 22:13:41 +03:00
added context menu to layer slots(flet ui)
This commit is contained in:
parent
ca0940fa99
commit
8c0079485f
@ -52,6 +52,7 @@ class AssetManager(ft.Container):
|
||||
def refresh_layers(self):
|
||||
self.layer_panel.refresh_layers()
|
||||
|
||||
|
||||
class AssetPanel(ft.Container):
|
||||
pass
|
||||
|
||||
@ -72,7 +73,7 @@ class LayerPanel(ft.Container):
|
||||
def refresh_visible_layers(self):
|
||||
self.page.visible_layers = []
|
||||
for layer in self.layers:
|
||||
if layer.visible:
|
||||
if not layer.disabled:
|
||||
self.page.visible_layers.append(layer)
|
||||
|
||||
def refresh_layer_name(self, e):
|
||||
@ -116,7 +117,7 @@ class LayerPanel(ft.Container):
|
||||
layer_slot.label = label
|
||||
layer_slot.handle = handle
|
||||
layer_slot.index = 0
|
||||
layer_slot.visible = True
|
||||
layer_slot.disabled = False
|
||||
layer_slot.active = False
|
||||
layer_slot.image = image
|
||||
layer_slot.layer_image = None
|
||||
@ -149,11 +150,95 @@ class LayerPanel(ft.Container):
|
||||
self.layers.insert(index, layer)
|
||||
self.page.refresh_layers()
|
||||
|
||||
def delete_layer(self, layer):
|
||||
if not layer:
|
||||
return
|
||||
self.layers.pop(layer.index)
|
||||
|
||||
|
||||
class LayerSlot(ft.Container):
|
||||
pass
|
||||
|
||||
|
||||
class LayerActionMenu(ft.Card):
|
||||
def show_menu(self):
|
||||
self.visible = True
|
||||
self.update()
|
||||
|
||||
def hide_menu(self):
|
||||
self.visible = False
|
||||
self.update()
|
||||
|
||||
|
||||
def close_menu(e):
|
||||
layer_action_menu.hide_menu()
|
||||
|
||||
def show_hide_layer(e):
|
||||
e.page.active_layer.disabled = False if e.page.active_layer.disabled else True
|
||||
e.page.refresh_layers()
|
||||
close_menu(e)
|
||||
|
||||
def move_layer_to_top(e):
|
||||
layer_panel.move_layer(e.page.active_layer, 0)
|
||||
close_menu(e)
|
||||
|
||||
def move_layer_up(e):
|
||||
layer_panel.move_layer(e.page.active_layer, e.page.active_layer.index - 1)
|
||||
close_menu(e)
|
||||
|
||||
def move_layer_down(e):
|
||||
layer_panel.move_layer(e.page.active_layer, e.page.active_layer.index + 2)
|
||||
close_menu(e)
|
||||
|
||||
def delete_layer(e):
|
||||
layer_panel.delete_layer(e.page.active_layer)
|
||||
e.page.active_layer = None
|
||||
e.page.refresh_layers()
|
||||
close_menu(e)
|
||||
|
||||
|
||||
class LayerAction():
|
||||
def __init__(self, text, on_click):
|
||||
self.text = text
|
||||
self.on_click = on_click
|
||||
|
||||
layer_action_list = [
|
||||
LayerAction('Show/Hide Layer', show_hide_layer),
|
||||
LayerAction('Move Layer To Top', move_layer_to_top),
|
||||
LayerAction('Move Layer Up', move_layer_up),
|
||||
LayerAction('Move Layer Down', move_layer_down),
|
||||
LayerAction('Delete Layer', delete_layer),
|
||||
]
|
||||
|
||||
def make_action_buttons(action_list):
|
||||
button_list = []
|
||||
for action in action_list:
|
||||
button_list.append(
|
||||
ft.TextButton(
|
||||
text = action.text,
|
||||
on_click = action.on_click,
|
||||
)
|
||||
)
|
||||
return button_list
|
||||
|
||||
# LayerActionMenu == ft.Card
|
||||
layer_action_menu = LayerActionMenu(
|
||||
content = ft.GestureDetector(
|
||||
content = ft.Column(
|
||||
controls = make_action_buttons(layer_action_list),
|
||||
expand = False,
|
||||
spacing = 0,
|
||||
alignment = 'start',
|
||||
tight = True,
|
||||
),
|
||||
on_exit = close_menu,
|
||||
),
|
||||
margin = 0,
|
||||
visible = False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def layer_left_click(e: ft.TapEvent):
|
||||
index = layer_panel.get_layer_index_from_position(e.local_y)
|
||||
if index >= len(layer_panel.layers):
|
||||
@ -161,6 +246,16 @@ def layer_left_click(e: ft.TapEvent):
|
||||
layer_panel.make_layer_active(index)
|
||||
layer_panel.update()
|
||||
|
||||
def layer_right_click(e: ft.TapEvent):
|
||||
index = layer_panel.get_layer_index_from_position(e.local_y)
|
||||
if index >= len(layer_panel.layers):
|
||||
return
|
||||
layer_panel.make_layer_active(index)
|
||||
layer_panel.update()
|
||||
layer_action_menu.left = e.global_x
|
||||
layer_action_menu.top = e.global_y
|
||||
layer_action_menu.show_menu()
|
||||
|
||||
def pickup_layer(e: ft.DragStartEvent):
|
||||
index = layer_panel.get_layer_index_from_position(e.local_y)
|
||||
if index >= len(layer_panel.layers):
|
||||
@ -194,6 +289,7 @@ layer_panel = LayerPanel(
|
||||
),
|
||||
drag_interval = 10,
|
||||
on_tap_down = layer_left_click,
|
||||
on_secondary_tap_down = layer_right_click,
|
||||
on_vertical_drag_start = pickup_layer,
|
||||
on_vertical_drag_update = on_layer_drag,
|
||||
on_vertical_drag_end = drop_layer,
|
||||
|
@ -22,7 +22,6 @@ class Canvas(ft.Container):
|
||||
self.add_canvas_background()
|
||||
self.center_canvas()
|
||||
self.refresh_canvas()
|
||||
self.update()
|
||||
|
||||
def refresh_canvas(self):
|
||||
self.image_stack.refresh_stack()
|
||||
@ -177,6 +176,7 @@ class ImageStack(ft.Container):
|
||||
for slot in self.page.visible_layers:
|
||||
self.content.controls.insert(0, slot.layer_image)
|
||||
self.content.controls.insert(0, self.canvas_bg)
|
||||
self.update()
|
||||
|
||||
def get_scaled_size(self):
|
||||
self.scaled_width = self.width * self.scale
|
||||
|
@ -129,7 +129,7 @@ gallery_window = GalleryWindow(
|
||||
),
|
||||
actions = [
|
||||
ft.ElevatedButton(
|
||||
text = "Add As New Layer",
|
||||
text = "Add As New Layer(s)",
|
||||
icon = ft.icons.ADD_OUTLINED,
|
||||
on_click = add_as_new_layer,
|
||||
),
|
||||
|
@ -77,14 +77,22 @@ class PropertyPanel(ft.Container):
|
||||
self.canvas_properties.update()
|
||||
|
||||
def refresh_layer_properties(self):
|
||||
self.layer_property_header.disabled = False
|
||||
self.layer_property_header.open = True
|
||||
self.layer_property_header.icon = ft.icons.ARROW_DROP_DOWN
|
||||
self.layer_property_header.icon_color = self.page.tertiary_color
|
||||
self.layer_properties.visible = True
|
||||
self.layer_properties.controls[0].controls[0].value = self.page.active_layer.label.value
|
||||
self.layer_properties.controls[1].controls[0].value = self.page.active_layer.image.width
|
||||
self.layer_properties.controls[1].controls[1].value = self.page.active_layer.image.height
|
||||
active = True if self.page.active_layer else False
|
||||
if active:
|
||||
self.layer_property_header.disabled = False
|
||||
self.layer_property_header.open = True
|
||||
self.layer_property_header.icon = ft.icons.ARROW_DROP_DOWN
|
||||
self.layer_property_header.icon_color = self.page.tertiary_color
|
||||
self.layer_properties.visible = True
|
||||
self.layer_properties.controls[0].controls[0].value = self.page.active_layer.label.value
|
||||
self.layer_properties.controls[1].controls[0].value = self.page.active_layer.image.width
|
||||
self.layer_properties.controls[1].controls[1].value = self.page.active_layer.image.height
|
||||
else:
|
||||
self.layer_property_header.disabled = True
|
||||
self.layer_property_header.open = False
|
||||
self.layer_property_header.icon = ft.icons.ARROW_RIGHT
|
||||
self.layer_property_header.icon_color = None
|
||||
self.layer_properties.visible = False
|
||||
self.update()
|
||||
|
||||
preview_pane = ft.Container(
|
||||
|
@ -89,9 +89,15 @@ class ToolManager(ft.Container):
|
||||
tool.disabled = False
|
||||
self.update()
|
||||
|
||||
def disable_tools(self):
|
||||
for tool in self.toolbox.content.controls:
|
||||
tool.disabled = True
|
||||
self.update()
|
||||
|
||||
def clear_tools(self):
|
||||
self.toolbox.clear_tools()
|
||||
|
||||
|
||||
class ToolBox(ft.Container):
|
||||
def get_tools(self):
|
||||
for action in action_list:
|
||||
|
@ -16,7 +16,7 @@ from scripts.flet_gallery_window import gallery_window
|
||||
from scripts.flet_file_manager import file_picker, uploads, imports
|
||||
from scripts.flet_titlebar import titlebar
|
||||
from scripts.flet_tool_manager import tool_manager
|
||||
from scripts.flet_asset_manager import asset_manager
|
||||
from scripts.flet_asset_manager import asset_manager, layer_action_menu
|
||||
from scripts.flet_canvas import canvas
|
||||
from scripts.flet_messages import messages
|
||||
from scripts.flet_property_manager import property_manager
|
||||
@ -104,6 +104,11 @@ def main(page: ft.Page):
|
||||
|
||||
page.enable_tools = enable_tools
|
||||
|
||||
def disable_tools():
|
||||
page.tool_manager.disable_tools()
|
||||
|
||||
page.disable_tools = disable_tools
|
||||
|
||||
def set_current_tool(e):
|
||||
page.tool_manager.clear_tools()
|
||||
page.canvas.clear_tools()
|
||||
@ -124,8 +129,8 @@ def main(page: ft.Page):
|
||||
if page.active_layer == layer_slot:
|
||||
return
|
||||
page.active_layer = layer_slot
|
||||
page.enable_tools()
|
||||
page.property_manager.refresh_layer_properties()
|
||||
page.message(f"set {layer_slot.label.value} as active layer")
|
||||
|
||||
page.set_active_layer = set_active_layer
|
||||
|
||||
@ -134,7 +139,6 @@ def main(page: ft.Page):
|
||||
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
|
||||
@ -144,7 +148,6 @@ def main(page: ft.Page):
|
||||
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
|
||||
@ -184,6 +187,10 @@ def main(page: ft.Page):
|
||||
page.refresh_canvas_preview = refresh_canvas_preview
|
||||
|
||||
def refresh_layers():
|
||||
if page.active_layer == None:
|
||||
page.disable_tools()
|
||||
else:
|
||||
page.enable_tools()
|
||||
page.asset_manager.refresh_layers()
|
||||
page.canvas.refresh_canvas()
|
||||
page.refresh_canvas_preview()
|
||||
@ -376,23 +383,30 @@ def main(page: ft.Page):
|
||||
|
||||
# workspace ##########################################################
|
||||
|
||||
workspace = ft.Container(
|
||||
bgcolor = page.background_color,
|
||||
padding = 0,
|
||||
margin = 0,
|
||||
workspace = ft.Column(
|
||||
controls = [
|
||||
titlebar,
|
||||
current_layout,
|
||||
],
|
||||
expand = True,
|
||||
content = ft.Column(
|
||||
controls = [
|
||||
titlebar,
|
||||
current_layout,
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
page.workspace = workspace
|
||||
|
||||
full_page = ft.Stack(
|
||||
expand = True,
|
||||
controls = [
|
||||
workspace,
|
||||
layer_action_menu,
|
||||
],
|
||||
height = page.height,
|
||||
width = page.width,
|
||||
)
|
||||
|
||||
page.full_page = full_page
|
||||
|
||||
page.title = "Stable Diffusion Playground"
|
||||
page.add(workspace)
|
||||
page.add(full_page)
|
||||
|
||||
page.settings_window.setup(page.session.get('settings'))
|
||||
page.gallery_window.setup()
|
||||
|
Loading…
Reference in New Issue
Block a user