started to move all module calls to main(flet ui)

This commit is contained in:
aedh carrick 2022-12-25 18:42:15 -06:00
parent 5b71cbd5df
commit 092d35e527
6 changed files with 105 additions and 40 deletions

View File

@ -22,8 +22,8 @@ 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, e):
self.layer_panel.add_blank_layer(e)
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)
@ -47,6 +47,11 @@ class AssetManager(ft.Container):
for tab in self.tabs:
tab.content.margin = margin
def resize_asset_manager(self, e: ft.DragUpdateEvent):
self.page.left_panel_width = max(250, self.page.left_panel_width + e.delta_x)
self.width = self.page.left_panel_width
self.page.update()
class AssetPanel(ft.Container):
pass
@ -123,7 +128,7 @@ class LayerPanel(ft.Container):
self.page.property_manager.refresh_layer_properties()
self.update()
def add_blank_layer(self, e):
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)
@ -217,15 +222,17 @@ asset_panel = AssetPanel(
),
)
def resize_asset_manager(e: ft.DragUpdateEvent):
e.page.left_panel_width = max(250, e.page.left_panel_width + e.delta_x)
asset_manager.width = e.page.left_panel_width
e.page.update()
def resize_asset_manager(e):
asset_manager.resize_asset_manager(e)
def realign_canvas(e):
e.page.align_canvas()
asset_manager_dragbar = ft.GestureDetector(
mouse_cursor = ft.MouseCursor.RESIZE_COLUMN,
drag_interval = 50,
on_pan_update = resize_asset_manager,
on_pan_end = realign_canvas,
content = ft.VerticalDivider(),
)

View File

