3
3
from board import Board
4
4
import itertools
5
5
from flet import (
6
- UserControl ,
7
6
Draggable ,
8
7
DragTarget ,
9
8
Column ,
10
9
Row ,
11
10
Text ,
12
11
Icon ,
12
+ Page ,
13
13
PopupMenuButton ,
14
14
PopupMenuItem ,
15
15
Container ,
26
26
from data_store import DataStore
27
27
28
28
29
- class BoardList (UserControl ):
29
+ class BoardList (Container ):
30
30
id_counter = itertools .count ()
31
31
32
- def __init__ (self , board : "Board" , store : DataStore , title : str , color : str = "" ):
33
- super (). __init__ ()
32
+ def __init__ (self , board : "Board" , store : DataStore , title : str , page : Page , color : str = "" ):
33
+ self . page = page
34
34
self .board_list_id = next (BoardList .id_counter )
35
35
self .store : DataStore = store
36
36
self .board = board
37
37
self .title = title
38
38
self .color = color
39
39
self .items = Column ([], tight = True , spacing = 4 )
40
40
self .items .controls = self .store .get_items (self .board_list_id )
41
-
42
- def build (self ):
43
-
44
41
self .new_item_field = TextField (
45
42
label = "new card name" , height = 50 , bgcolor = colors .WHITE , on_submit = self .add_item_handler )
46
43
@@ -51,11 +48,13 @@ def build(self):
51
48
width = 200 ,
52
49
opacity = 0.0
53
50
)
51
+
54
52
self .edit_field = Row ([
55
53
TextField (value = self .title , width = 150 , height = 40 ,
56
54
content_padding = padding .only (left = 10 , bottom = 10 )),
57
55
TextButton (text = "Save" , on_click = self .save_title )
58
56
])
57
+
59
58
self .header = Row (
60
59
controls = [
61
60
Text (value = self .title , style = "titleMedium" ,
@@ -103,6 +102,7 @@ def build(self):
103
102
padding = padding .only (
104
103
bottom = 10 , right = 10 , left = 10 , top = 5 )
105
104
)
105
+
106
106
self .view = DragTarget (
107
107
group = "items" ,
108
108
content = Draggable (
@@ -121,9 +121,11 @@ def build(self):
121
121
on_will_accept = self .item_will_drag_accept ,
122
122
on_leave = self .item_drag_leave
123
123
)
124
-
125
- return self .view
126
-
124
+ super ().__init__ (
125
+ content = self .view ,
126
+ data = self
127
+ )
128
+
127
129
def item_drag_accept (self , e ):
128
130
src = self .page .get_control (e .src_id )
129
131
self .add_item (src .data .item_text )
@@ -142,13 +144,12 @@ def item_drag_leave(self, e):
142
144
143
145
def list_drag_accept (self , e ):
144
146
src = self .page .get_control (e .src_id )
145
- l = self .board .board_lists
147
+ l = self .board .content . controls
146
148
to_index = l .index (e .control .data )
147
149
from_index = l .index (src .content .data )
148
150
l [to_index ], l [from_index ] = l [from_index ], l [to_index ]
149
151
self .inner_list .border = border .all (2 , colors .BLACK12 )
150
- self .board .update ()
151
- self .update ()
152
+ self .page .update ()
152
153
153
154
def list_will_drag_accept (self , e ):
154
155
if e .data == "true" :
@@ -171,7 +172,6 @@ def save_title(self, e):
171
172
self .title = self .edit_field .controls [0 ].value
172
173
self .header .controls [0 ] = Text (value = self .title , style = "titleMedium" ,
173
174
text_align = "left" , overflow = "clip" , expand = True )
174
-
175
175
self .header .controls [1 ].visible = True
176
176
self .update ()
177
177
0 commit comments