dhxpyt.menu
13class Menu: 14 def __init__(self, config: MenuConfig = None, widget_parent: Any = None): 15 """Initializes the Menu instance.""" 16 if config is None: 17 config = MenuConfig() 18 config_dict = config.to_dict() 19 self.menu = js.dhx.Menu.new(widget_parent, js.JSON.parse(json.dumps(config_dict))) 20 21 """ Menu API Functions """ 22 23 def destructor(self) -> None: 24 """Removes the Menu instance and releases occupied resources.""" 25 self.menu.destructor() 26 27 def disable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 28 """Disables and dims an item(s) of Menu.""" 29 self.menu.disable(ids) 30 31 def enable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 32 """Enables a disabled item(s) of Menu.""" 33 self.menu.enable(ids) 34 35 def get_selected(self) -> List[Union[str, int]]: 36 """Returns an array of IDs of selected items.""" 37 return list(self.menu.getSelected()) 38 39 def hide(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 40 """Hides an item(s) of Menu.""" 41 self.menu.hide(ids) 42 43 def is_disabled(self, id: Union[str, int]) -> bool: 44 """Checks whether an item of Menu is disabled.""" 45 return self.menu.isDisabled(id) 46 47 def is_selected(self, id: Union[str, int]) -> bool: 48 """Checks whether a specified Menu item is selected.""" 49 return self.menu.isSelected(id) 50 51 def paint(self) -> None: 52 """Repaints Menu on a page.""" 53 self.menu.paint() 54 55 def select(self, id: Union[str, int], unselect: bool = True) -> None: 56 """Selects a specified item of Menu.""" 57 self.menu.select(id, unselect) 58 59 def show(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 60 """Shows an item(s) of Menu.""" 61 self.menu.show(ids) 62 63 def show_at(self, elem: Union[str, Any], show_at: str = "bottom") -> None: 64 """Shows a context menu.""" 65 self.menu.showAt(elem, show_at) 66 67 def unselect(self, id: Union[str, int] = None) -> None: 68 """Unselects a selected Menu item.""" 69 self.menu.unselect(id) 70 71 """ Menu Events """ 72 73 def add_event_handler(self, event_name: str, handler: Callable) -> None: 74 """Helper to add event handlers dynamically.""" 75 event_proxy = create_proxy(handler) 76 self.menu.events.on(event_name, event_proxy) 77 78 def on_after_hide(self, handler: Callable[[Any], None]) -> None: 79 """Fires after hiding a sub-item of Menu.""" 80 self.add_event_handler('afterHide', handler) 81 82 def on_before_hide(self, handler: Callable[[Union[str, int], Any], Union[bool, None]]) -> None: 83 """Fires before hiding a sub-item of Menu.""" 84 def event_handler(id, events): 85 result = handler(id, events) 86 if result is False: 87 return js.Boolean(False) 88 event_proxy = create_proxy(event_handler) 89 self.menu.events.on('beforeHide', event_proxy) 90 91 def on_click(self, handler: Callable[[Union[str, int], Any], None]) -> None: 92 """Fires after a click on a button or a menu option.""" 93 self.add_event_handler('click', handler) 94 95 def on_keydown(self, handler: Callable[[Any, Union[str, int]], None]) -> None: 96 """Fires when any key is pressed and an option of Menu is in focus.""" 97 self.add_event_handler('keydown', handler) 98 99 def on_open_menu(self, handler: Callable[[Union[str, int]], None]) -> None: 100 """Fires on expanding a menu item.""" 101 self.add_event_handler('openMenu', handler) 102 103 """ Menu Properties """ 104 105 @property 106 def css(self) -> str: 107 """Gets or sets the CSS classes for Menu.""" 108 return self.menu.config.css 109 110 @css.setter 111 def css(self, value: str) -> None: 112 self.menu.config.css = value 113 114 @property 115 def data(self) -> List[Dict[str, Any]]: 116 """Gets or sets the data objects for Menu.""" 117 return self.menu.config.data 118 119 @data.setter 120 def data(self, value: List[Dict[str, Any]]) -> None: 121 self.menu.data.parse(js.JSON.parse(json.dumps(value))) 122 123 @property 124 def menu_css(self) -> str: 125 """Gets or sets the CSS classes for Menu controls with nested items.""" 126 return self.menu.config.menuCss 127 128 @menu_css.setter 129 def menu_css(self, value: str) -> None: 130 self.menu.config.menuCss = value 131 132 @property 133 def navigation_type(self) -> str: 134 """Gets or sets the action that opens menu options ('click' or 'pointer').""" 135 return self.menu.config.navigationType 136 137 @navigation_type.setter 138 def navigation_type(self, value: str) -> None: 139 self.menu.config.navigationType = value
14 def __init__(self, config: MenuConfig = None, widget_parent: Any = None): 15 """Initializes the Menu instance.""" 16 if config is None: 17 config = MenuConfig() 18 config_dict = config.to_dict() 19 self.menu = js.dhx.Menu.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
Initializes the Menu instance.
23 def destructor(self) -> None: 24 """Removes the Menu instance and releases occupied resources.""" 25 self.menu.destructor()
Removes the Menu instance and releases occupied resources.
27 def disable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 28 """Disables and dims an item(s) of Menu.""" 29 self.menu.disable(ids)
Disables and dims an item(s) of Menu.
31 def enable(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 32 """Enables a disabled item(s) of Menu.""" 33 self.menu.enable(ids)
Enables a disabled item(s) of Menu.
35 def get_selected(self) -> List[Union[str, int]]: 36 """Returns an array of IDs of selected items.""" 37 return list(self.menu.getSelected())
Returns an array of IDs of selected items.
39 def hide(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 40 """Hides an item(s) of Menu.""" 41 self.menu.hide(ids)
Hides an item(s) of Menu.
43 def is_disabled(self, id: Union[str, int]) -> bool: 44 """Checks whether an item of Menu is disabled.""" 45 return self.menu.isDisabled(id)
Checks whether an item of Menu is disabled.
47 def is_selected(self, id: Union[str, int]) -> bool: 48 """Checks whether a specified Menu item is selected.""" 49 return self.menu.isSelected(id)
Checks whether a specified Menu item is selected.
55 def select(self, id: Union[str, int], unselect: bool = True) -> None: 56 """Selects a specified item of Menu.""" 57 self.menu.select(id, unselect)
Selects a specified item of Menu.
59 def show(self, ids: Union[str, int, List[Union[str, int]]] = None) -> None: 60 """Shows an item(s) of Menu.""" 61 self.menu.show(ids)
Shows an item(s) of Menu.
63 def show_at(self, elem: Union[str, Any], show_at: str = "bottom") -> None: 64 """Shows a context menu.""" 65 self.menu.showAt(elem, show_at)
Shows a context menu.
67 def unselect(self, id: Union[str, int] = None) -> None: 68 """Unselects a selected Menu item.""" 69 self.menu.unselect(id)
Unselects a selected Menu item.
73 def add_event_handler(self, event_name: str, handler: Callable) -> None: 74 """Helper to add event handlers dynamically.""" 75 event_proxy = create_proxy(handler) 76 self.menu.events.on(event_name, event_proxy)
Helper to add event handlers dynamically.
78 def on_after_hide(self, handler: Callable[[Any], None]) -> None: 79 """Fires after hiding a sub-item of Menu.""" 80 self.add_event_handler('afterHide', handler)
Fires after hiding a sub-item of Menu.
82 def on_before_hide(self, handler: Callable[[Union[str, int], Any], Union[bool, None]]) -> None: 83 """Fires before hiding a sub-item of Menu.""" 84 def event_handler(id, events): 85 result = handler(id, events) 86 if result is False: 87 return js.Boolean(False) 88 event_proxy = create_proxy(event_handler) 89 self.menu.events.on('beforeHide', event_proxy)
Fires before hiding a sub-item of Menu.
91 def on_click(self, handler: Callable[[Union[str, int], Any], None]) -> None: 92 """Fires after a click on a button or a menu option.""" 93 self.add_event_handler('click', handler)
Fires after a click on a button or a menu option.
95 def on_keydown(self, handler: Callable[[Any, Union[str, int]], None]) -> None: 96 """Fires when any key is pressed and an option of Menu is in focus.""" 97 self.add_event_handler('keydown', handler)
Fires when any key is pressed and an option of Menu is in focus.
75class MenuConfig: 76 """ 77 Configuration class for Menu. 78 """ 79 def __init__(self, 80 css: str = None, 81 data: List[MenuItemConfig] = None, 82 menuCss: str = None, 83 navigationType: str = "pointer"): 84 """ 85 :param css: (Optional) Adds style classes to Menu. 86 :param data: (Optional) Specifies an array of MenuItemConfig objects to set into Menu. 87 :param menuCss: (Optional) Adds style classes to all containers of Menu controls with nested items. 88 :param navigationType: (Optional) Defines the action that opens menu options ('click' or 'pointer'). 89 """ 90 self.css = css 91 self.data = data if data else [] 92 self.menuCss = menuCss 93 self.navigationType = navigationType 94 95 def to_dict(self) -> Dict[str, Any]: 96 """ 97 Converts the MenuConfig into a dictionary format that can be 98 passed into the menu constructor. 99 """ 100 config_dict = { 101 'css': self.css, 102 'data': [item.to_dict() for item in self.data], 103 'menuCss': self.menuCss, 104 'navigationType': self.navigationType 105 } 106 # Remove None values 107 return {k: v for k, v in config_dict.items() if v is not None}
Configuration class for Menu.
79 def __init__(self, 80 css: str = None, 81 data: List[MenuItemConfig] = None, 82 menuCss: str = None, 83 navigationType: str = "pointer"): 84 """ 85 :param css: (Optional) Adds style classes to Menu. 86 :param data: (Optional) Specifies an array of MenuItemConfig objects to set into Menu. 87 :param menuCss: (Optional) Adds style classes to all containers of Menu controls with nested items. 88 :param navigationType: (Optional) Defines the action that opens menu options ('click' or 'pointer'). 89 """ 90 self.css = css 91 self.data = data if data else [] 92 self.menuCss = menuCss 93 self.navigationType = navigationType
Parameters
- css: (Optional) Adds style classes to Menu.
- data: (Optional) Specifies an array of MenuItemConfig objects to set into Menu.
- menuCss: (Optional) Adds style classes to all containers of Menu controls with nested items.
- navigationType: (Optional) Defines the action that opens menu options ('click' or 'pointer').
95 def to_dict(self) -> Dict[str, Any]: 96 """ 97 Converts the MenuConfig into a dictionary format that can be 98 passed into the menu constructor. 99 """ 100 config_dict = { 101 'css': self.css, 102 'data': [item.to_dict() for item in self.data], 103 'menuCss': self.menuCss, 104 'navigationType': self.navigationType 105 } 106 # Remove None values 107 return {k: v for k, v in config_dict.items() if v is not None}
Converts the MenuConfig into a dictionary format that can be passed into the menu constructor.
5class MenuItemConfig: 6 """ 7 Configuration class for individual items in the Menu. 8 """ 9 def __init__(self, 10 id: Union[str, int] = None, 11 value: str = None, 12 type: str = "menuItem", 13 parent: Union[str, int] = None, 14 items: List['MenuItemConfig'] = None, 15 count: Union[int, str] = None, 16 countColor: str = "danger", 17 hotkey: str = None, 18 html: str = None, 19 icon: str = None, 20 css: str = None, 21 disabled: bool = False, 22 hidden: bool = False): 23 """ 24 :param id: (Optional) The id of the menu item. 25 :param value: (Optional) The text value of the menu item. 26 :param type: (Optional) The type of control, should be "menuItem". 27 :param parent: (Optional) The parent id of the menu item. 28 :param items: (Optional) An array of child MenuItemConfig objects. 29 :param count: (Optional) A badge with a number. 30 :param countColor: (Optional) The color of the badge ("danger", "secondary", "primary", "success"). 31 :param hotkey: (Optional) The name of a keyboard shortcut for the menu item. 32 :param html: (Optional) A string with HTML to insert into the menu item. 33 :param icon: (Optional) The name of an icon from the used icon font. 34 :param css: (Optional) Adds style classes. 35 :param disabled: (Optional) Defines whether an item is disabled. 36 :param hidden: (Optional) Defines whether the control is hidden. 37 """ 38 self.id = id 39 self.value = value 40 self.type = type 41 self.parent = parent 42 self.items = items if items else [] 43 self.count = count 44 self.countColor = countColor 45 self.hotkey = hotkey 46 self.html = html 47 self.icon = icon 48 self.css = css 49 self.disabled = disabled 50 self.hidden = hidden 51 52 def to_dict(self) -> Dict[str, Any]: 53 """ 54 Converts the MenuItemConfig into a dictionary format that can be 55 passed into the menu constructor. 56 """ 57 config_dict = { 58 'id': self.id, 59 'value': self.value, 60 'type': self.type, 61 'parent': self.parent, 62 'items': [item.to_dict() for item in self.items] if self.items else None, 63 'count': self.count, 64 'countColor': self.countColor, 65 'hotkey': self.hotkey, 66 'html': self.html, 67 'icon': self.icon, 68 'css': self.css, 69 'disabled': self.disabled, 70 'hidden': self.hidden 71 } 72 # Remove None values 73 return {k: v for k, v in config_dict.items() if v is not None}
Configuration class for individual items in the Menu.
9 def __init__(self, 10 id: Union[str, int] = None, 11 value: str = None, 12 type: str = "menuItem", 13 parent: Union[str, int] = None, 14 items: List['MenuItemConfig'] = None, 15 count: Union[int, str] = None, 16 countColor: str = "danger", 17 hotkey: str = None, 18 html: str = None, 19 icon: str = None, 20 css: str = None, 21 disabled: bool = False, 22 hidden: bool = False): 23 """ 24 :param id: (Optional) The id of the menu item. 25 :param value: (Optional) The text value of the menu item. 26 :param type: (Optional) The type of control, should be "menuItem". 27 :param parent: (Optional) The parent id of the menu item. 28 :param items: (Optional) An array of child MenuItemConfig objects. 29 :param count: (Optional) A badge with a number. 30 :param countColor: (Optional) The color of the badge ("danger", "secondary", "primary", "success"). 31 :param hotkey: (Optional) The name of a keyboard shortcut for the menu item. 32 :param html: (Optional) A string with HTML to insert into the menu item. 33 :param icon: (Optional) The name of an icon from the used icon font. 34 :param css: (Optional) Adds style classes. 35 :param disabled: (Optional) Defines whether an item is disabled. 36 :param hidden: (Optional) Defines whether the control is hidden. 37 """ 38 self.id = id 39 self.value = value 40 self.type = type 41 self.parent = parent 42 self.items = items if items else [] 43 self.count = count 44 self.countColor = countColor 45 self.hotkey = hotkey 46 self.html = html 47 self.icon = icon 48 self.css = css 49 self.disabled = disabled 50 self.hidden = hidden
Parameters
- id: (Optional) The id of the menu item.
- value: (Optional) The text value of the menu item.
- type: (Optional) The type of control, should be "menuItem".
- parent: (Optional) The parent id of the menu item.
- items: (Optional) An array of child MenuItemConfig objects.
- count: (Optional) A badge with a number.
- countColor: (Optional) The color of the badge ("danger", "secondary", "primary", "success").
- hotkey: (Optional) The name of a keyboard shortcut for the menu item.
- html: (Optional) A string with HTML to insert into the menu item.
- icon: (Optional) The name of an icon from the used icon font.
- css: (Optional) Adds style classes.
- disabled: (Optional) Defines whether an item is disabled.
- hidden: (Optional) Defines whether the control is hidden.
52 def to_dict(self) -> Dict[str, Any]: 53 """ 54 Converts the MenuItemConfig into a dictionary format that can be 55 passed into the menu constructor. 56 """ 57 config_dict = { 58 'id': self.id, 59 'value': self.value, 60 'type': self.type, 61 'parent': self.parent, 62 'items': [item.to_dict() for item in self.items] if self.items else None, 63 'count': self.count, 64 'countColor': self.countColor, 65 'hotkey': self.hotkey, 66 'html': self.html, 67 'icon': self.icon, 68 'css': self.css, 69 'disabled': self.disabled, 70 'hidden': self.hidden 71 } 72 # Remove None values 73 return {k: v for k, v in config_dict.items() if v is not None}
Converts the MenuItemConfig into a dictionary format that can be passed into the menu constructor.