dhxpyt.tree

1from .tree import Tree
2from .tree_config import TreeConfig, TreeItemConfig
3
4__all__ = ["Tree", "TreeConfig", "TreeItemConfig"]
class Tree:
 14class Tree:
 15    def __init__(self, config: TreeConfig = None, widget_parent: str = None):
 16        """
 17        Initializes the Tree widget.
 18
 19        :param config: (Optional) The TreeConfig object containing the tree configuration.
 20        :param widget_parent: (Optional) The ID of the HTML element where the tree will be attached.
 21        """
 22        if config is None:
 23            config = TreeConfig()
 24        config_dict = config.to_dict()
 25        # Create the Tree instance
 26        self.tree = js.dhx.Tree.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
 27
 28    """ Tree API Functions """
 29
 30    def check_item(self, id: Union[str, int]) -> None:
 31        """Checks the checkbox of a tree item and all its sub-items."""
 32        self.tree.checkItem(id)
 33
 34    def collapse(self, id: Union[str, int]) -> None:
 35        """Collapses a tree item by ID."""
 36        self.tree.collapse(id)
 37
 38    def collapse_all(self) -> None:
 39        """Collapses all expanded tree items."""
 40        self.tree.collapseAll()
 41
 42    def destructor(self) -> None:
 43        """Releases the occupied resources."""
 44        self.tree.destructor()
 45
 46    def edit_item(self, id: Union[str, int], config: dict = None) -> None:
 47        """Edits a tree item."""
 48        self.tree.editItem(id, config)
 49
 50    def expand(self, id: Union[str, int]) -> None:
 51        """Expands a tree item by ID."""
 52        self.tree.expand(id)
 53
 54    def expand_all(self) -> None:
 55        """Expands all collapsed tree items."""
 56        self.tree.expandAll()
 57
 58    def focus_item(self, id: Union[str, int]) -> None:
 59        """Sets focus to a tree item and moves the scroll to it."""
 60        self.tree.focusItem(id)
 61
 62    def get_checked(self) -> List[Union[str, int]]:
 63        """Gets all checked tree items."""
 64        return self.tree.getChecked().to_py()
 65
 66    def get_state(self) -> Dict[str, Dict[str, Union[int, bool]]]:
 67        """Gets the state of the tree."""
 68        return self.tree.getState().to_py()
 69
 70    def paint(self) -> None:
 71        """Repaints the tree on the page."""
 72        self.tree.paint()
 73
 74    def set_state(self, state: Dict[str, Dict[str, Union[int, bool]]]) -> None:
 75        """Sets the state for the tree."""
 76        self.tree.setState(js.JSON.parse(json.dumps(state)))
 77
 78    def toggle(self, id: Union[str, int]) -> None:
 79        """Opens or closes a tree item by ID."""
 80        self.tree.toggle(id)
 81
 82    def uncheck_item(self, id: Union[str, int]) -> None:
 83        """Unchecks the checkbox of a tree item and all its sub-items."""
 84        self.tree.uncheckItem(id)
 85
 86    """ Tree Event Handlers """
 87
 88    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 89        """
 90        Adds an event handler for the specified event.
 91        
 92        :param event_name: The name of the event.
 93        :param handler: The handler function to attach.
 94        """
 95        event_proxy = create_proxy(handler)
 96        self.tree.events.on(event_name, event_proxy)
 97
 98    def on_after_check(self, handler: Callable[[int, Union[str, int], bool], None]) -> None:
 99        """Fires after the state of an item is changed (checked)."""
