dhxpyt.kanban

1from .kanban import Kanban
2from .kanban_config import KanbanConfig
3
4__all__ = ["Kanban", "KanbanConfig"]
class Kanban:
  9class Kanban:
 10    """
 11    Wrapper class for the DHTMLX Kanban widget.
 12    """
 13    def __init__(self, config: KanbanConfig, container: str = None):
 14        """
 15        Initializes the Kanban widget.
 16
 17        :param config: KanbanConfig object containing the configuration.
 18        :param container: ID of the HTML element to attach the Kanban to.
 19        """
 20        config_dict = config.to_dict()
 21        self.kanban = js.kanban.Kanban.new(container, js.JSON.parse(json.dumps(config_dict)))
 22
 23    """ Kanban API Methods """
 24
 25    def add_card(self, card: Dict[str, Any]) -> None:
 26        """Adds a new card to the Kanban."""
 27        self.kanban.addCard(js.JSON.parse(json.dumps(card)))
 28
 29    def remove_card(self, card_id: Union[str, int]) -> None:
 30        """Removes a card by its ID."""
 31        self.kanban.removeCard(card_id)
 32
 33    def update_card(self, card_id: Union[str, int], updates: Dict[str, Any]) -> None:
 34        """Updates a card's properties."""
 35        self.kanban.updateCard(card_id, js.JSON.parse(json.dumps(updates)))
 36
 37    def add_column(self, column: Dict[str, Any]) -> None:
 38        """Adds a new column to the Kanban."""
 39        self.kanban.addColumn(js.JSON.parse(json.dumps(column)))
 40
 41    def set_theme(self, theme: str) -> None:
 42        self.kanban.setTheme(js.JSON.parse(json.dumps({"name": theme, "fonts": True})))
 43
 44    def remove_column(self, column_id: Union[str, int]) -> None:
 45        """Removes a column by its ID."""
 46        self.kanban.removeColumn(column_id)
 47
 48    def get_cards(self) -> List[Dict[str, Any]]:
 49        """Returns all cards in the Kanban."""
 50        return [card.to_py() for card in self.kanban.getCards()]
 51
 52    def get_columns(self) -> List[Dict[str, Any]]:
 53        """Returns all columns in the Kanban."""
 54        return [column.to_py() for column in self.kanban.getColumns()]
 55
 56    def select_card(self, card_id: Union[str, int]) -> None:
 57        """Selects a card by its ID."""
 58        self.kanban.selectCard(card_id)
 59
 60    def unselect_card(self, card_id: Union[str, int]) -> None:
 61        """Unselects a card by its ID."""
 62        self.kanban.unselectCard(card_id)
 63
 64    def export_to_json(self) -> str:
 65        """Exports Kanban data to JSON format."""
 66        return self.kanban.data.serialize()
 67
 68    """ Kanban Event Handlers """
 69
 70    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 71        """Adds an event handler for the specified event."""
 72        event_proxy = create_proxy(handler)
 73        self.kanban.events.on(event_name, event_proxy)
 74
 75    def on_card_click(self, handler: Callable[[Dict[str, Any]], None]) -> None:
 76        """Fires when a card is clicked."""
 77        def event_handler(card):
 78            handler(card.to_py())
 79        self.kanban.events.on("cardClick", create_proxy(event_handler))
 80
 81    def on_column_click(self, handler: Callable[[Dict[str, Any]], None]) -> None:
 82        """Fires when a column header is clicked."""
 83        def event_handler(column):
 84            handler(column.to_py())
 85        self.kanban.events.on("columnClick", create_proxy(event_handler))
 86
 87    def on_card_drag(self, handler: Callable[[Dict[str, Any]], None]) -> None:
 88        """Fires during a card drag event."""
 89        def event_handler(card):
 90            handler(card.to_py())
 91        self.kanban.events.on("cardDrag", create_proxy(event_handler))
 92
 93    def on_card_drop(self, handler: Callable[[Dict[str, Any]], None]) -> None:
 94        """Fires when a card is dropped."""
 95        def event_handler(card):
 96            handler(card.to_py())
 97        self.kanban.events.on("cardDrop", create_proxy(event_handler))
 98
 99    def on_editor_change(self, handler: Callable[[Dict[str, Any]], None]) -> None:
100        """Fires when editor data is changed."""
101        def event_handler(data):
102            handler(data.to_py())
103        self.kanban.events.on("editorChange", create_proxy(event_handler))

Wrapper class for the DHTMLX Kanban widget.

Kanban( config: KanbanConfig, container: str = None)
13    def __init__(self, config: KanbanConfig, container: str = None):
14        """
15        Initializes the Kanban widget.
16
17        :param config: KanbanConfig object containing the configuration.
18        :param container: ID of the HTML element to attach the Kanban to.
19        """
20        config_dict = config.to_dict()
21        self.kanban = js.kanban.Kanban.new(container, js.JSON.parse(json.dumps(config_dict)))

Initializes the Kanban widget.

Parameters
  • config: KanbanConfig object containing the configuration.
  • container: ID of the HTML element to attach the Kanban to.
kanban

Kanban API Methods

def add_card(self, card: Dict[str, Any]) -> None:
25    def add_card(self, card: Dict[str, Any]) -> None:
26        """Adds a new card to the Kanban."""
27        self.kanban.addCard(js.JSON.parse(json.dumps(card)))

Adds a new card to the Kanban.

def remove_card(self, card_id: Union[str, int]) -> None:
29    def remove_card(self, card_id: Union[str, int]) -> None:
30        """Removes a card by its ID."""
31        self.kanban.removeCard(card_id)

Removes a card by its ID.

def update_card(self, card_id: Union[str, int], updates: Dict[str, Any]) -> None:
33    def update_card(self, card_id: Union[str, int], updates: Dict[str, Any]) -> None:
34        """Updates a card's properties."""
35        self.kanban.updateCard(card_id, js.JSON.parse(json.dumps(updates)))

Updates a card's properties.

def add_column(self, column: Dict[str, Any]) -> None:
37    def add_column(self, column: Dict[str, Any]) -> None:
38        """Adds a new column to the Kanban."""
39        self.kanban.addColumn(js.JSON.parse(json.dumps(column)))

Adds a new column to the Kanban.

def set_theme(self, theme: str) -> None:
41    def set_theme(self, theme: str) -> None:
42        self.kanban.setTheme(js.JSON.parse(json.dumps({"name": theme, "fonts": True})))
def remove_column(self, column_id: Union[str, int]) -> None:
44    def remove_column(self, column_id: Union[str, int]) -> None:
45        """Removes a column by its ID."""
46        self.kanban.removeColumn(column_id)

Removes a column by its ID.

def get_cards(self) -> List[Dict[str, Any]]:
48    def get_cards(self) -> List[Dict[str, Any]]:
49        """Returns all cards in the Kanban."""
50        return [card.to_py() for card in self.kanban.getCards()]

Returns all cards in the Kanban.

def get_columns(self) -> List[Dict[str, Any]]:
52    def get_columns(self) -> List[Dict[str, Any]]:
53        """Returns all columns in the Kanban."""
54        return [column.to_py() for column in self.kanban.getColumns()]

Returns all columns in the Kanban.

def select_card(self, card_id: Union[str, int]) -> None:
56    def select_card(self, card_id: Union[str, int]) -> None:
57        """Selects a card by its ID."""
58        self.kanban.selectCard(card_id)

Selects a card by its ID.

def unselect_card(self, card_id: Union[str, int]) -> None:
60    def unselect_card(self, card_id: Union[str, int]) -> None:
61        """Unselects a card by its ID."""
62        self.kanban.unselectCard(card_id)

Unselects a card by its ID.

def export_to_json(self) -> str:
64    def export_to_json(self) -> str:
65        """Exports Kanban data to JSON format."""
66        return self.kanban.data.serialize()

Exports Kanban data to JSON format.

def add_event_handler(self, event_name: str, handler: Callable) -> None:
70    def add_event_handler(self, event_name: str, handler: Callable) -> None:
71        """Adds an event handler for the specified event."""
72        event_proxy = create_proxy(handler)
73        self.kanban.events.on(event_name, event_proxy)

Adds an event handler for the specified event.

