Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion python/apps/trolli/src/app_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
)
from sidebar import Sidebar


class AppLayout(Row):
def __init__(self, app, page: Page, store: DataStore, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
54 changes: 20 additions & 34 deletions python/apps/trolli/src/board.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import itertools
from flet import (
UserControl,
Column,
Row,
FloatingActionButton,
ElevatedButton,
Text,
GridView,
Page,
Container,
TextField,
AlertDialog,
Expand All @@ -23,56 +23,42 @@
from data_store import DataStore


class Board(UserControl):
class Board(Container):
id_counter = itertools.count()

def __init__(self, app, store: DataStore, name: str):
super().__init__()
def __init__(self, app, store: DataStore, name: str, page: Page):
self.page = page
self.board_id = next(Board.id_counter)
self.store: DataStore = store
self.app = app
self.name = name
self.add_list_button = FloatingActionButton(
icon=icons.ADD, text="add a list", height=30, on_click=self.create_list)

self.board_lists = [
self.add_list_button
]
for l in self.store.get_lists_by_board(self.board_id):
self.add_list(l)

self.list_wrap = Row(
self.board_lists,
self.board_lists = Row(
controls=[self.add_list_button],
vertical_alignment="start",
visible=True,
scroll="auto",
expand=True,
width=(self.app.page.width - 310),
height=(self.app.page.height - 95)
height=(self.app.page.height - 95),
)
for l in self.store.get_lists_by_board(self.board_id):
self.add_list(l)

def build(self):
self.view = Container(
content=Column(
controls=[
self.list_wrap
],

scroll="auto",
expand=True
),
super().__init__(
content=self.board_lists,
data=self,
margin=margin.all(0),
padding=padding.only(top=10, right=0),
height=self.app.page.height,
height=self.app.page.height
)
return self.view

def resize(self, nav_rail_extended, width, height):
self.list_wrap.width = (
self.board_lists.width = (
width - 310) if nav_rail_extended else (width - 50)
self.view.height = height
self.list_wrap.update()
self.view.update()
self.height = height
self.update()

def create_list(self, e):

Expand Down Expand Up @@ -112,12 +98,11 @@ def set_color(e):

def close_dlg(e):
if (hasattr(e.control, "text") and not e.control.text == "Cancel") or (type(e.control) is TextField and e.control.value != ""):
new_list = BoardList(self, self.store, dialog_text.value,
new_list = BoardList(self, self.store, dialog_text.value, self.page,
color=color_options.data)
self.add_list(new_list)
dialog.open = False
self.page.update()
self.update()

def textfield_change(e):
if dialog_text.value == "":
Expand Down Expand Up @@ -154,9 +139,10 @@ def remove_list(self, list: BoardList, e):
self.store.remove_list(self.board_id, list.board_list_id)
self.update()

def add_list(self, list: BoardList):
self.board_lists.insert(-1, list)
def add_list(self, list):
self.board_lists.controls.insert(-1, list)
self.store.add_list(self.board_id, list)
self.page.update()

def color_option_creator(self, color: str):
return Container(
Expand Down
28 changes: 14 additions & 14 deletions python/apps/trolli/src/board_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from board import Board
import itertools
from flet import (
UserControl,
Draggable,
DragTarget,
Column,
Row,
Text,
Icon,
Page,
PopupMenuButton,
PopupMenuItem,
Container,
Expand All @@ -26,21 +26,18 @@
from data_store import DataStore


class BoardList(UserControl):
class BoardList(Container):
id_counter = itertools.count()

def __init__(self, board: "Board", store: DataStore, title: str, color: str = ""):
super().__init__()
def __init__(self, board: "Board", store: DataStore, title: str, page: Page, color: str = ""):
self.page = page
self.board_list_id = next(BoardList.id_counter)
self.store: DataStore = store
self.board = board
self.title = title
self.color = color
self.items = Column([], tight=True, spacing=4)
self.items.controls = self.store.get_items(self.board_list_id)

def build(self):

self.new_item_field = TextField(
label="new card name", height=50, bgcolor=colors.WHITE, on_submit=self.add_item_handler)

Expand All @@ -51,11 +48,13 @@ def build(self):
width=200,
opacity=0.0
)

self.edit_field = Row([
TextField(value=self.title, width=150, height=40,
content_padding=padding.only(left=10, bottom=10)),
TextButton(text="Save", on_click=self.save_title)
])

self.header = Row(
controls=[
Text(value=self.title, style="titleMedium",
Expand Down Expand Up @@ -103,6 +102,7 @@ def build(self):
padding=padding.only(
bottom=10, right=10, left=10, top=5)
)

self.view = DragTarget(
group="items",
content=Draggable(
Expand All @@ -121,9 +121,11 @@ def build(self):
on_will_accept=self.item_will_drag_accept,
on_leave=self.item_drag_leave
)

return self.view

super().__init__(
content=self.view,
data=self
)

def item_drag_accept(self, e):
src = self.page.get_control(e.src_id)
self.add_item(src.data.item_text)
Expand All @@ -142,13 +144,12 @@ def item_drag_leave(self, e):

def list_drag_accept(self, e):
src = self.page.get_control(e.src_id)
l = self.board.board_lists
l = self.board.content.controls
to_index = l.index(e.control.data)
from_index = l.index(src.content.data)
l[to_index], l[from_index] = l[from_index], l[to_index]
self.inner_list.border = border.all(2, colors.BLACK12)
self.board.update()
self.update()
self.page.update()

def list_will_drag_accept(self, e):
if e.data == "true":
Expand All @@ -171,7 +172,6 @@ def save_title(self, e):
self.title = self.edit_field.controls[0].value
self.header.controls[0] = Text(value=self.title, style="titleMedium",
text_align="left", overflow="clip", expand=True)

self.header.controls[1].visible = True
self.update()

Expand Down
12 changes: 4 additions & 8 deletions python/apps/trolli/src/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@
Container,
Checkbox,
Row,
UserControl,
Card,
border_radius,
)
from data_store import DataStore


class Item(UserControl):
class Item(Container):
id_counter = itertools.count()

def __init__(self, list: "BoardList", store: DataStore, item_text: str):
super().__init__()
self.item_id = next(Item.id_counter)
self.store: DataStore = store
self.list = list
Expand All @@ -35,9 +32,6 @@ def __init__(self, list: "BoardList", store: DataStore, item_text: str):
elevation=1,
data=self.list
)

def build(self):

self.view = Draggable(
group="items",
content=DragTarget(
Expand All @@ -49,7 +43,9 @@ def build(self):
),
data=self
)
return self.view
super().__init__(
content=self.view
)

def drag_accept(self, e):
src = self.page.get_control(e.src_id)
Expand Down
39 changes: 23 additions & 16 deletions python/apps/trolli/src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import flet
from app_layout import AppLayout
from board import Board
from board_list import BoardList
from data_store import DataStore
from flet import (
AlertDialog,
Expand All @@ -12,12 +13,10 @@
Page,
PopupMenuButton,
PopupMenuItem,
RoundedRectangleBorder,
Row,
TemplateRoute,
Text,
TextField,
UserControl,
View,
colors,
icons,
Expand All @@ -29,9 +28,8 @@
from user import User


class TrelloApp(UserControl):
class TrelloApp(AppLayout):
def __init__(self, page: Page, store: DataStore):
super().__init__()
self.page = page
self.store: DataStore = store
self.page.on_route_change = self.route_change
Expand All @@ -58,23 +56,31 @@ def __init__(self, page: Page, store: DataStore):
)
self.page.appbar = self.appbar
self.page.update()

def build(self):
self.layout = AppLayout(
super().__init__(
self,
self.page,
self.store,
tight=True,
expand=True,
vertical_alignment="start",
)
return self.layout

# def build(self):
# self.layout = AppLayout(
# self,
# self.page,
# self.store,
# tight=True,
# expand=True,
# vertical_alignment="start",
# )
# return self.layout

def initialize(self):
self.page.views.append(
View(
"/",
[self.appbar, self.layout],
[self.appbar, self],
padding=padding.all(0),
bgcolor=colors.BLUE_GREY_200,
)
Expand Down Expand Up @@ -131,11 +137,11 @@ def route_change(self, e):
if int(troute.id) > len(self.store.get_boards()):
self.page.go("/")
return
self.layout.set_board_view(int(troute.id))
self.set_board_view(int(troute.id))
elif troute.match("/boards"):
self.layout.set_all_boards_view()
self.set_all_boards_view()
elif troute.match("/members"):
self.layout.set_members_view()
self.set_members_view()
self.page.update()

def add_board(self, e):
Expand Down Expand Up @@ -183,13 +189,13 @@ def textfield_change(e):
dialog_text.focus()

def create_new_board(self, board_name):
new_board = Board(self, self.store, board_name)
new_board = Board(self, self.store, board_name, self.page)
self.store.add_board(new_board)
self.layout.hydrate_all_boards_view()
self.hydrate_all_boards_view()

def delete_board(self, e):
self.store.remove_board(e.control.data)
self.layout.set_all_boards_view()
self.set_all_boards_view()


def main(page: Page):
Expand All @@ -205,5 +211,6 @@ def main(page: Page):
page.update()
app.initialize()


print("flet version: ", flet.version.version)
print("flet path: ", flet.__file__)
flet.app(target=main, assets_dir="../assets")
Loading