100        self.add_event_handler('afterCheck', handler)
101
102    def on_after_collapse(self, handler: Callable[[Union[str, int]], None]) -> None:
103        """Fires after collapsing a tree item."""
104        self.add_event_handler('afterCollapse', handler)
105
106    def on_after_drag(self, handler: Callable[[dict, Any], Any]) -> None:
107        """Fires after dragging an item is finished."""
108        self.add_event_handler('afterDrag', handler)
109
110    def on_after_drop(self, handler: Callable[[dict, Any], None]) -> None:
111        """Fires before the user has finished dragging an item but after the mouse button is released."""
112        self.add_event_handler('afterDrop', handler)
113
114    def on_after_edit_end(self, handler: Callable[[str, Union[str, int]], None]) -> None:
115        """Fires after editing a tree item is finished."""
116        self.add_event_handler('afterEditEnd', handler)
117
118    def on_after_edit_start(self, handler: Callable[[str, Union[str, int]], None]) -> None:
119        """Fires after editing of a tree item has started."""
120        self.add_event_handler('afterEditStart', handler)
121
122    def on_after_expand(self, handler: Callable[[Union[str, int]], None]) -> None:
123        """Fires after expanding a tree item."""
124        self.add_event_handler('afterExpand', handler)
125
126    def on_before_check(self, handler: Callable[[int, Union[str, int]], Union[bool, None]]) -> None:
127        """Fires before the state of an item is changed (checking)."""
128        def event_handler(index, id):
129            result = handler(index, id)
130            if result is False:
131                return js.Boolean(False)
132        self.tree.events.on('beforeCheck', create_proxy(event_handler))
133
134    def on_before_collapse(self, handler: Callable[[Union[str, int]], Union[bool, None]]) -> None:
135        """Fires before collapsing a tree item."""
136        def event_handler(id):
137            result = handler(id)
138            if result is False:
139                return js.Boolean(False)
140        self.tree.events.on('beforeCollapse', create_proxy(event_handler))
141
142    def on_before_drag(self, handler: Callable[[dict, Any, Any], Union[bool, None]]) -> None:
143        """Fires before dragging of an item starts."""
144        def event_handler(data, event, ghost):
145            result = handler(data, event, ghost)
146            if result is False:
147                return js.Boolean(False)
148        self.tree.events.on('beforeDrag', create_proxy(event_handler))
149
150    def on_before_drop(self, handler: Callable[[dict, Any], Union[bool, None]]) -> None:
151        """Fires before the user has finished dragging an item and released the mouse button."""
152        def event_handler(data, event):
153            result = handler(data, event)
154            if result is False:
155                return js.Boolean(False)
156        self.tree.events.on('beforeDrop', create_proxy(event_handler))
157
158    def on_before_edit_end(self, handler: Callable[[str, Union[str, int]], Union[bool, None]]) -> None:
159        """Fires before editing a tree item is finished."""
160        def event_handler(value, id):
161            result = handler(value, id)
162            if result is False:
163                return js.Boolean(False)
164        self.tree.events.on('beforeEditEnd', create_proxy(event_handler))
165
166    def on_before_edit_start(self, handler: Callable[[str, Union[str, int]], Union[bool, None]]) -> None:
167        """Fires before editing of a tree item starts."""
168        def event_handler(value, id):
169            result = handler(value, id)
170            if result is False:
171                return js.Boolean(False)
172        self.tree.events.on('beforeEditStart', create_proxy(event_handler))
173
174    def on_before_expand(self, handler: Callable[[Union[str, int]], Union[bool, None]]) -> None:
175        """Fires before expanding a tree item."""
176        def event_handler(id):
177            result = handler(id)
178            if result is False:
179                return js.Boolean(False)
180        self.tree.events.on('beforeExpand', create_proxy(event_handler))
181    
182    # Additional event handlers like dragStart, itemClick, itemDblClick can also be added similarly
Tree( config: TreeConfig = None, widget_parent: str = None)
15    def __init__(self, config: TreeConfig = None, widget_parent: str = None):
16        """
17        Initializes the Tree widget.
18
19        :param config: (Optional) The TreeConfig object containing the tree configuration.
20        :param widget_parent: (Optional) The ID of the HTML element where the tree will be attached.
21        """
22        if config is None:
23            config = TreeConfig()
24        config_dict = config.to_dict()
25        # Create the Tree instance
26        self.tree = js.dhx.Tree.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))

Initializes the Tree widget.

Parameters
  • config: (Optional) The TreeConfig object containing the tree configuration.
  • widget_parent: (Optional) The ID of the HTML element where the tree will be attached.
tree

Tree API Functions

