dhxpyt.window

1from .window import Window
2from .window_config import WindowConfig
3
4__all__ = ["Window", "WindowConfig"]
class Window:
 14class Window:
 15    def __init__(self, config: WindowConfig = None, widget_parent: str = None):
 16        """
 17        Initializes the Window widget.
 18
 19        :param config: (Optional) The WindowConfig object containing the window configuration.
 20        :param widget_parent: (Optional) The ID of the HTML element where the window will be attached.
 21        """
 22        if config is None:
 23            config = WindowConfig()
 24        config_dict = config.to_dict()
 25        # Create the Window instance
 26        self.window = js.dhx.Window.new(js.JSON.parse(json.dumps(config_dict)))
 27
 28    """ Window API Functions """
 29
 30    def attach(self, name: Union[str, Any], config: dict = None) -> None:
 31        """Attaches a DHTMLX component to the window."""
 32        self.window.attach(name, config)
 33
 34    def attach_html(self, html: str) -> None:
 35        """Adds an HTML content into a DHTMLX window."""
 36        self.window.attachHTML(html)
 37
 38    def destructor(self) -> None:
 39        """Releases the occupied resources."""
 40        self.window.destructor()
 41
 42    def get_container(self) -> Any:
 43        """Returns the HTML element of the window."""
 44        return self.window.getContainer()
 45
 46    def get_position(self) -> Dict[str, int]:
 47        """Gets the position of the window."""
 48        return self.window.getPosition().to_py()
 49
 50    def get_size(self) -> Dict[str, int]:
 51        """Gets the size of the window."""
 52        return self.window.getSize().to_py()
 53
 54    def get_widget(self) -> Any:
 55        """Returns the widget attached to the window."""
 56        return self.window.getWidget()
 57
 58    def hide(self) -> None:
 59        """Hides the window."""
 60        self.window.hide()
 61
 62    def is_full_screen(self) -> bool:
 63        """Checks whether the window is in full-screen mode."""
 64        return self.window.isFullScreen()
 65
 66    def is_visible(self) -> bool:
 67        """Checks whether the window is visible."""
 68        return self.window.isVisible()
 69
 70    def paint(self) -> None:
 71        """Repaints the window on the page."""
 72        self.window.paint()
 73
 74    def set_full_screen(self) -> None:
 75        """Switches the window to full-screen mode."""
 76        self.window.setFullScreen()
 77
 78    def set_position(self, left: int, top: int) -> None:
 79        """Sets the position of the window."""
 80        self.window.setPosition(left, top)
 81
 82    def set_size(self, width: int, height: int) -> None:
 83        """Sets the size of the window."""
 84        self.window.setSize(width, height)
 85
 86    def show(self, left: Optional[int] = None, top: Optional[int] = None) -> None:
 87        """Shows the window on the page."""
 88        self.window.show(left, top)
 89
 90    def unset_full_screen(self) -> None:
 91        """Switches the window from full-screen mode to windowed mode."""
 92        self.window.unsetFullScreen()
 93
 94    """ Window Event Handlers """
 95
 96    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 97        """
 98        Adds an event handler for the specified event.
 99
100        :param event_name: The name of the event.
101        :param handler: The handler function to attach.
102        """
103        event_proxy = create_proxy(handler)
104        self.window.events.on(event_name, event_proxy)
105
106    def on_after_hide(self, handler: Callable[[Dict[str, int], Optional[Any]], None]) -> None:
107        """Fires after the window is hidden."""
108        self.add_event_handler('afterHide', handler)
109
110    def on_after_show(self, handler: Callable[[Dict[str, int]], None]) -> None:
111        """Fires after the window is shown."""
112        self.add_event_handler('afterShow', handler)
113
114    def on_before_hide(self, handler: Callable[[Dict[str, int], Optional[Any]], Union[bool, None]]) -> None:
115        """Fires before the window is hidden."""
116        def event_handler(position, event=None):
117            result = handler(position, event)
118            if result is False:
119                return js.Boolean(False)
120        self.window.events.on('beforeHide', create_proxy(event_handler))
121
122    def on_before_show(self, handler: Callable[[Dict[str, int]], Union[bool, None]]) -> None:
123        """Fires before the window is shown."""
124        def event_handler(position):
125            result = handler(position)
126            if result is False:
127                return js.Boolean(False)
128        self.window.events.on('beforeShow', create_proxy(event_handler))
129
130    def on_header_double_click(self, handler: Callable[[Any], None]) -> None:
131        """Fires on double-clicking the window's header."""
132        self.add_event_handler('headerDoubleClick', handler)
133
134    def on_move(self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], None]) -> None:
135        """Fires on moving the window."""
136        self.add_event_handler('move', handler)
137
138    def on_resize(self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], None]) -> None:
139        """Fires on resizing the window."""
140        self.add_event_handler('resize', handler)
Window( config: WindowConfig = None, widget_parent: str = None)
15    def __init__(self, config: WindowConfig = None, widget_parent: str = None):
16        """
17        Initializes the Window widget.
18
19        :param config: (Optional) The WindowConfig object containing the window configuration.
20        :param widget_parent: (Optional) The ID of the HTML element where the window will be attached.
21        """
22        if config is None:
23            config = WindowConfig()
24        config_dict = config.to_dict()
25        # Create the Window instance
26        self.window = js.dhx.Window.new(js.JSON.parse(json.dumps(config_dict)))

