dhxpyt.sidebar
1from .sidebar import Sidebar 2from .sidebar_config import SidebarConfig, CustomHTMLConfig, MenuItemConfig, NavItemConfig, SeparatorConfig, SpacerConfig, TitleConfig 3 4__all__ = [ 5 'Sidebar', 6 'SidebarConfig', 7 'CustomHTMLConfig', 8 'MenuItemConfig', 9 'NavItemConfig', 10 'SeparatorConfig', 11 'SpacerConfig', 12 'TitleConfig' 13]
14class Sidebar: 15 def __init__(self, config: SidebarConfig = None, widget_parent: str = None): 16 """ 17 Initializes the Sidebar widget. 18 19 :param config: (Optional) The SidebarConfig object containing the sidebar configuration. 20 :param widget_parent: (Optional) The ID of the HTML element where the sidebar will be attached. 21 """ 22 if config is None: 23 config = SidebarConfig() 24 config_dict = config.to_dict() 25 # Create the Sidebar instance 26 self.sidebar = js.dhx.Sidebar.new(widget_parent, js.JSON.parse(json.dumps(config_dict))) 27 28 """ Sidebar API Functions """ 29 30 def collapse(self) -> None: 31 """Collapses the sidebar.""" 32 self.sidebar.collapse() 33 34 def destructor(self) -> None: 35 """Destroys the Sidebar instance and releases resources.""" 36 self.sidebar.destructor() 37 38 def disable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 39 """Disables and dims items of Sidebar.""" 40 self.sidebar.disable(ids) 41 42 def enable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 43 """Enables disabled items of Sidebar.""" 44 self.sidebar.enable(ids) 45 46 def expand(self) -> None: 47 """Expands the sidebar.""" 48 self.sidebar.expand() 49 50 def get_selected(self) -> List[Union[str, int]]: 51 """Returns an array of IDs of selected items.""" 52 selected = self.sidebar.getSelected() 53 return [item for item in selected.to_py()] 54 55 def hide(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 56 """Hides items of Sidebar.""" 57 self.sidebar.hide(ids) 58 59 def is_collapsed(self) -> bool: 60 """Checks whether Sidebar is collapsed.""" 61 return self.sidebar.isCollapsed() 62 63 def is_disabled(self, id: Union[str, int]) -> bool: 64 """Checks whether an item of Sidebar is disabled.""" 65 return self.sidebar.isDisabled(id) 66 67 def is_selected(self, id: Union[str, int]) -> bool: 68 """Checks whether a specified Sidebar item is selected.""" 69 return self.sidebar.isSelected(id) 70 71 def paint(self) -> None: 72 """Repaints Sidebar on a page.""" 73 self.sidebar.paint() 74 75 def select(self, id: Union[str, int], unselect: bool = True) -> None: 76 """Selects a specified Sidebar item.""" 77 self.sidebar.select(id, unselect) 78 79 def show(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 80 """Shows items of Sidebar.""" 81 self.sidebar.show(ids) 82 83 def toggle(self) -> None: 84 """Expands/collapses Sidebar.""" 85 self.sidebar.toggle() 86 87 def unselect(self, id: Union[str, int] = None) -> None: 88 """Unselects a selected Sidebar item.""" 89 self.sidebar.unselect(id) 90 91 """ Sidebar Event Handlers """ 92 93 def add_event_handler(self, event_name: str, handler: Callable) -> None: 94 """ 95 Adds an event handler for the specified event. 96 97 :param event_name: The name of the event. 98 :param handler: The handler function to attach. 99 """ 100 event_proxy = create_proxy(handler) 101 self.sidebar.events.on(event_name, event_proxy) 102 103 def on_after_collapse(self, handler: Callable[[], None]) -> None: 104 """Fires after collapsing a sidebar.""" 105 self.add_event_handler('afterCollapse', handler) 106 107 def on_after_expand(self, handler: Callable[[], None]) -> None: 108 """Fires after expanding a sidebar.""" 109 self.add_event_handler('afterExpand', handler) 110 111 def on_after_hide(self, handler: Callable[[Any], None]) -> None: 112 """ 113 Fires after hiding a sub-item of Sidebar. 114 115 :param handler: The handler function with parameter events (Event). 116 """ 117 self.add_event_handler('afterHide', handler) 118 119 def on_before_collapse(self, handler: Callable[[], Union[bool, None]]) -> None: 120 """ 121 Fires before collapsing a sidebar. 122 123 :param handler: The handler function that returns False to prevent collapsing. 124 """ 125 def event_handler(): 126 result = handler() 127 if result is False: 128 return js.Boolean(False) 129 self.sidebar.events.on('beforeCollapse', create_proxy(event_handler)) 130 131 def on_before_expand(self, handler: Callable[[], Union[bool, None]]) -> None: 132 """ 133 Fires before expanding a sidebar. 134 135 :param handler: The handler function that returns False to prevent expanding. 136 """ 137 def event_handler(): 138 result = handler() 139 if result is False: 140 return js.Boolean(False) 141 self.sidebar.events.on('beforeExpand', create_proxy(event_handler)) 142 143 def on_before_hide(self, handler: Callable[[Union[str, int], Any], Union[bool, None]]) -> None: 144 """ 145 Fires before hiding a sub-item of Sidebar. 146 147 :param handler: The handler function with parameters id (str or int), events (Event). 148 """ 149 def event_handler(id, events): 150 result = handler(id, events) 151 if result is False: 152 return js.Boolean(False) 153 self.sidebar.events.on('beforeHide', create_proxy(event_handler)) 154 155 def on_click(self, handler: Callable[[Union[str, int], Any], None]) -> None: 156 """ 157 Fires after a click on a control. 158 159 :param handler: The handler function with parameters id (str or int), events (Event). 160 """ 161 def event_handler(id, events): 162 handler(id, events) 163 self.sidebar.events.on('click', create_proxy(event_handler)) 164 165 def on_input_blur(self, handler: Callable[[Union[str, int]], None]) -> None: 166 """ 167 Fires when a control is blurred. 168 169 :param handler: The handler function with parameter id (str or int). 170 """ 171 self.add_event_handler('inputBlur', handler) 172 173 def on_input_created(self, handler: Callable[[Union[str, int], Any], None]) -> None: 174 """ 175 Fires when a new input is added. 176 177 :param handler: The handler function with parameters id (str or int), input (HTMLInputElement). 178 """ 179 def event_handler(id, input): 180 handler(id, input) 181 self.sidebar.events.on('inputCreated', create_proxy(event_handler)) 182 183 def on_input_focus(self, handler: Callable[[Union[str, int]], None]) -> None: 184 """ 185 Fires when a control is focused. 186 187 :param handler: The handler function with parameter id (str or int). 188 """ 189 self.add_event_handler('inputFocus', handler) 190 191 def on_keydown(self, handler: Callable[[Any, Optional[str]], None]) -> None: 192 """ 193 Fires when any key is pressed and a Sidebar option is in focus. 194 195 :param handler: The handler function with parameters event (KeyboardEvent), id (str or None). 196 """ 197 def event_handler(event, id=None): 198 handler(event, id) 199 self.sidebar.events.on('keydown', create_proxy(event_handler)) 200 201 def on_open_menu(self, handler: Callable[[Union[str, int]], None]) -> None: 202 """ 203 Fires on expanding a menu control. 204 205 :param handler: The handler function with parameter id (str or int). 206 """ 207 self.add_event_handler('openMenu', handler)
15 def __init__(self, config: SidebarConfig = None, widget_parent: str = None): 16 """ 17 Initializes the Sidebar widget. 18 19 :param config: (Optional) The SidebarConfig object containing the sidebar configuration. 20 :param widget_parent: (Optional) The ID of the HTML element where the sidebar will be attached. 21 """ 22 if config is None: 23 config = SidebarConfig() 24 config_dict = config.to_dict() 25 # Create the Sidebar instance 26 self.sidebar = js.dhx.Sidebar.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
Initializes the Sidebar widget.
Parameters
- config: (Optional) The SidebarConfig object containing the sidebar configuration.
- widget_parent: (Optional) The ID of the HTML element where the sidebar will be attached.
34 def destructor(self) -> None: 35 """Destroys the Sidebar instance and releases resources.""" 36 self.sidebar.destructor()
Destroys the Sidebar instance and releases resources.
38 def disable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 39 """Disables and dims items of Sidebar.""" 40 self.sidebar.disable(ids)
Disables and dims items of Sidebar.
42 def enable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 43 """Enables disabled items of Sidebar.""" 44 self.sidebar.enable(ids)
Enables disabled items of Sidebar.
50 def get_selected(self) -> List[Union[str, int]]: 51 """Returns an array of IDs of selected items.""" 52 selected = self.sidebar.getSelected() 53 return [item for item in selected.to_py()]
Returns an array of IDs of selected items.
55 def hide(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 56 """Hides items of Sidebar.""" 57 self.sidebar.hide(ids)
Hides items of Sidebar.
59 def is_collapsed(self) -> bool: 60 """Checks whether Sidebar is collapsed.""" 61 return self.sidebar.isCollapsed()
Checks whether Sidebar is collapsed.
63 def is_disabled(self, id: Union[str, int]) -> bool: 64 """Checks whether an item of Sidebar is disabled.""" 65 return self.sidebar.isDisabled(id)
Checks whether an item of Sidebar is disabled.
67 def is_selected(self, id: Union[str, int]) -> bool: 68 """Checks whether a specified Sidebar item is selected.""" 69 return self.sidebar.isSelected(id)
Checks whether a specified Sidebar item is selected.
75 def select(self, id: Union[str, int], unselect: bool = True) -> None: 76 """Selects a specified Sidebar item.""" 77 self.sidebar.select(id, unselect)
Selects a specified Sidebar item.
79 def show(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 80 """Shows items of Sidebar.""" 81 self.sidebar.show(ids)
Shows items of Sidebar.
87 def unselect(self, id: Union[str, int] = None) -> None: 88 """Unselects a selected Sidebar item.""" 89 self.sidebar.unselect(id)
Unselects a selected Sidebar item.
93 def add_event_handler(self, event_name: str, handler: Callable) -> None: 94 """ 95 Adds an event handler for the specified event. 96 97 :param event_name: The name of the event. 98 :param handler: The handler function to attach. 99 """ 100 event_proxy = create_proxy(handler) 101 self.sidebar.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.
103 def on_after_collapse(self, handler: Callable[[], None]) -> None: 104 """Fires after collapsing a sidebar.""" 105 self.add_event_handler('afterCollapse', handler)
Fires after collapsing a sidebar.
107 def on_after_expand(self, handler: Callable[[], None]) -> None: 108 """Fires after expanding a sidebar.""" 109 self.add_event_handler('afterExpand', handler)
Fires after expanding a sidebar.
111 def on_after_hide(self, handler: Callable[[Any], None]) -> None: 112 """ 113 Fires after hiding a sub-item of Sidebar. 114 115 :param handler: The handler function with parameter events (Event). 116 """ 117 self.add_event_handler('afterHide', handler)
Fires after hiding a sub-item of Sidebar.
Parameters
- handler: The handler function with parameter events (Event).
119 def on_before_collapse(self, handler: Callable[[], Union[bool, None]]) -> None: 120 """ 121 Fires before collapsing a sidebar. 122 123 :param handler: The handler function that returns False to prevent collapsing. 124 """ 125 def event_handler(): 126 result = handler() 127 if result is False: 128 return js.Boolean(False) 129 self.sidebar.events.on('beforeCollapse', create_proxy(event_handler))
Fires before collapsing a sidebar.
Parameters
- handler: The handler function that returns False to prevent collapsing.
131 def on_before_expand(self, handler: Callable[[], Union[bool, None]]) -> None: 132 """ 133 Fires before expanding a sidebar. 134 135 :param handler: The handler function that returns False to prevent expanding. 136 """ 137 def event_handler(): 138 result = handler() 139 if result is False: 140 return js.Boolean(False) 141 self.sidebar.events.on('beforeExpand', create_proxy(event_handler))
Fires before expanding a sidebar.
Parameters
- handler: The handler function that returns False to prevent expanding.
143 def on_before_hide(self, handler: Callable[[Union[str, int], Any], Union[bool, None]]) -> None: 144 """ 145 Fires before hiding a sub-item of Sidebar. 146 147 :param handler: The handler function with parameters id (str or int), events (Event). 148 """ 149 def event_handler(id, events): 150 result = handler(id, events) 151 if result is False: 152 return js.Boolean(False) 153 self.sidebar.events.on('beforeHide', create_proxy(event_handler))
Fires before hiding a sub-item of Sidebar.
Parameters
- handler: The handler function with parameters id (str or int), events (Event).
155 def on_click(self, handler: Callable[[Union[str, int], Any], None]) -> None: 156 """ 157 Fires after a click on a control. 158 159 :param handler: The handler function with parameters id (str or int), events (Event). 160 """ 161 def event_handler(id, events): 162 handler(id, events) 163 self.sidebar.events.on('click', create_proxy(event_handler))
Fires after a click on a control.
Parameters
- handler: The handler function with parameters id (str or int), events (Event).
165 def on_input_blur(self, handler: Callable[[Union[str, int]], None]) -> None: 166 """ 167 Fires when a control is blurred. 168 169 :param handler: The handler function with parameter id (str or int). 170 """ 171 self.add_event_handler('inputBlur', handler)
Fires when a control is blurred.
Parameters
- handler: The handler function with parameter id (str or int).
173 def on_input_created(self, handler: Callable[[Union[str, int], Any], None]) -> None: 174 """ 175 Fires when a new input is added. 176 177 :param handler: The handler function with parameters id (str or int), input (HTMLInputElement). 178 """ 179 def event_handler(id, input): 180 handler(id, input) 181 self.sidebar.events.on('inputCreated', create_proxy(event_handler))
Fires when a new input is added.
Parameters
- handler: The handler function with parameters id (str or int), input (HTMLInputElement).
183 def on_input_focus(self, handler: Callable[[Union[str, int]], None]) -> None: 184 """ 185 Fires when a control is focused. 186 187 :param handler: The handler function with parameter id (str or int). 188 """ 189 self.add_event_handler('inputFocus', handler)
Fires when a control is focused.
Parameters
- handler: The handler function with parameter id (str or int).
191 def on_keydown(self, handler: Callable[[Any, Optional[str]], None]) -> None: 192 """ 193 Fires when any key is pressed and a Sidebar option is in focus. 194 195 :param handler: The handler function with parameters event (KeyboardEvent), id (str or None). 196 """ 197 def event_handler(event, id=None): 198 handler(event, id) 199 self.sidebar.events.on('keydown', create_proxy(event_handler))
Fires when any key is pressed and a Sidebar option is in focus.
Parameters
- handler: The handler function with parameters event (KeyboardEvent), id (str or None).
140class SidebarConfig: 141 """ 142 Configuration class for the Sidebar widget. 143 """ 144 def __init__(self, 145 data: Optional[List[ControlConfig]] = None, 146 collapsed: Optional[bool] = None, 147 css: Optional[str] = None, 148 menuCss: Optional[str] = None, 149 minWidth: Union[int, str] = None, 150 width: Union[int, str] = None): 151 """ 152 Initializes the SidebarConfig. 153 154 :param data: (Optional) List of control configurations to set into Sidebar. 155 :param collapsed: (Optional) Defines that a sidebar is initialized in the collapsed state. 156 :param css: (Optional) Adds style classes to Sidebar. 157 :param menuCss: (Optional) Adds style classes to all containers of Sidebar controls with nested items. 158 :param minWidth: (Optional) Sets the minimal width of a sidebar in the collapsed state. 159 :param width: (Optional) Sets the width of a sidebar. 160 """ 161 self.data = data 162 self.collapsed = collapsed 163 self.css = css 164 self.menuCss = menuCss 165 self.minWidth = minWidth 166 self.width = width 167 168 def to_dict(self) -> Dict[str, Any]: 169 """ 170 Converts the SidebarConfig into a dictionary format. 171 """ 172 data_dicts = [item.to_dict() for item in self.data] if self.data else None 173 config_dict = { 174 'data': data_dicts, 175 'collapsed': self.collapsed, 176 'css': self.css, 177 'menuCss': self.menuCss, 178 'minWidth': self.minWidth, 179 'width': self.width 180 } 181 return {k: v for k, v in config_dict.items() if v is not None}
Configuration class for the Sidebar widget.
144 def __init__(self, 145 data: Optional[List[ControlConfig]] = None, 146 collapsed: Optional[bool] = None, 147 css: Optional[str] = None, 148 menuCss: Optional[str] = None, 149 minWidth: Union[int, str] = None, 150 width: Union[int, str] = None): 151 """ 152 Initializes the SidebarConfig. 153 154 :param data: (Optional) List of control configurations to set into Sidebar. 155 :param collapsed: (Optional) Defines that a sidebar is initialized in the collapsed state. 156 :param css: (Optional) Adds style classes to Sidebar. 157 :param menuCss: (Optional) Adds style classes to all containers of Sidebar controls with nested items. 158 :param minWidth: (Optional) Sets the minimal width of a sidebar in the collapsed state. 159 :param width: (Optional) Sets the width of a sidebar. 160 """ 161 self.data = data 162 self.collapsed = collapsed 163 self.css = css 164 self.menuCss = menuCss 165 self.minWidth = minWidth 166 self.width = width
Initializes the SidebarConfig.
Parameters
- data: (Optional) List of control configurations to set into Sidebar.
- collapsed: (Optional) Defines that a sidebar is initialized in the collapsed state.
- css: (Optional) Adds style classes to Sidebar.
- menuCss: (Optional) Adds style classes to all containers of Sidebar controls with nested items.
- minWidth: (Optional) Sets the minimal width of a sidebar in the collapsed state.
- width: (Optional) Sets the width of a sidebar.
168 def to_dict(self) -> Dict[str, Any]: 169 """ 170 Converts the SidebarConfig into a dictionary format. 171 """ 172 data_dicts = [item.to_dict() for item in self.data] if self.data else None 173 config_dict = { 174 'data': data_dicts, 175 'collapsed': self.collapsed, 176 'css': self.css, 177 'menuCss': self.menuCss, 178 'minWidth': self.minWidth, 179 'width': self.width 180 } 181 return {k: v for k, v in config_dict.items() if v is not None}
Converts the SidebarConfig into a dictionary format.
10class CustomHTMLConfig(ControlConfig): 11 def __init__(self, 12 id: Optional[str] = None, 13 parent: Optional[str] = None, 14 html: Optional[str] = None, 15 css: Optional[str] = None, 16 hidden: Optional[bool] = None): 17 self.type = "customHTML" 18 self.id = id 19 self.parent = parent 20 self.html = html 21 self.css = css 22 self.hidden = hidden
11 def __init__(self, 12 id: Optional[str] = None, 13 parent: Optional[str] = None, 14 html: Optional[str] = None, 15 css: Optional[str] = None, 16 hidden: Optional[bool] = None): 17 self.type = "customHTML" 18 self.id = id 19 self.parent = parent 20 self.html = html 21 self.css = css 22 self.hidden = hidden
25class MenuItemConfig(ControlConfig): 26 def __init__(self, 27 id: Optional[str] = None, 28 parent: Optional[str] = None, 29 value: Optional[str] = None, 30 items: Optional[List['ControlConfig']] = None, 31 count: Optional[int] = None, 32 countColor: Optional[str] = None, 33 hotkey: Optional[str] = None, 34 html: Optional[str] = None, 35 icon: Optional[str] = None, 36 tooltip: Optional[str] = None, 37 css: Optional[str] = None, 38 disabled: Optional[bool] = None, 39 hidden: Optional[bool] = None): 40 self.type = "menuItem" 41 self.id = id 42 self.parent = parent 43 self.value = value 44 self.items = items 45 self.count = count 46 self.countColor = countColor 47 self.hotkey = hotkey 48 self.html = html 49 self.icon = icon 50 self.tooltip = tooltip 51 self.css = css 52 self.disabled = disabled 53 self.hidden = hidden 54 55 def to_dict(self) -> Dict[str, Any]: 56 config = {k: v for k, v in self.__dict__.items() if v is not None} 57 if self.items: 58 config['items'] = [item.to_dict() for item in self.items] 59 return config
26 def __init__(self, 27 id: Optional[str] = None, 28 parent: Optional[str] = None, 29 value: Optional[str] = None, 30 items: Optional[List['ControlConfig']] = None, 31 count: Optional[int] = None, 32 countColor: Optional[str] = None, 33 hotkey: Optional[str] = None, 34 html: Optional[str] = None, 35 icon: Optional[str] = None, 36 tooltip: Optional[str] = None, 37 css: Optional[str] = None, 38 disabled: Optional[bool] = None, 39 hidden: Optional[bool] = None): 40 self.type = "menuItem" 41 self.id = id 42 self.parent = parent 43 self.value = value 44 self.items = items 45 self.count = count 46 self.countColor = countColor 47 self.hotkey = hotkey 48 self.html = html 49 self.icon = icon 50 self.tooltip = tooltip 51 self.css = css 52 self.disabled = disabled 53 self.hidden = hidden
105class SeparatorConfig(ControlConfig): 106 def __init__(self, 107 id: Optional[str] = None): 108 self.type = "separator" 109 self.id = id
112class SpacerConfig(ControlConfig): 113 def __init__(self, 114 id: Optional[str] = None): 115 self.type = "spacer" 116 self.id = id
119class TitleConfig(ControlConfig): 120 def __init__(self, 121 id: Optional[str] = None, 122 parent: Optional[str] = None, 123 value: Optional[str] = None, 124 html: Optional[str] = None, 125 tooltip: Optional[str] = None, 126 css: Optional[str] = None, 127 disabled: Optional[bool] = None, 128 hidden: Optional[bool] = None): 129 self.type = "title" 130 self.id = id 131 self.parent = parent 132 self.value = value 133 self.html = html 134 self.tooltip = tooltip 135 self.css = css 136 self.disabled = disabled 137 self.hidden = hidden
120 def __init__(self, 121 id: Optional[str] = None, 122 parent: Optional[str] = None, 123 value: Optional[str] = None, 124 html: Optional[str] = None, 125 tooltip: Optional[str] = None, 126 css: Optional[str] = None, 127 disabled: Optional[bool] = None, 128 hidden: Optional[bool] = None): 129 self.type = "title" 130 self.id = id 131 self.parent = parent 132 self.value = value 133 self.html = html 134 self.tooltip = tooltip 135 self.css = css 136 self.disabled = disabled 137 self.hidden = hidden