def check_item(self, id: Union[str, int]) -> None:
30    def check_item(self, id: Union[str, int]) -> None:
31        """Checks the checkbox of a tree item and all its sub-items."""
32        self.tree.checkItem(id)

Checks the checkbox of a tree item and all its sub-items.

def collapse(self, id: Union[str, int]) -> None:
34    def collapse(self, id: Union[str, int]) -> None:
35        """Collapses a tree item by ID."""
36        self.tree.collapse(id)

Collapses a tree item by ID.

def collapse_all(self) -> None:
38    def collapse_all(self) -> None:
39        """Collapses all expanded tree items."""
40        self.tree.collapseAll()

Collapses all expanded tree items.

def destructor(self) -> None:
42    def destructor(self) -> None:
43        """Releases the occupied resources."""
44        self.tree.destructor()

Releases the occupied resources.

def edit_item(self, id: Union[str, int], config: dict = None) -> None:
46    def edit_item(self, id: Union[str, int], config: dict = None) -> None:
47        """Edits a tree item."""
48        self.tree.editItem(id, config)

Edits a tree item.

def expand(self, id: Union[str, int]) -> None:
50    def expand(self, id: Union[str, int]) -> None:
51        """Expands a tree item by ID."""
52        self.tree.expand(id)

Expands a tree item by ID.

def expand_all(self) -> None:
54    def expand_all(self) -> None:
55        """Expands all collapsed tree items."""
56        self.tree.expandAll()

Expands all collapsed tree items.

def focus_item(self, id: Union[str, int]) -> None:
58    def focus_item(self, id: Union[str, int]) -> None:
59        """Sets focus to a tree item and moves the scroll to it."""
60        self.tree.focusItem(id)

Sets focus to a tree item and moves the scroll to it.

def get_checked(self) -> List[Union[str, int]]:
62    def get_checked(self) -> List[Union[str, int]]:
63        """Gets all checked tree items."""
64        return self.tree.getChecked().to_py()

Gets all checked tree items.

def get_state(self) -> Dict[str, Dict[str, Union[int, bool]]]:
66    def get_state(self) -> Dict[str, Dict[str, Union[int, bool]]]:
67        """Gets the state of the tree."""
68        return self.tree.getState().to_py()

Gets the state of the tree.

def paint(self) -> None:
70    def paint(self) -> None:
71        """Repaints the tree on the page."""
72        self.tree.paint()

Repaints the tree on the page.

def set_state(self, state: Dict[str, Dict[str, Union[int, bool]]]) -> None:
74    def set_state(self, state: Dict[str, Dict[str, Union[int, bool]]]) -> None:
75        """Sets the state for the tree."""
76        self.tree.setState(js.JSON.parse(json.dumps(state)))

Sets the state for the tree.

def toggle(self, id: Union[str, int]) -> None:
78    def toggle(self, id: Union[str, int]) -> None:
79        """Opens or closes a tree item by ID."""
80        self.tree.toggle(id)

Opens or closes a tree item by ID.

def uncheck_item(self, id: Union[str, int]) -> None:
82    def uncheck_item(self, id: Union[str, int]) -> None:
83        """Unchecks the checkbox of a tree item and all its sub-items."""
84        self.tree.uncheckItem(id)

Unchecks the checkbox of a tree item and all its sub-items.

def add_event_handler(self, event_name: str, handler: Callable) -> None:
88    def add_event_handler(self, event_name: str, handler: Callable) -> None:
89        """
90        Adds an event handler for the specified event.
91        
92        :param event_name: The name of the event.
93        :param handler: The handler function to attach.
94        """
95        event_proxy = create_proxy(handler)
96        self.tree.events.on(event_name, event_proxy)

Adds an event handler for the specified event.

Parameters
  • event_name: The name of the event.
  • handler: The handler function to attach.
def on_after_check(self, handler: Callable[[int, Union[str, int], bool], NoneType]) -> None:
 98    def on_after_check(self, handler: Callable[[int, Union[str, int], bool], None]) -> None:
 99        """Fires after the state of an item is changed (checked)."""