@ -20,16 +20,10 @@ class Canvas(ft.Container):
self.overlay.size_display.content.color = self.page.text_color
self.overlay.size_display.content.size = self.page.text_size
self.add_canvas_background()
self.center_canvas(self)
self.center_canvas()
self.refresh_canvas()
self.update()
def lock_canvas(self):
self.overlay.cover.lock_canvas()
def unlock_canvas(self):
self.overlay.cover.unlock_canvas()
def refresh_canvas(self):
self.overlay.refresh_canvas_overlay()
self.page.update()
@ -47,7 +41,7 @@ class Canvas(ft.Container):
def get_image_stack_preview(self):
return self.image_stack.get_preview()
def center_canvas(self, e):
def center_canvas(self):
width, height = self.page.get_viewport_size()
self.image_stack.offset_x = 0
self.image_stack.offset_y = 0
@ -57,7 +51,7 @@ class Canvas(ft.Container):
self.overlay.frame.top = self.image_stack.top
self.update()
def align_canvas(self, e):
def align_canvas(self):
width, height = self.page.get_viewport_size()
self.image_stack.left = (width * 0.5) - (self.image_stack.width * 0.5) + self.image_stack.offset_x
self.image_stack.top = (height * 0.5) - (self.image_stack.height * 0.5) + self.image_stack.offset_y
@ -74,7 +68,7 @@ class Canvas(ft.Container):
self.image_stack.offset_y = max(self.image_stack.offset_y, (height - self.image_stack.height) * 0.5)
self.image_stack.offset_x = min(self.image_stack.offset_x, (self.image_stack.width - width) * 0.5)
self.image_stack.offset_y = min(self.image_stack.offset_y, (self.image_stack.height - height) * 0.5)
self.align_canvas(e)
self.align_canvas()
def zoom_in(self, e):
if self.image_stack.scale >= 4.0:
@ -83,7 +77,7 @@ class Canvas(ft.Container):
self.image_stack.scale += 0.05
self.image_stack.get_scaled_size()
self.overlay.frame.scale = self.image_stack.scale
self.align_canvas(e)
self.align_canvas()
def zoom_out(self, e):
if self.image_stack.scale <= 0.1:
@ -92,7 +86,10 @@ class Canvas(ft.Container):
self.image_stack.scale -= 0.05
self.overlay.frame.scale = self.image_stack.scale
self.image_stack.get_scaled_size()
self.align_canvas(e)
self.align_canvas()
def clear_tools(self):
self.overlay.clear_tools()
def set_current_tool(self, tool):
if tool == 'pan':
@ -114,6 +111,7 @@ class Canvas(ft.Container):
pass
self.update()
class ImageStack(ft.Container):
def add_canvas_background(self):
image = self.page.canvas_background
@ -169,7 +167,7 @@ class ImageStack(ft.Container):
layer_image.offset_y = 0
self.center_layer(layer_image)
self.content.controls.append(layer_image)
self.page.tool_manager.enable_tools()
self.page.enable_tools()
canvas.refresh_canvas()
def get_preview(self):
@ -224,15 +222,16 @@ class CanvasGestures(ft.GestureDetector):
class CanvasOverlay(ft.Stack):
def refresh_canvas_overlay(self):
self.refresh_canvas_size_display()
self.refresh_canvas_preview()
self.page.refresh_canvas_preview()
def refresh_canvas_size_display(self):
self.size_display.content.value = str(self.page.canvas_size)
self.update()
def refresh_canvas_preview(self):
preview = canvas.get_image_stack_preview()
self.page.property_manager.set_preview_image(preview)
def clear_tools(self):
for tool in canvas_tools.content.controls:
tool.selected = False
# ImageStack == ft.Container
@ -339,7 +338,7 @@ canvas_size_display = ft.Container(
)
def center_canvas(e):
canvas.center_canvas(e)
canvas.center_canvas()
center_canvas_button = ft.IconButton(
content = ft.Icon(ft.icons.FILTER_CENTER_FOCUS_OUTLINED),
@ -348,12 +347,13 @@ center_canvas_button = ft.IconButton(
)
def set_pan_tool(e):
canvas.set_current_tool('pan')
e.page.set_current_tool(e)
pan_canvas_button = ft.IconButton(
content = ft.Icon(ft.icons.PAN_TOOL_OUTLINED),
tooltip = 'pan canvas',
on_click = set_pan_tool,
data = {'label':'pan'},
)
def zoom_in_canvas(e):

View File

@ -81,10 +81,14 @@ video_editor_panel = ft.Column(
def resize_messages(e):
messages.resize_messages(e)
def realign_canvas(e):
e.page.align_canvas()
messages_dragbar = ft.GestureDetector(
mouse_cursor = ft.MouseCursor.RESIZE_ROW,
drag_interval = 50,
on_pan_update = resize_messages,
on_pan_end = realign_canvas,
content = ft.Divider(),
)

View File

@ -58,6 +58,13 @@ class PropertyManager(ft.Container):
def refresh_layer_properties(self):
self.property_panel.refresh_layer_properties()
def resize_property_manager(self, e: ft.DragUpdateEvent):
self.page.right_panel_width = max(250, self.page.right_panel_width - e.delta_x)
self.width = self.page.right_panel_width
self.property_panel.preview.width = self.page.right_panel_width
self.page.update()
class PropertyPanel(ft.Container):
def resize_preview(self, e):
self.preview.height = max(200, self.preview.height + e.delta_y)
@ -271,16 +278,17 @@ output_panel = PropertyPanel(
),
)
def resize_property_manager(e: ft.DragUpdateEvent):
e.page.right_panel_width = max(250, e.page.right_panel_width - e.delta_x)
property_manager.width = e.page.right_panel_width
property_panel.preview.width = e.page.right_panel_width
e.page.update()
def resize_property_manager(e):
property_manager.resize_property_manager(e)
def realign_canvas(e):
e.page.align_canvas()
property_manager_dragbar = ft.GestureDetector(
mouse_cursor = ft.MouseCursor.RESIZE_COLUMN,
drag_interval = 50,
on_pan_update = resize_property_manager,
on_pan_end = realign_canvas,
content = ft.VerticalDivider()
)

View File

@ -6,21 +6,18 @@ import flet as ft
# utils imports
from scripts import flet_utils
def open_gallery(e):
e.page.open_gallery(e)
def blank_layer(e):
e.page.asset_manager.add_blank_layer(e)
e.page.add_blank_layer()
def load_image(e):
e.page.file_picker.pick_files(file_type = 'image', allow_multiple = True)
e.page.load_image()
def tool_select(e):
toolbox.clear_tools()
e.page.current_tool = e.control.data['label']
e.page.canvas.set_current_tool(e.control.data['label'])
e.control.selected = True
e.page.update()
e.page.set_current_tool(e)
class Action():
@ -31,7 +28,6 @@ class Action():
self.on_click = on_click
self.disabled = False
action_list = [
Action('gallery', ft.icons.DASHBOARD_OUTLINED, 'Gallery', open_gallery),
Action('blank layer', ft.icons.ADD_OUTLINED, 'Add blank layer', blank_layer),
@ -47,7 +43,6 @@ class Tool():
self.on_click = tool_select
self.disabled = True
tool_list = [
Tool('move', ft.icons.OPEN_WITH_OUTLINED, 'Move layer(s)'),
Tool('select', ft.icons.HIGHLIGHT_ALT_OUTLINED, 'Select tool'),
@ -94,6 +89,9 @@ class ToolManager(ft.Container):
tool.disabled = False
self.update()
def clear_tools(self):
self.toolbox.clear_tools()
class ToolBox(ft.Container):
def get_tools(self):
for action in action_list:
@ -173,10 +171,14 @@ tool_properties = ToolPropertyPanel(
def resize_tool_manager(e):
tool_manager.resize_tool_manager(e)
def realign_canvas(e):
e.page.align_canvas()
tool_manager_dragbar = ft.GestureDetector(
mouse_cursor = ft.MouseCursor.RESIZE_COLUMN,
drag_interval = 50,
on_pan_update = resize_tool_manager,
on_pan_end = realign_canvas,
content = ft.VerticalDivider(),
)

View File

@ -37,6 +37,7 @@ def main(page: ft.Page):
page.message = messages.message
page.max_message_history = 50
# ui
page.current_layout = 'Default'
page.titlebar_height = 50
@ -55,16 +56,20 @@ def main(page: ft.Page):
page.text_color = None
page.text_size = 14
page.icon_size = 20
page.padding = 0
page.margin = 0
page.container_padding = 0
page.container_margin = 0
page.tab_color = 'white_10'
page.tab_padding = ft.padding.only(left = 2, top = 12, right = 2, bottom = 8)
page.tab_margin = 0
page.divider_height = 10
page.vertical_divider_width = 10
# titlebar
page.titlebar = titlebar
@ -89,15 +94,41 @@ def main(page: ft.Page):
page.set_layout = set_layout
# tools
page.tool_manager = tool_manager
page.current_tool = 'pan'
def enable_tools():
page.tool_manager.enable_tools()
page.enable_tools = enable_tools
def set_current_tool(e):
page.tool_manager.clear_tools()
page.canvas.clear_tools()
e.control.selected = True
page.current_tool = e.control.data['label']
page.canvas.set_current_tool(e.control.data['label'])
page.update()
page.set_current_tool = set_current_tool
# asset manager
page.asset_manager = asset_manager
page.active_layer = None
page.layer_height = 50
def add_blank_layer():
page.asset_manager.add_blank_layer()
page.add_blank_layer = add_blank_layer
def load_image():
page.file_picker.pick_files(file_type = 'image', allow_multiple = True)
page.load_image = load_image
# canvas
page.canvas = canvas
page.canvas_background = flet_utils.get_canvas_background('webui/flet/assets/images/default_grid_texture.png')
@ -110,9 +141,22 @@ def main(page: ft.Page):
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()
page.align_canvas = align_canvas
# property manager
page.property_manager = property_manager
# settings
def load_settings():
settings = flet_utils.get_user_settings_from_config()