Initializes the Window widget.

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

Window API Functions

def attach(self, name: Union[str, Any], config: dict = None) -> None:
30    def attach(self, name: Union[str, Any], config: dict = None) -> None:
31        """Attaches a DHTMLX component to the window."""
32        self.window.attach(name, config)

Attaches a DHTMLX component to the window.

def attach_html(self, html: str) -> None:
34    def attach_html(self, html: str) -> None:
35        """Adds an HTML content into a DHTMLX window."""
36        self.window.attachHTML(html)

Adds an HTML content into a DHTMLX window.

def destructor(self) -> None:
38    def destructor(self) -> None:
39        """Releases the occupied resources."""
40        self.window.destructor()

Releases the occupied resources.

def get_container(self) -> Any:
42    def get_container(self) -> Any:
43        """Returns the HTML element of the window."""
44        return self.window.getContainer()

Returns the HTML element of the window.

def get_position(self) -> Dict[str, int]:
46    def get_position(self) -> Dict[str, int]:
47        """Gets the position of the window."""
48        return self.window.getPosition().to_py()

Gets the position of the window.

def get_size(self) -> Dict[str, int]:
50    def get_size(self) -> Dict[str, int]:
51        """Gets the size of the window."""
52        return self.window.getSize().to_py()

Gets the size of the window.

def get_widget(self) -> Any:
54    def get_widget(self) -> Any:
55        """Returns the widget attached to the window."""
56        return self.window.getWidget()

Returns the widget attached to the window.

def hide(self) -> None:
58    def hide(self) -> None:
59        """Hides the window."""
60        self.window.hide()

Hides the window.

def is_full_screen(self) -> bool:
62    def is_full_screen(self) -> bool:
63        """Checks whether the window is in full-screen mode."""
64        return self.window.isFullScreen()

Checks whether the window is in full-screen mode.

def is_visible(self) -> bool:
66    def is_visible(self) -> bool:
67        """Checks whether the window is visible."""
68        return self.window.isVisible()

Checks whether the window is visible.

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

Repaints the window on the page.

def set_full_screen(self) -> None:
74    def set_full_screen(self) -> None:
75        """Switches the window to full-screen mode."""
76        self.window.setFullScreen()

Switches the window to full-screen mode.

def set_position(self, left: int, top: int) -> None:
78    def set_position(self, left: int, top: int) -> None:
79        """Sets the position of the window."""
80        self.window.setPosition(left, top)

Sets the position of the window.

def set_size(self, width: int, height: int) -> None:
82    def set_size(self, width: int, height: int) -> None:
83        """Sets the size of the window."""
84        self.window.setSize(width, height)

Sets the size of the window.

def show(self, left: Optional[int] = None, top: Optional[int] = None) -> None:
86    def show(self, left: Optional[int] = None, top: Optional[int] = None) -> None:
87        """Shows the window on the page."""
88        self.window.show(left, top)

Shows the window on the page.

def unset_full_screen(self) -> None:
90    def unset_full_screen(self) -> None:
91        """Switches the window from full-screen mode to windowed mode."""
92        self.window.unsetFullScreen()

Switches the window from full-screen mode to windowed mode.

def add_event_handler(self, event_name: str, handler: Callable) -> None:
 96    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 97        """
 98        Adds an event handler for the specified event.
 99
100        :param event_name: The name of the event.
101        :param handler: The handler function to attach.
102        """
103        event_proxy = create_proxy(handler)
104        self.window.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_hide( self, handler: Callable[[Dict[str, int], Optional[Any]], NoneType]) -> None:
106    def on_after_hide(self, handler: Callable[[Dict[str, int], Optional[Any]], None]) -> None:
107        """Fires after the window is hidden."""
108        self.add_event_handler('afterHide', handler)

Fires after the window is hidden.

def on_after_show(self, handler: Callable[[Dict[str, int]], NoneType]) -> None:
110    def on_after_show(self, handler: Callable[[Dict[str, int]], None]) -> None:
111        """Fires after the window is shown."""
112        self.add_event_handler('afterShow', handler)

