Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
967cf23
autocomplete tests
InesaFitsner Dec 3, 2024
d8bd2cd
checkbox examples
InesaFitsner Dec 5, 2024
980da8e
text with different properties example updated
InesaFitsner Dec 5, 2024
a140a04
text example updated
InesaFitsner Dec 5, 2024
8e7e585
update text example
InesaFitsner Dec 5, 2024
52403f6
source_code for text example
InesaFitsner Dec 5, 2024
1cc0ec8
text example updated
InesaFitsner Dec 5, 2024
b6b2d98
text example
InesaFitsner Dec 5, 2024
da5a6cc
text example updated
InesaFitsner Dec 6, 2024
0d3d40b
dataclass value_type for style
InesaFitsner Dec 6, 2024
ed5f450
open properties dialog
InesaFitsner Dec 6, 2024
ecf3614
Update properties_table.py
InesaFitsner Dec 6, 2024
705c8f7
update text example
InesaFitsner Dec 9, 2024
5c74473
updated text example
InesaFitsner Dec 9, 2024
8d35b80
text example with ExpansionPanelList
InesaFitsner Dec 10, 2024
098fa5d
Update properties_table.py
InesaFitsner Dec 11, 2024
89ab503
Update properties_table.py
InesaFitsner Dec 12, 2024
ccf308e
text example
InesaFitsner Dec 12, 2024
9cc4221
text example
InesaFitsner Dec 12, 2024
fa48208
value control changed to Slider for numbers
InesaFitsner Dec 12, 2024
a933ae2
list of Spans
InesaFitsner Dec 12, 2024
41adec3
spans
InesaFitsner Dec 12, 2024
19115e7
Update properties_table.py
InesaFitsner Dec 12, 2024
4edaeda
Update properties_table.py
InesaFitsner Dec 12, 2024
c56b30f
property that is a list
InesaFitsner Dec 13, 2024
aba95c4
text example
InesaFitsner Dec 13, 2024
a97ae9a
update text example
InesaFitsner Dec 14, 2024
1093e95
Update properties_table.py
InesaFitsner Dec 14, 2024
1ddf1d8
Update 10_text_with_variable_properties.py
InesaFitsner Dec 14, 2024
f7c7248
Update 10_text_with_variable_properties.py
InesaFitsner Jan 6, 2025
f22885a
info icon with tooltip for property description
InesaFitsner Jan 6, 2025
224205b
Update 10_text_with_variable_properties.py
InesaFitsner Jan 6, 2025
bf4bbae
text example
InesaFitsner Jan 9, 2025
0191543
Update properties_table.py
InesaFitsner Jan 9, 2025
f1b218f
update text example
InesaFitsner Jan 9, 2025
36babf7
add/delete property buttons
InesaFitsner Jan 14, 2025
513bb0a
on-off switch for dataclass property
InesaFitsner Jan 14, 2025
5f271c5
Update 10_text_with_variable_properties.py
InesaFitsner Jan 14, 2025
9596861
delete button for list items
InesaFitsner Jan 14, 2025
13356cf
text example
InesaFitsner Jan 16, 2025
e197b6e
delete list item
InesaFitsner Jan 16, 2025
9974c81
Update properties_table.py
InesaFitsner Jan 16, 2025
14a0144
delete button
InesaFitsner Jan 16, 2025
1096bf7
Update properties_table.py
InesaFitsner Jan 17, 2025
95ab508
updated pyproject.toml
InesaFitsner Jan 23, 2025
b12011b
changed pyproject.toml
InesaFitsner Jan 23, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions python/apps/controls-gallery/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ FROM python:3-alpine

WORKDIR /app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

RUN pip install --no-cache-dir .

EXPOSE 8000

CMD ["python", "main.py"]
281 changes: 281 additions & 0 deletions python/apps/controls-gallery/components/properties_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
import flet as ft


class SourceCode(ft.Text):
def __init__(self, control):
super().__init__()
self.control = control
# self.update_source_code(control)

def did_mount(self):
self.update_source_code(self.control)

def update_source_code(self, control):
text = ""
# for property in self.properties:
# if type(getattr(self.control, property["name"])).__name__ == "str":
# property_value = f"""'{getattr(self.control, property["name"])}'"""
# else:
# property_value = getattr(self.control, property["name"])
# text = text + f"{property["name"]}={property_value}, "
# control_name = type(self.control).__name__
print(control)

# code = f"""ft.{control_name}({text})"""
# self.value = code
self.update()


class PropertyName(ft.Row):
def __init__(self, name, description="Description"):
super().__init__()
self.controls = [
ft.Text(name),
ft.Icon(
name=ft.Icons.INFO_OUTLINE, tooltip=ft.Tooltip(message=description)
),
]


class PropertiesList(ft.ListView):
def __init__(self, properties, control, top_control=None):
super().__init__()
self.properties = properties
self.control = control
self.divider_thickness = 3
self.width = 500
self.auto_scroll = True
if top_control == None:
self.top_control = control
else:
self.top_control = top_control
self.controls = self.get_properties_list()

