Skip to content

Commit

Permalink
Made figuritive changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NAFAYT committed Nov 15, 2023
1 parent fdefe89 commit d80d860
Show file tree
Hide file tree
Showing 13 changed files with 972 additions and 68 deletions.
234 changes: 234 additions & 0 deletions .lh/testy.py.json

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions .lh/widgets/widget_list.json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"sourceFile": "widgets/widget_list.json",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 6,
"patches": [
{
"date": 1699954770152,
"content": "Index: \n===================================================================\n--- \n+++ \n"
},
{
"date": 1699954781615,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,1 +1,3 @@\n-[]\n\\ No newline at end of file\n+[{\n+ \"\"\n+}]\n\\ No newline at end of file\n"
},
{
"date": 1699954790497,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,3 +1,1 @@\n-[{\n- \"\"\n-}]\n\\ No newline at end of file\n+[]\n\\ No newline at end of file\n"
},
{
"date": 1699954796267,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,1 +1,1 @@\n-[]\n\\ No newline at end of file\n+[\"Container\"]\n\\ No newline at end of file\n"
},
{
"date": 1699954801383,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,1 +1,1 @@\n-[\"Container\"]\n\\ No newline at end of file\n+[{}]\n\\ No newline at end of file\n"
},
{
"date": 1699954808470,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,1 +1,3 @@\n-[{}]\n\\ No newline at end of file\n+[{\n+ \"Container\":\"c\"\n+}]\n\\ No newline at end of file\n"
},
{
"date": 1699954818898,
"content": "Index: \n===================================================================\n--- \n+++ \n@@ -1,3 +1,3 @@\n [{\n- \"Container\":\"c\"\n+ \"Container\":\"Container\"\n }]\n\\ No newline at end of file\n"
}
],
"date": 1699954770152,
"name": "Commit-0",
"content": "[]"
}
]
}
318 changes: 318 additions & 0 deletions .lh/widgets/widgets.json.json

Large diffs are not rendered by default.

28 changes: 2 additions & 26 deletions DesignPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,14 @@ def build(self):
x1 = ToolbarItem("x1")
x2 = ToolbarItem("x2")
x3 = ToolbarItem("x3")
x4 = ToolbarItem("x4")
x5 = ToolbarItem("x5")
x6 = ToolbarItem("x5")
x7 = ToolbarItem("x5")
x8 = ToolbarItem("x5")
x9 = ToolbarItem("x5")
x11 = ToolbarItem("x5")
x12 = ToolbarItem("x5")
x13 = ToolbarItem("x5")
x14 = ToolbarItem("x5")
x15 = ToolbarItem("x5")
x16 = ToolbarItem("x5")
x17 = ToolbarItem("x5")

itemslist = [
Container,
Row,
x1,
x2,
x3,
x4,
x5,
x6,
x7,
x8,
x9,
x11,
x12,
x13,
x14,
x15,
x16,
x17,

]
toolbaritems = ToolbarItems(itemslist)
self.toolbar = Toolbar(toolbaritems)
Expand Down
150 changes: 121 additions & 29 deletions Designer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import flet as ft
from flet import Container
from Parser.Parserengine import Parser

import json
from UI.ToolbarItem import ToolbarItem

# ft.Draggable()
Expand All @@ -10,49 +10,141 @@
class DesignerSection(ft.UserControl):
def __init__(self):
self.parser = Parser()
self.list_file = "widgets/widgets_list.json"
self.all_controls = {}
self.all_regions = {}
self.selected = None
self.itemName = None
self.buttonDown = False
self.outline_width = 3
self.outlineContainer = ft.Container(
border=ft.border.all(color=ft.colors.WHITE, width=self.outline_width),
)
self.control_counter = 1
super().__init__()

def on_pan_update1(self, e: ft.DragUpdateEvent):
# e.control.left = max(0, (e.control.left or 0) + e.delta_x)
# e.control.top = max(0, (e.control.top or 0) + e.delta_y)
e.control.width = max(50, (e.control.width or 0) + e.delta_x)
e.control.height = max(50, (e.control.height or 0) + e.delta_y)
e.control.update()
def load_control_list(self):
with open(self.list_file, "rb") as f:
self.supportedControls = list(
map(lambda x: list(x.keys())[0], json.loads(f.read()))
)

def buttonDown1(self, e: ft.TapEvent):
self.buttonDown = True

def show_outline(self):
self.outlineContainer.left = self.selected.left - self.outline_width
self.outlineContainer.top = self.selected.top - self.outline_width
self.outlineContainer.width = self.selected.width + (self.outline_width * 2)
self.outlineContainer.height = self.selected.height + (self.outline_width * 2)
self.outlineContainer.visible = True
self.outlineContainer.update()

def isInRange(self, x, y, region):
if (
(x >= region.get("begin_x"))
and (y >= region.get("begin_y"))
and (x <= region.get("end_x"))
and (y <= region.get("end_y"))
):
return True
return False

def itemselection(self, e: ft.TapEvent):
self.selected = None
self.outlineContainer.visible = False
self.outlineContainer.update()
for name, region in self.all_regions.items():
if self.isInRange(e.local_x, e.local_y, region):
item = self.all_controls.get(name)
self.selected = item
self.itemName = name
break
if self.selected == None:
return
self.show_outline()
return

def on_pan_end(self, e: ft.DragEndEvent):
self.show_outline()

def on_pan_update(self, e: ft.DragUpdateEvent):
if self.selected == None:
return
self.outlineContainer.visible = False
self.outlineContainer.update()
self.new_left = max(80, (self.selected.left or 0) + e.delta_x)
self.new_top = max(30, (self.selected.top or 0) + e.delta_y)
self.all_regions.update(
{
self.itemName: {
"begin_x": self.new_left,
"begin_y": self.new_top,
"end_x": self.new_left + self.selected.width,
"end_y": self.new_top + self.selected.height,
}
}
)
self.selected.left = self.new_left
self.selected.top = self.new_top
self.selected.update()

def accept_draggable(self, e: ft.DragTargetAcceptEvent):
ctrlname = e.page.get_control(e.src_id)
name = ctrlname.content.content.value
self.container = e.control.content.controls
object = globals()[name]
object = object(bgcolor=ft.colors.RED, width=100, height=200)
self.container.append(
ft.GestureDetector(
on_pan_update=self.on_pan_update1,
left=max(0, 100), # Ensure initial left is not less than 0
top=50,
content=object,
object = object(
bgcolor=ft.colors.RED,
width=100,
height=200,
left=200 + (self.control_counter+5),
top=200,
)
unique_name = f"container{self.control_counter}"
print(unique_name)
self.all_controls.update({unique_name: object})
self.all_regions.update(
{
unique_name: {
"begin_x": object.left,
"begin_y": object.top,
"end_x": object.left + object.width,
"end_y": object.top + object.height,
}
}
)
(
self.main_stack.controls.append(
list(self.all_controls.values())[self.control_counter - 1]
)
)

self.control_counter += 1
e.control.update()
self.main_stack.update()

def build(self):
self.main_stack = ft.Stack(
controls=[
ft.Container(
border=ft.border.all(1.9, color="#383838"),
border_radius=ft.border_radius.all(8),
bgcolor=ft.colors.BLACK,
# alignment=ft.alignment.center,
),
self.outlineContainer,
],
)
self.DesignerSection1 = ft.DragTarget(
group="widget",
on_accept=self.accept_draggable,
content=ft.Stack(
controls=[
ft.Container(
border=ft.border.all(1.9, color="#383838"),
border_radius=ft.border_radius.all(8),
bgcolor=ft.colors.BLACK,
margin=ft.margin.only(left=75, top=25),
width=1200,
height=1250,
# alignment=ft.alignment.center,
),
],
content=ft.GestureDetector(
width=1200,
height=1290,
content=self.main_stack,
on_tap_down=self.buttonDown1,
on_pan_update=self.on_pan_update,
on_pan_end=self.on_pan_end,
on_tap_up=self.itemselection,
),
)

return self.DesignerSection1
2 changes: 1 addition & 1 deletion Parser/LoadDesignfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def ConstructPage(self, page: ft.Page):
# Initialization of the page
self.__page = page
for control in self.__keys.values():
if(not control.__dict__.get("isChild")):
if not control.__dict__.get("isChild"):
self.__page.add(control)
page.window_height = 800
# page.theme = ft.theme.Theme(color_scheme_seed="cyan100")
Expand Down
Binary file modified Parser/__pycache__/Parserengine.cpython-311.pyc
Binary file not shown.
Binary file modified UI/__pycache__/ToolbarItem.cpython-311.pyc
Binary file not shown.
24 changes: 12 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from Parser.LoadDesignfile import LoadDesignFile
import flet
# from Parser.LoadDesignfile import LoadDesignFile
# import flet

ldf = LoadDesignFile(jsonfilepath="request.json")
# ldf = LoadDesignFile(jsonfilepath="request.json")


def update1(e):
ldf.b1.text = "update"
ldf.b1.update()
# def update1(e):
# ldf.b1.text = "update"
# ldf.b1.update()


ldf.b1.on_click = update1
# ldf.b1.on_click = update1


def update12(e):
ldf.b12.text = "update"
ldf.b12.update()
# def update12(e):
# ldf.b12.text = "update"
# ldf.b12.update()


ldf.b12.on_click = update12
ldf.run()
# ldf.b12.on_click = update12
# ldf.run()


# # # import the library
Expand Down
Loading

0 comments on commit d80d860

Please sign in to comment.