100        self.add_event_handler('afterCheck', handler)

Fires after the state of an item is changed (checked).

def on_after_collapse(self, handler: Callable[[Union[str, int]], NoneType]) -> None:
102    def on_after_collapse(self, handler: Callable[[Union[str, int]], None]) -> None:
103        """Fires after collapsing a tree item."""
104        self.add_event_handler('afterCollapse', handler)

Fires after collapsing a tree item.

def on_after_drag(self, handler: Callable[[dict, Any], Any]) -> None:
106    def on_after_drag(self, handler: Callable[[dict, Any], Any]) -> None:
107        """Fires after dragging an item is finished."""
108        self.add_event_handler('afterDrag', handler)

Fires after dragging an item is finished.

def on_after_drop(self, handler: Callable[[dict, Any], NoneType]) -> None:
110    def on_after_drop(self, handler: Callable[[dict, Any], None]) -> None:
111        """Fires before the user has finished dragging an item but after the mouse button is released."""
112        self.add_event_handler('afterDrop', handler)

Fires before the user has finished dragging an item but after the mouse button is released.

def on_after_edit_end(self, handler: Callable[[str, Union[str, int]], NoneType]) -> None:
114    def on_after_edit_end(self, handler: Callable[[str, Union[str, int]], None]) -> None:
115        """Fires after editing a tree item is finished."""
116        self.add_event_handler('afterEditEnd', handler)

Fires after editing a tree item is finished.

def on_after_edit_start(self, handler: Callable[[str, Union[str, int]], NoneType]) -> None:
118    def on_after_edit_start(self, handler: Callable[[str, Union[str, int]], None]) -> None:
119        """Fires after editing of a tree item has started."""
120        self.add_event_handler('afterEditStart', handler)

Fires after editing of a tree item has started.

def on_after_expand(self, handler: Callable[[Union[str, int]], NoneType]) -> None:
122    def on_after_expand(self, handler: Callable[[Union[str, int]], None]) -> None:
123        """Fires after expanding a tree item."""
124        self.add_event_handler('afterExpand', handler)

Fires after expanding a tree item.

def on_before_check(self, handler: Callable[[int, Union[str, int]], Optional[bool]]) -> None:
126    def on_before_check(self, handler: Callable[[int, Union[str, int]], Union[bool, None]]) -> None:
127        """Fires before the state of an item is changed (checking)."""
128        def event_handler(index, id):
129            result = handler(index, id)
130            if result is False:
131                return js.Boolean(False)
132        self.tree.events.on('beforeCheck', create_proxy(event_handler))

Fires before the state of an item is changed (checking).

def on_before_collapse(self, handler: Callable[[Union[str, int]], Optional[bool]]) -> None:
134    def on_before_collapse(self, handler: Callable[[Union[str, int]], Union[bool, None]]) -> None:
135        """Fires before collapsing a tree item."""
136        def event_handler(id):
137            result = handler(id)
138            if result is False:
139                return js.Boolean(False)
140        self.tree.events.on('beforeCollapse', create_proxy(event_handler))

Fires before collapsing a tree item.

def on_before_drag(self, handler: Callable[[dict, Any, Any], Optional[bool]]) -> None:
142    def on_before_drag(self, handler: Callable[[dict, Any, Any], Union[bool, None]]) -> None:
143        """Fires before dragging of an item starts."""
144        def event_handler(data, event, ghost):
145            result = handler(data, event, ghost)
146            if result is False:
147                return js.Boolean(False)
148        self.tree.events.on('beforeDrag', create_proxy(event_handler))

Fires before dragging of an item starts.

def on_before_drop(self, handler: Callable[[dict, Any], Optional[bool]]) -> None:
150    def on_before_drop(self, handler: Callable[[dict, Any], Union[bool, None]]) -> None:
151        """Fires before the user has finished dragging an item and released the mouse button."""
152        def event_handler(data, event):
153            result = handler(data, event)
154            if result is False:
155                return js.Boolean(False)
156        self.tree.events.on('beforeDrop', create_proxy(event_handler))