Fires after the window is shown.

def on_before_hide( self, handler: Callable[[Dict[str, int], Optional[Any]], Optional[bool]]) -> None:
114    def on_before_hide(self, handler: Callable[[Dict[str, int], Optional[Any]], Union[bool, None]]) -> None:
115        """Fires before the window is hidden."""
116        def event_handler(position, event=None):
117            result = handler(position, event)
118            if result is False:
119                return js.Boolean(False)
120        self.window.events.on('beforeHide', create_proxy(event_handler))

Fires before the window is hidden.

def on_before_show(self, handler: Callable[[Dict[str, int]], Optional[bool]]) -> None:
122    def on_before_show(self, handler: Callable[[Dict[str, int]], Union[bool, None]]) -> None:
123        """Fires before the window is shown."""
124        def event_handler(position):
125            result = handler(position)
126            if result is False:
127                return js.Boolean(False)
128        self.window.events.on('beforeShow', create_proxy(event_handler))

Fires before the window is shown.

def on_header_double_click(self, handler: Callable[[Any], NoneType]) -> None:
130    def on_header_double_click(self, handler: Callable[[Any], None]) -> None:
131        """Fires on double-clicking the window's header."""
132        self.add_event_handler('headerDoubleClick', handler)

Fires on double-clicking the window's header.

def on_move( self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], NoneType]) -> None:
134    def on_move(self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], None]) -> None:
135        """Fires on moving the window."""
136        self.add_event_handler('move', handler)

Fires on moving the window.

def on_resize( self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], NoneType]) -> None:
138    def on_resize(self, handler: Callable[[Dict[str, int], Dict[str, int], Dict[str, bool]], None]) -> None:
139        """Fires on resizing the window."""
140        self.add_event_handler('resize', handler)

Fires on resizing the window.

class WindowConfig:
 5class WindowConfig:
 6    """
 7    Configuration class for the Window widget.
 8    """
 9    def __init__(self,
10                 closable: Optional[bool] = False,
11                 css: Optional[str] = None,
12                 footer: Optional[bool] = None,
13                 header: Optional[bool] = None,
14                 height: Optional[Union[int, str]] = "50%",
15                 html: Optional[str] = None,
16                 left: Optional[int] = None,
17                 minHeight: Optional[int] = 100,
18                 minWidth: Optional[int] = 100,
19                 modal: Optional[bool] = False,
20                 movable: Optional[bool] = False,
21                 node: Optional[Union[Any, str]] = None,
22                 resizable: Optional[bool] = False,
23                 title: Optional[str] = None,
24                 top: Optional[int] = None,
25                 viewportOverflow: Optional[bool] = False,
26                 width: Optional[Union[int, str]] = "50%"):
27        """
28        Initializes the WindowConfig.
29
30        :param closable: Defines whether a window can be closed.
31        :param css: Adds style classes for the window.
32        :param footer: Adds a footer to the window.
33        :param header: Adds a header to the window.
34        :param height: Sets the height of the window.
35        :param html: Sets an HTML content into a window on initialization.
36        :param left: The left coordinate of a window position.
37        :param minHeight: Sets the minimal height of a window.
38        :param minWidth: Sets the minimal width of a window.
39        :param modal: Defines whether a window is modal.
40        :param movable: Defines whether a window is movable.
41        :param node: The container for a window or its ID.
42        :param resizable: Defines whether a window can be resized.
43        :param title: Adds some text into the header of a window.
44        :param top: The top coordinate of a window position.
45        :param viewportOverflow: Defines whether a window can go beyond borders of the browser.
46        :param width: Sets the width of the window.
47        """
48        self.closable = closable
49        self.css = css
50        self.footer = footer
51        self.header = header
52        self.height = height
53        self.html = html
54        self.left = left
55        self.minHeight = minHeight
56        self.minWidth = minWidth
57        self.modal = modal
58        self.movable = movable
59        self.node = node
60        self.resizable = resizable
61        self.title = title
62        self.top = top
63        self.viewportOverflow = viewportOverflow
64        self.width = width
65
66    def to_dict(self) -> Dict[str, Any]:
67        """
68        Converts the WindowConfig into a dictionary format.
69        """
70        config_dict = {
71            'closable': self.closable,
72            'css': self.css,
73            'footer': self.footer,
74            'header': self.header,
75            'height': self.height,
76            'html': self.html,
77            'left': self.left,
78            'minHeight': self.minHeight,
79            'minWidth': self.minWidth,
80            'modal': self.modal,
81            'movable': self.movable,
82            'node': self.node,
83            'resizable': self.resizable,
84            'title': self.title,
85            'top': self.top,
86            'viewportOverflow': self.viewportOverflow,
87            'width': self.width
88        }
89        return {k: v for k, v in config_dict.items() if v is not None}