def on_card_click(self, handler: Callable[[Dict[str, Any]], NoneType]) -> None:
75    def on_card_click(self, handler: Callable[[Dict[str, Any]], None]) -> None:
76        """Fires when a card is clicked."""
77        def event_handler(card):
78            handler(card.to_py())
79        self.kanban.events.on("cardClick", create_proxy(event_handler))

Fires when a card is clicked.

def on_column_click(self, handler: Callable[[Dict[str, Any]], NoneType]) -> None:
81    def on_column_click(self, handler: Callable[[Dict[str, Any]], None]) -> None:
82        """Fires when a column header is clicked."""
83        def event_handler(column):
84            handler(column.to_py())
85        self.kanban.events.on("columnClick", create_proxy(event_handler))

Fires when a column header is clicked.

def on_card_drag(self, handler: Callable[[Dict[str, Any]], NoneType]) -> None:
87    def on_card_drag(self, handler: Callable[[Dict[str, Any]], None]) -> None:
88        """Fires during a card drag event."""
89        def event_handler(card):
90            handler(card.to_py())
91        self.kanban.events.on("cardDrag", create_proxy(event_handler))

Fires during a card drag event.

def on_card_drop(self, handler: Callable[[Dict[str, Any]], NoneType]) -> None:
93    def on_card_drop(self, handler: Callable[[Dict[str, Any]], None]) -> None:
94        """Fires when a card is dropped."""
95        def event_handler(card):
96            handler(card.to_py())
97        self.kanban.events.on("cardDrop", create_proxy(event_handler))

Fires when a card is dropped.

def on_editor_change(self, handler: Callable[[Dict[str, Any]], NoneType]) -> None:
 99    def on_editor_change(self, handler: Callable[[Dict[str, Any]], None]) -> None:
100        """Fires when editor data is changed."""
101        def event_handler(data):
102            handler(data.to_py())
103        self.kanban.events.on("editorChange", create_proxy(event_handler))

Fires when editor data is changed.

class KanbanConfig:
 4class KanbanConfig:
 5    """
 6    Configuration class for the Kanban widget.
 7    """
 8    def __init__(self,
 9                 columns: List[Dict[str, Any]],
10                 cards: List[Dict[str, Any]] = None,
11                 dragMode: bool = True,
12                 editable: bool = True,
13                 multiselection: bool = False,
14                 autosize: bool = True,
15                 toolbar: Dict[str, Any] = None,
16                 cardShape: Dict[str, Any] = None,
17                 editorShape: List[Dict[str, Any]] = None,
18                 rows: List[Dict[str, Any]] = None,
19                 links: List[Dict[str, Any]] = None,
20                 rowKey: str = None,
21                 currentUser: Union[int, str] = None):
22        """
23        Initializes the KanbanConfig.
24
25        :param columns: List of column configurations.
26        :param cards: List of card configurations.
27        :param dragMode: Enables drag-and-drop functionality.
28        :param editable: Allows editing of card text.
29        :param multiselection: Enables multi-card selection.
30        :param autosize: Adjusts the Kanban board to fit its container.
31        :param toolbar: Toolbar configuration for the Kanban.
32        :param cardShape: Configuration for the shape and properties of cards.
33        :param editorShape: Configuration for the Kanban editor.
34        :param rows: List of row configurations.
35        :param links: List of links between cards.
36        :param rowKey: Key used for row-grouping of cards.
37        :param currentUser: ID of the current user interacting with the Kanban.
38        """
39        self.columns = columns
40        self.cards = cards
41        self.dragMode = dragMode
42        self.editable = editable
43        self.multiselection = multiselection
44        self.autosize = autosize
45        self.toolbar = toolbar
46        self.cardShape = cardShape
47        self.editorShape = editorShape
48        self.rows = rows
49        self.links = links
50        self.rowKey = rowKey
51        self.currentUser = currentUser
52
53    def to_dict(self) -> Dict[str, Any]:
54        """
55        Converts the KanbanConfig into a dictionary format.
56        """
57        config_dict = {
58            "columns": self.columns,
59            "cards": self.cards,
60            "dragMode": self.dragMode,
61            "editable": self.editable,
62            "multiselection": self.multiselection,
63            "autosize": self.autosize,
64            "toolbar": self.toolbar,
65            "cardShape": self.cardShape,
66            "editorShape": self.editorShape,
67            "rows": self.rows,
68            "links": self.links,
69            "rowKey": self.rowKey,
70            "currentUser": self.currentUser
71        }
72        return {k: v for k, v in config_dict.items() if v is not None}

