Kanban board

A board like Trello’s in about 100 lines:
examples/dnd/kanban.py.
python examples/dnd/kanban.py-
The data. The board is plain Python: the columns in order, and the cards of each one by column id. Each card has an
id, which the sortable uses as its key.def card(title, tag=None):return {"id": f"card-{next(_ids)}", "title": title, "tag": tag}self.columns = [{"id": "todo", "title": "To do"}, {"id": "doing", "title": "In progress"},{"id": "done", "title": "Done"}]self.cards = {"todo": [card("Design the login screen", "feature"), ...], "doing": [...], "done": [...]} -
One column is a sortable. Its
idis the column’s id and every column has the samegroup, so cards can travel between them:cards = pz.sortable(items=self.cards[cid], item=self.card_view, id=cid, group="cards",spacing=8, height="fill", on_reorder=self.move_card)self.cardsalready maps list ids to lists, which is whatpz.dnd.movetakes, so the handler is one line:def move_card(self, event):pz.dnd.move(self.cards, event) -
The columns are a sortable too. A horizontal sortable of columns, with another
groupso cards and columns don’t mix.handle=Truedrags a column only by the grip in its header: the rest of the column belongs to its cards.header = pz.row([pz.drag_handle(pz.icon("grip-vertical")), ui.label(column["title"], weight="bold"),ui.count_badge(len(self.cards[cid]))], spacing=6)board = pz.sortable(items=self.columns, item=self.column_view, id="board", group="columns",direction="horizontal", spacing=14, handle=True, on_reorder=self.move_column)def move_column(self, event):pz.dnd.reorder(self.columns, event.from_index, event.index) -
A trash can that appears while dragging. The column’s
on_drag_startandon_drag_endset a flag, and the view shows a droppable that accepts cards while it is on:cards = pz.sortable(..., on_drag_start=lambda e: setattr(self, "dragging", True),on_drag_end=lambda e: setattr(self, "dragging", False))trash = pz.droppable(bin_, "trash", accepts="cards", on_drop=self.delete,over_style={"background": pz.theme.alpha(t.error, 0.15), "border_color": t.error})def delete(self, event):self.cards[event.from_list].pop(event.from_index) -
Long columns scroll. Each list sits in a
pz.scrollable: dragging a card near its bottom edge scrolls it by itself.
Ideas to go further
Section titled “Ideas to go further”- Limit a column with
max_items(a “work in progress” limit), or forbid moving cards back withcan_drop=lambda e: .... - Save the board as JSON in
move_card. - Make “Done” read-only for others:
put=Falseon that list.