Configuration class for the Window widget.

WindowConfig( closable: Optional[bool] = False, css: Optional[str] = None, footer: Optional[bool] = None, header: Optional[bool] = None, height: Union[int, str, NoneType] = '50%', html: Optional[str] = None, left: Optional[int] = None, minHeight: Optional[int] = 100, minWidth: Optional[int] = 100, modal: Optional[bool] = False, movable: Optional[bool] = False, node: Union[Any, str, NoneType] = None, resizable: Optional[bool] = False, title: Optional[str] = None, top: Optional[int] = None, viewportOverflow: Optional[bool] = False, width: Union[int, str, NoneType] = '50%')
 9    def __init__(self,
10                 closable: Optional[bool] = False,
11                 css: Optional[str] = None,
12                 footer: Optional[bool] = None,
13                 header: Optional[bool] = None,
14                 height: Optional[Union[int, str]] = "50%",
15                 html: Optional[str] = None,
16                 left: Optional[int] = None,
17                 minHeight: Optional[int] = 100,
18                 minWidth: Optional[int] = 100,
19                 modal: Optional[bool] = False,
20                 movable: Optional[bool] = False,
21                 node: Optional[Union[Any, str]] = None,
22                 resizable: Optional[bool] = False,
23                 title: Optional[str] = None,
24                 top: Optional[int] = None,
25                 viewportOverflow: Optional[bool] = False,
26                 width: Optional[Union[int, str]] = "50%"):
27        """
28        Initializes the WindowConfig.
29
30        :param closable: Defines whether a window can be closed.
31        :param css: Adds style classes for the window.
32        :param footer: Adds a footer to the window.
33        :param header: Adds a header to the window.
34        :param height: Sets the height of the window.
35        :param html: Sets an HTML content into a window on initialization.
36        :param left: The left coordinate of a window position.
37        :param minHeight: Sets the minimal height of a window.
38        :param minWidth: Sets the minimal width of a window.
39        :param modal: Defines whether a window is modal.
40        :param movable: Defines whether a window is movable.
41        :param node: The container for a window or its ID.
42        :param resizable: Defines whether a window can be resized.
43        :param title: Adds some text into the header of a window.
44        :param top: The top coordinate of a window position.
45        :param viewportOverflow: Defines whether a window can go beyond borders of the browser.
46        :param width: Sets the width of the window.
47        """
48        self.closable = closable
49        self.css = css
50        self.footer = footer
51        self.header = header
52        self.height = height
53        self.html = html
54        self.left = left
55        self.minHeight = minHeight
56        self.minWidth = minWidth
57        self.modal = modal
58        self.movable = movable
59        self.node = node
60        self.resizable = resizable
61        self.title = title
62        self.top = top
63        self.viewportOverflow = viewportOverflow
64        self.width = width

Initializes the WindowConfig.

Parameters
  • closable: Defines whether a window can be closed.
  • css: Adds style classes for the window.
  • footer: Adds a footer to the window.
  • header: Adds a header to the window.
  • height: Sets the height of the window.
  • html: Sets an HTML content into a window on initialization.
  • left: The left coordinate of a window position.
  • minHeight: Sets the minimal height of a window.
  • minWidth: Sets the minimal width of a window.
  • modal: Defines whether a window is modal.
  • movable: Defines whether a window is movable.
  • node: The container for a window or its ID.
  • resizable: Defines whether a window can be resized.
  • title: Adds some text into the header of a window.
  • top: The top coordinate of a window position.
  • viewportOverflow: Defines whether a window can go beyond borders of the browser.
  • width: Sets the width of the window.
closable
css
footer
header
height
html
left
minHeight
minWidth
modal
movable
node
resizable
title
top
viewportOverflow
width
def to_dict(self) -> Dict[str, Any]:
66    def to_dict(self) -> Dict[str, Any]:
67        """
68        Converts the WindowConfig into a dictionary format.
69        """
70        config_dict = {
71            'closable': self.closable,
72            'css': self.css,
73            'footer': self.footer,
74            'header': self.header,
75            'height': self.height,
76            'html': self.html,
77            'left': self.left,
78            'minHeight': self.minHeight,
79            'minWidth': self.minWidth,
80            'modal': self.modal,
81            'movable': self.movable,
82            'node': self.node,
83            'resizable': self.resizable,
84            'title': self.title,
85            'top': self.top,
86            'viewportOverflow': self.viewportOverflow,
87            'width': self.width
88        }
89        return {k: v for k, v in config_dict.items() if v is not None}

Converts the WindowConfig into a dictionary format.