Fires before the user has finished dragging an item and released the mouse button.

def on_before_edit_end(self, handler: Callable[[str, Union[str, int]], Optional[bool]]) -> None:
158    def on_before_edit_end(self, handler: Callable[[str, Union[str, int]], Union[bool, None]]) -> None:
159        """Fires before editing a tree item is finished."""
160        def event_handler(value, id):
161            result = handler(value, id)
162            if result is False:
163                return js.Boolean(False)
164        self.tree.events.on('beforeEditEnd', create_proxy(event_handler))

Fires before editing a tree item is finished.

def on_before_edit_start(self, handler: Callable[[str, Union[str, int]], Optional[bool]]) -> None:
166    def on_before_edit_start(self, handler: Callable[[str, Union[str, int]], Union[bool, None]]) -> None:
167        """Fires before editing of a tree item starts."""
168        def event_handler(value, id):
169            result = handler(value, id)
170            if result is False:
171                return js.Boolean(False)
172        self.tree.events.on('beforeEditStart', create_proxy(event_handler))

Fires before editing of a tree item starts.

def on_before_expand(self, handler: Callable[[Union[str, int]], Optional[bool]]) -> None:
174    def on_before_expand(self, handler: Callable[[Union[str, int]], Union[bool, None]]) -> None:
175        """Fires before expanding a tree item."""
176        def event_handler(id):
177            result = handler(id)
178            if result is False:
179                return js.Boolean(False)
180        self.tree.events.on('beforeExpand', create_proxy(event_handler))

Fires before expanding a tree item.

class TreeConfig:
 42class TreeConfig:
 43    """
 44    Configuration class for the Tree widget.
 45    """
 46    def __init__(self,
 47                 data: Optional[List[TreeItemConfig]] = None,
 48                 checkbox: Optional[bool] = None,
 49                 collapsed: Optional[bool] = None,
 50                 css: Optional[str] = None,
 51                 dragCopy: Optional[bool] = None,
 52                 dragMode: Optional[str] = None,
 53                 dropBehaviour: Optional[str] = None,
 54                 editable: Optional[bool] = None,
 55                 icon: Optional[dict] = None,
 56                 itemHeight: Optional[Union[int, str]] = None,
 57                 keyNavigation: Optional[bool] = None,
 58                 rootId: Optional[Union[str, int]] = None,
 59                 selection: Optional[bool] = None,
 60                 template: Optional[Callable[[dict, bool], str]] = None):
 61        """
 62        Initializes the configuration for the Tree widget.
 63
 64        :param data: List of TreeItemConfig to define the tree structure.
 65        :param checkbox: Whether checkboxes are enabled in the tree.
 66        :param collapsed: Whether the tree is initialized in the collapsed state.
 67        :param css: Adds custom style classes to the tree.
 68        :param dragCopy: Defines if the tree item should be copied during drag-and-drop.
 69        :param dragMode: Defines drag-and-drop mode ("target", "source", "both").
 70        :param dropBehaviour: Defines the behavior of dragged items ("child", "sibling", "complex").
 71        :param editable: Enables inline editing of tree items.
 72        :param icon: Custom icons for tree items.
 73        :param itemHeight: Sets the height of tree items.
 74        :param keyNavigation: Enables key navigation for tree.
 75        :param rootId: The ID for the root tree element.
 76        :param selection: Enables selection of tree items.
 77        :param template: Custom template function for rendering tree items.
 78        """
 79        self.data = data
 80        self.checkbox = checkbox
 81        self.collapsed = collapsed
 82        self.css = css
 83        self.dragCopy = dragCopy
 84        self.dragMode = dragMode
 85        self.dropBehaviour = dropBehaviour
 86        self.editable = editable
 87        self.icon = icon
 88        self.itemHeight = itemHeight
 89        self.keyNavigation = keyNavigation
 90        self.rootId = rootId
 91        self.selection = selection
 92        self.template = template
 93
 94    def to_dict(self) -> Dict[str, Any]:
 95        config = {
 96            "data": [item.to_dict() for item in self.data] if self.data else None,
 97            "checkbox": self.checkbox,
 98            "collapsed": self.collapsed,
 99            "css": self.css,
100            "dragCopy": self.dragCopy,
101            "dragMode": self.dragMode,
102            "dropBehaviour": self.dropBehaviour,
103            "editable": self.editable,
104            "icon": self.icon,
105            "itemHeight": self.itemHeight,
106            "keyNavigation": self.keyNavigation,
107            "rootId": self.rootId,
108            "selection": self.selection,
109            "template": self.template
110        }
111        return {k: v for k, v in config.items() if v is not None}