def get_dataclass_tile(self, property, object):

def switch_changed(e):
if e.control.value:
setattr(self.control, property["name"], object)
else:
setattr(self.control, property["name"], None)
self.top_control.update()

if getattr(self.control, property["name"]) == None:
switch_value = False
else:
switch_value = True
switch = ft.Switch(
value=switch_value,
on_change=switch_changed,
tooltip=ft.Tooltip(f"Set/Unset {property["name"]} property"),
)

return ft.ExpansionTile(
bgcolor=ft.Colors.OUTLINE_VARIANT,
title=PropertyName(
name=property["name"], description=property["description"]
),
controls=[
ft.Row(controls=[switch], alignment=ft.MainAxisAlignment.START),
PropertiesList(
properties=property["properties"],
control=object,
top_control=self.top_control,
),
],
)

def get_properties_list(self):
controls = []

for property in self.properties:

def add_list_item(e):
items_list = getattr(self.control, property["name"])
if items_list == None:
items_list = []
dataclass_type = property["dataclass"]
# adding new item to a list
items_list.append(dataclass_type())
# updating property with the new list
setattr(self.control, property["name"], items_list)
self.controls = self.get_properties_list()
self.update()

value = getattr(self.control, property["name"])

if "list" in property["value_type"]:
list_items = []
n = 0
if value != None:
for item in value:

def delete_item(e):
items_list = getattr(self.control, property["name"])
# removing item from the list
items_list.remove(items_list[e.control.data])
# updating property with the new list
setattr(self.control, property["name"], items_list)
# removing the tile
e.control.parent.parent.parent.controls.remove(
e.control.parent.parent
)
self.update()
self.control.update()

list_items.append(
ft.ExpansionTile(
bgcolor=ft.Colors.OUTLINE_VARIANT,
title=ft.Text(f"{property["name"]}{n+1}"),
controls=[
PropertiesList(
properties=property["properties"],
# control=ft.TextSpan(text="Span 1 Text"),
control=value[n],
top_control=self.top_control,
),
ft.Row(
controls=[
ft.IconButton(
ft.Icons.DELETE,
on_click=delete_item,
tooltip=ft.Tooltip(
f"Delete {property["name"]}{n+1}"
),
data=n,
)
]
),
],
)
)
n += 1
controls.append(
ft.Container(
bgcolor=ft.Colors.ON_INVERSE_SURFACE,
margin=5,
padding=5,
border_radius=3,
content=ft.Column(
[
ft.Row(
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
controls=[
ft.Text(property["name"]),
ft.IconButton(
icon=ft.Icons.ADD, on_click=add_list_item
),
# list_items,
],
)
]
+ list_items,
),
)
)
elif property["value_type"] == "dataclass":
if value == None:
dataclass_type = property["dataclass"]
value = dataclass_type()
print(value)
# setting badge = ft.Badge()
# setattr(self.control, property["name"], value)
controls.append(self.get_dataclass_tile(property, value))
else:
controls.append(
ft.Container(
bgcolor=ft.Colors.ON_INVERSE_SURFACE,
margin=5,
padding=5,
border_radius=3,
content=ft.Row(
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
controls=[
# ft.Text(property["name"]),
PropertyName(
name=property["name"],
description=property["description"],
),
self.get_value_control(property),
],
),
)
)

return controls

def value_changed(self, e):
print(f"Control: {self.control}!")
print(f"Top Control: {self.top_control}!")
print(f"Property: {e.control.data}!")

print(f"Value: {e.control.value}!")

setattr(self.control, e.control.data, e.control.value)
self.top_control.update()

def get_value_control(self, property):

value = getattr(self.control, property["name"])

match property["value_type"]:
case "str":
return ft.TextField(
border_color=ft.Colors.SECONDARY,
content_padding=3,
value=value,
data=property["name"],
on_change=self.value_changed,
)
case "number":
return ft.Row(
alignment=ft.MainAxisAlignment.CENTER,
controls=[
ft.Text(property["min"]),
ft.Slider(
min=property["min"],
max=property["max"],
label="{value}%",
value=value,
data=property["name"],
on_change=self.value_changed,
),
ft.Text(property["max"]),
],
)
case "bool":
return ft.Checkbox(
value=value,
data=property["name"],
on_change=self.value_changed,
)
case "enum":

options = []

options_list = property["values"]
for item in options_list:
options.append(ft.dropdown.Option(item.value))

return ft.Dropdown(
options=options,
value=value,
data=property["name"],
on_change=self.value_changed,
)

case "dataclass":

if value == None:
print(f"This dataclass value is None")

properties_list = PropertiesList(
properties=property["properties"], control=value
)

return properties_list
# ft.Container(bgcolor=ft.Colors.YELLOW, width=30, height=30)

# If an exact match is not confirmed, this last case will be used if provided
case _:
return ft.Text("Something's wrong with the type")

This file was deleted.

Loading