diff --git a/python/apps/trolli/src/app_layout.py b/python/apps/trolli/src/app_layout.py index 8ead344c..6caf5c65 100644 --- a/python/apps/trolli/src/app_layout.py +++ b/python/apps/trolli/src/app_layout.py @@ -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) diff --git a/python/apps/trolli/src/board.py b/python/apps/trolli/src/board.py index 2237b039..cd0c2623 100644 --- a/python/apps/trolli/src/board.py +++ b/python/apps/trolli/src/board.py @@ -1,12 +1,12 @@ import itertools from flet import ( - UserControl, Column, Row, FloatingActionButton, ElevatedButton, Text, GridView, + Page, Container, TextField, AlertDialog, @@ -23,11 +23,11 @@ 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 @@ -35,44 +35,30 @@ def __init__(self, app, store: DataStore, name: str): 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): @@ -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 == "": @@ -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( diff --git a/python/apps/trolli/src/board_list.py b/python/apps/trolli/src/board_list.py index 694ca340..08f4857f 100644 --- a/python/apps/trolli/src/board_list.py +++ b/python/apps/trolli/src/board_list.py @@ -3,13 +3,13 @@ from board import Board import itertools from flet import ( - UserControl, Draggable, DragTarget, Column, Row, Text, Icon, + Page, PopupMenuButton, PopupMenuItem, Container, @@ -26,11 +26,11 @@ 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 @@ -38,9 +38,6 @@ def __init__(self, board: "Board", store: DataStore, title: str, color: str = "" 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) @@ -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", @@ -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( @@ -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) @@ -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": @@ -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() diff --git a/python/apps/trolli/src/item.py b/python/apps/trolli/src/item.py index 8b76288c..cc5afaad 100644 --- a/python/apps/trolli/src/item.py +++ b/python/apps/trolli/src/item.py @@ -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 @@ -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( @@ -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) diff --git a/python/apps/trolli/src/main.py b/python/apps/trolli/src/main.py index b8b2191b..54454e69 100644 --- a/python/apps/trolli/src/main.py +++ b/python/apps/trolli/src/main.py @@ -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, @@ -12,12 +13,10 @@ Page, PopupMenuButton, PopupMenuItem, - RoundedRectangleBorder, Row, TemplateRoute, Text, TextField, - UserControl, View, colors, icons, @@ -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 @@ -58,9 +56,7 @@ 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, @@ -68,13 +64,23 @@ def build(self): 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, ) @@ -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): @@ -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): @@ -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") diff --git a/python/apps/trolli/src/sidebar.py b/python/apps/trolli/src/sidebar.py index c8771bdc..75123f67 100644 --- a/python/apps/trolli/src/sidebar.py +++ b/python/apps/trolli/src/sidebar.py @@ -1,5 +1,4 @@ from flet import ( - UserControl, Column, Container, IconButton, @@ -18,11 +17,9 @@ ) from data_store import DataStore - -class Sidebar(UserControl): +class Sidebar(Container): def __init__(self, app_layout, store: DataStore, page): - super().__init__() self.store: DataStore = store self.app_layout = app_layout self.nav_rail_visible = True @@ -39,8 +36,8 @@ def __init__(self, app_layout, store: DataStore, page): icon=icons.PERSON, selected_icon=icons.PERSON ), - ] + self.top_nav_rail = NavigationRail( selected_index=None, label_type="all", @@ -50,6 +47,7 @@ def __init__(self, app_layout, store: DataStore, page): extended=True, height=110 ) + self.bottom_nav_rail = NavigationRail( selected_index=None, label_type="all", @@ -60,8 +58,7 @@ def __init__(self, app_layout, store: DataStore, page): ) self.toggle_nav_rail_button = IconButton(icons.ARROW_BACK) - def build(self): - self.view = Container( + super().__init__( content=Column([ Row([ Text("Workspace"), @@ -88,11 +85,10 @@ def build(self): padding=padding.all(15), margin=margin.all(0), width=250, - expand=True, + #expand=True, bgcolor=colors.BLUE_GREY, visible=self.nav_rail_visible, ) - return self.view def sync_board_destinations(self): boards = self.store.get_boards() @@ -119,11 +115,11 @@ def sync_board_destinations(self): icon=icons.CHEVRON_RIGHT_OUTLINED ) ) - self.view.update() + self.update() def toggle_nav_rail(self, e): - self.view.visible = not self.view.visible - self.view.update() + self.visible = not self.visible + self.update() self.page.update() def board_name_focus(self, e): @@ -143,7 +139,7 @@ def top_nav_change(self, e): index = e if (type(e) == int) else e.control.selected_index self.bottom_nav_rail.selected_index = None self.top_nav_rail.selected_index = index - self.view.update() + self.update() if index == 0: self.page.route = "/boards" elif index == 1: @@ -155,5 +151,5 @@ def bottom_nav_change(self, e): self.top_nav_rail.selected_index = None self.bottom_nav_rail.selected_index = index self.page.route = f"/board/{index}" - self.view.update() + self.update() self.page.update()