Configuration class for the Tree widget.

TreeConfig( data: Optional[List[TreeItemConfig]] = None, checkbox: Optional[bool] = None, collapsed: Optional[bool] = None, css: Optional[str] = None, dragCopy: Optional[bool] = None, dragMode: Optional[str] = None, dropBehaviour: Optional[str] = None, editable: Optional[bool] = None, icon: Optional[dict] = None, itemHeight: Union[int, str, NoneType] = None, keyNavigation: Optional[bool] = None, rootId: Union[int, str, NoneType] = None, selection: Optional[bool] = None, template: Optional[Callable[[dict, bool], str]] = None)
46    def __init__(self,
47                 data: Optional[List[TreeItemConfig]] = None,
48                 checkbox: Optional[bool] = None,
49                 collapsed: Optional[bool] = None,
50                 css: Optional[str] = None,
51                 dragCopy: Optional[bool] = None,
52                 dragMode: Optional[str] = None,
53                 dropBehaviour: Optional[str] = None,
54                 editable: Optional[bool] = None,
55                 icon: Optional[dict] = None,
56                 itemHeight: Optional[Union[int, str]] = None,
57                 keyNavigation: Optional[bool] = None,
58                 rootId: Optional[Union[str, int]] = None,
59                 selection: Optional[bool] = None,
60                 template: Optional[Callable[[dict, bool], str]] = None):
61        """
62        Initializes the configuration for the Tree widget.
63
64        :param data: List of TreeItemConfig to define the tree structure.
65        :param checkbox: Whether checkboxes are enabled in the tree.
66        :param collapsed: Whether the tree is initialized in the collapsed state.
67        :param css: Adds custom style classes to the tree.
68        :param dragCopy: Defines if the tree item should be copied during drag-and-drop.
69        :param dragMode: Defines drag-and-drop mode ("target", "source", "both").
70        :param dropBehaviour: Defines the behavior of dragged items ("child", "sibling", "complex").
71        :param editable: Enables inline editing of tree items.
72        :param icon: Custom icons for tree items.
73        :param itemHeight: Sets the height of tree items.
74        :param keyNavigation: Enables key navigation for tree.
75        :param rootId: The ID for the root tree element.
76        :param selection: Enables selection of tree items.
77        :param template: Custom template function for rendering tree items.
78        """
79        self.data = data
80        self.checkbox = checkbox
81        self.collapsed = collapsed
82        self.css = css
83        self.dragCopy = dragCopy
84        self.dragMode = dragMode
85        self.dropBehaviour = dropBehaviour
86        self.editable = editable
87        self.icon = icon
88        self.itemHeight = itemHeight
89        self.keyNavigation = keyNavigation
90        self.rootId = rootId
91        self.selection = selection
92        self.template = template

Initializes the configuration for the Tree widget.

Parameters
  • data: List of TreeItemConfig to define the tree structure.
  • checkbox: Whether checkboxes are enabled in the tree.
  • collapsed: Whether the tree is initialized in the collapsed state.
  • css: Adds custom style classes to the tree.
  • dragCopy: Defines if the tree item should be copied during drag-and-drop.
  • dragMode: Defines drag-and-drop mode ("target", "source", "both").
  • dropBehaviour: Defines the behavior of dragged items ("child", "sibling", "complex").
  • editable: Enables inline editing of tree items.
  • icon: Custom icons for tree items.
  • itemHeight: Sets the height of tree items.
  • keyNavigation: Enables key navigation for tree.
  • rootId: The ID for the root tree element.
  • selection: Enables selection of tree items.
  • template: Custom template function for rendering tree items.