Configuration class for the Kanban widget.

KanbanConfig( columns: List[Dict[str, Any]], cards: List[Dict[str, Any]] = None, dragMode: bool = True, editable: bool = True, multiselection: bool = False, autosize: bool = True, toolbar: Dict[str, Any] = None, cardShape: Dict[str, Any] = None, editorShape: List[Dict[str, Any]] = None, rows: List[Dict[str, Any]] = None, links: List[Dict[str, Any]] = None, rowKey: str = None, currentUser: Union[int, str] = None)
 8    def __init__(self,
 9                 columns: List[Dict[str, Any]],
10                 cards: List[Dict[str, Any]] = None,
11                 dragMode: bool = True,
12                 editable: bool = True,
13                 multiselection: bool = False,
14                 autosize: bool = True,
15                 toolbar: Dict[str, Any] = None,
16                 cardShape: Dict[str, Any] = None,
17                 editorShape: List[Dict[str, Any]] = None,
18                 rows: List[Dict[str, Any]] = None,
19                 links: List[Dict[str, Any]] = None,
20                 rowKey: str = None,
21                 currentUser: Union[int, str] = None):
22        """
23        Initializes the KanbanConfig.
24
25        :param columns: List of column configurations.
26        :param cards: List of card configurations.
27        :param dragMode: Enables drag-and-drop functionality.
28        :param editable: Allows editing of card text.
29        :param multiselection: Enables multi-card selection.
30        :param autosize: Adjusts the Kanban board to fit its container.
31        :param toolbar: Toolbar configuration for the Kanban.
32        :param cardShape: Configuration for the shape and properties of cards.
33        :param editorShape: Configuration for the Kanban editor.
34        :param rows: List of row configurations.
35        :param links: List of links between cards.
36        :param rowKey: Key used for row-grouping of cards.
37        :param currentUser: ID of the current user interacting with the Kanban.
38        """
39        self.columns = columns
40        self.cards = cards
41        self.dragMode = dragMode
42        self.editable = editable
43        self.multiselection = multiselection
44        self.autosize = autosize
45        self.toolbar = toolbar
46        self.cardShape = cardShape
47        self.editorShape = editorShape
48        self.rows = rows
49        self.links = links
50        self.rowKey = rowKey
51        self.currentUser = currentUser

Initializes the KanbanConfig.

Parameters
  • columns: List of column configurations.
  • cards: List of card configurations.
  • dragMode: Enables drag-and-drop functionality.
  • editable: Allows editing of card text.
  • multiselection: Enables multi-card selection.
  • autosize: Adjusts the Kanban board to fit its container.
  • toolbar: Toolbar configuration for the Kanban.
  • cardShape: Configuration for the shape and properties of cards.
  • editorShape: Configuration for the Kanban editor.
  • rows: List of row configurations.
  • links: List of links between cards.
  • rowKey: Key used for row-grouping of cards.
  • currentUser: ID of the current user interacting with the Kanban.
columns
cards
dragMode
editable
multiselection
autosize
toolbar
cardShape
editorShape
rows
rowKey
currentUser
def to_dict(self) -> Dict[str, Any]:
53    def to_dict(self) -> Dict[str, Any]:
54        """
55        Converts the KanbanConfig into a dictionary format.
56        """
57        config_dict = {
58            "columns": self.columns,
59            "cards": self.cards,
60            "dragMode": self.dragMode,
61            "editable": self.editable,
62            "multiselection": self.multiselection,
63            "autosize": self.autosize,
64            "toolbar": self.toolbar,
65            "cardShape": self.cardShape,
66            "editorShape": self.editorShape,
67            "rows": self.rows,
68            "links": self.links,
69            "rowKey": self.rowKey,
70            "currentUser": self.currentUser
71        }
72        return {k: v for k, v in config_dict.items() if v is not None}

Converts the KanbanConfig into a dictionary format.