data
checkbox
collapsed
css
dragCopy
dragMode
dropBehaviour
editable
icon
itemHeight
keyNavigation
rootId
selection
template
def to_dict(self) -> Dict[str, Any]:
 94    def to_dict(self) -> Dict[str, Any]:
 95        config = {
 96            "data": [item.to_dict() for item in self.data] if self.data else None,
 97            "checkbox": self.checkbox,
 98            "collapsed": self.collapsed,
 99            "css": self.css,
100            "dragCopy": self.dragCopy,
101            "dragMode": self.dragMode,
102            "dropBehaviour": self.dropBehaviour,
103            "editable": self.editable,
104            "icon": self.icon,
105            "itemHeight": self.itemHeight,
106            "keyNavigation": self.keyNavigation,
107            "rootId": self.rootId,
108            "selection": self.selection,
109            "template": self.template
110        }
111        return {k: v for k, v in config.items() if v is not None}
class TreeItemConfig:
 5class TreeItemConfig:
 6    def __init__(self,
 7                 id: Optional[Union[str, int]] = None,
 8                 value: Optional[str] = None,
 9                 opened: Optional[bool] = None,
10                 checkbox: Optional[bool] = None,
11                 items: Optional[List['TreeItemConfig']] = None,
12                 icon: Optional[dict] = None):
13        """
14        Initializes the configuration for a tree item.
15
16        :param id: The ID of the tree item.
17        :param value: The value of the tree item.
18        :param opened: Whether the tree item is opened by default.
19        :param checkbox: Whether the checkbox is displayed for the tree item.
20        :param items: Nested child tree items.
21        :param icon: Custom icons for the tree item.
22        """
23        self.id = id
24        self.value = value
25        self.opened = opened
26        self.checkbox = checkbox
27        self.items = items
28        self.icon = icon
29
30    def to_dict(self) -> Dict[str, Any]:
31        config = {
32            "id": self.id,
33            "value": self.value,
34            "opened": self.opened,
35            "checkbox": self.checkbox,
36            "items": [item.to_dict() for item in self.items] if self.items else None,
37            "icon": self.icon
38        }
39        return {k: v for k, v in config.items() if v is not None}
TreeItemConfig( id: Union[int, str, NoneType] = None, value: Optional[str] = None, opened: Optional[bool] = None, checkbox: Optional[bool] = None, items: Optional[List[TreeItemConfig]] = None, icon: Optional[dict] = None)
 6    def __init__(self,
 7                 id: Optional[Union[str, int]] = None,
 8                 value: Optional[str] = None,
 9                 opened: Optional[bool] = None,
10                 checkbox: Optional[bool] = None,
11                 items: Optional[List['TreeItemConfig']] = None,
12                 icon: Optional[dict] = None):
13        """
14        Initializes the configuration for a tree item.
15
16        :param id: The ID of the tree item.
17        :param value: The value of the tree item.
18        :param opened: Whether the tree item is opened by default.
19        :param checkbox: Whether the checkbox is displayed for the tree item.
20        :param items: Nested child tree items.
21        :param icon: Custom icons for the tree item.
22        """
23        self.id = id
24        self.value = value
25        self.opened = opened
26        self.checkbox = checkbox
27        self.items = items
28        self.icon = icon

Initializes the configuration for a tree item.

Parameters
  • id: The ID of the tree item.
  • value: The value of the tree item.
  • opened: Whether the tree item is opened by default.
  • checkbox: Whether the checkbox is displayed for the tree item.
  • items: Nested child tree items.
  • icon: Custom icons for the tree item.
id
value
opened
checkbox
items
icon
def to_dict(self) -> Dict[str, Any]:
30    def to_dict(self) -> Dict[str, Any]:
31        config = {
32            "id": self.id,
33            "value": self.value,
34            "opened": self.opened,
35            "checkbox": self.checkbox,
36            "items": [item.to_dict() for item in self.items] if self.items else None,
37            "icon": self.icon
38        }
39        return {k: v for k, v in config.items() if v is not None}