|
@@ -119,96 +119,8 @@ from .utils.table_col_builder import _enhance_columns
|
|
class Gui:
|
|
class Gui:
|
|
"""Entry point for the Graphical User Interface generation.
|
|
"""Entry point for the Graphical User Interface generation.
|
|
|
|
|
|
- Attributes:
|
|
|
|
- on_action (Callable): The function that is called when a control
|
|
|
|
- triggers an action, as the result of an interaction with the end-user.<br/>
|
|
|
|
- It defaults to the `on_action()` global function defined in the Python
|
|
|
|
- application. If there is no such function, actions will not trigger anything.<br/>
|
|
|
|
- The signature of the *on_action* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *id* (optional): a string representing the identifier of the caller.
|
|
|
|
- - *payload* (optional): an optional payload from the caller.
|
|
|
|
- on_change (Callable): The function that is called when a control
|
|
|
|
- modifies variables it is bound to, as the result of an interaction with the
|
|
|
|
- end-user.<br/>
|
|
|
|
- It defaults to the `on_change()` global function defined in the Python
|
|
|
|
- application. If there is no such function, user interactions will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
- The signature of the *on_change* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *var_name* (str): The name of the variable that triggered this callback.
|
|
|
|
- - *var_value* (any): The new value for this variable.
|
|
|
|
- on_init (Callable): The function that is called on the first connection of a new client.<br/>
|
|
|
|
- It defaults to the `on_init()` global function defined in the Python
|
|
|
|
- application. If there is no such function, the first connection will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
-
|
|
|
|
- The signature of the *on_init* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- on_page_load (Callable): This callback is invoked just before the page content is sent
|
|
|
|
- to the front-end.<br/>
|
|
|
|
- It defaults to the `on_page_load()` global function defined in the Python
|
|
|
|
- application. If there is no such function, page loads will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
-
|
|
|
|
- The signature of the *on_page_load* callback function must be:
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *page_name*: the name of the page that is being loaded.
|
|
|
|
- on_navigate (Callable): The function that is called when a page is requested.<br/>
|
|
|
|
- It defaults to the `on_navigate()` global function defined in the Python
|
|
|
|
- application. If there is no such function, page requests will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
- The signature of the *on_navigate* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *page_name*: the name of the page the user is navigating to.
|
|
|
|
- - *params* (Optional): the query parameters provided in the URL.
|
|
|
|
-
|
|
|
|
- The *on_navigate* callback function must return the name of the page the user should be
|
|
|
|
- directed to.
|
|
|
|
- on_exception (Callable): The function that is called an exception occurs on user code.<br/>
|
|
|
|
- It defaults to the `on_exception()` global function defined in the Python
|
|
|
|
- application. If there is no such function, exceptions will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
- The signature of the *on_exception* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *function_name*: the name of the function that raised the exception.
|
|
|
|
- - *exception*: the exception object that was raised.
|
|
|
|
- on_status (Callable): The function that is called when the status page is shown.<br/>
|
|
|
|
- It defaults to the `on_status()` global function defined in the Python
|
|
|
|
- application. If there is no such function, status page content shows only the status of the
|
|
|
|
- server.<br/>
|
|
|
|
- The signature of the *on_status* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
-
|
|
|
|
- It must return raw and valid HTML content as a string.
|
|
|
|
- on_user_content (Callable): The function that is called when a specific URL (generated by
|
|
|
|
- `get_user_content_url()^`) is requested.<br/>
|
|
|
|
- This callback function must return the raw HTML content of the page to be displayed on
|
|
|
|
- the browser.
|
|
|
|
-
|
|
|
|
- This attribute defaults to the `on_user_content()` global function defined in the Python
|
|
|
|
- application. If there is no such function, those specific URLs will not trigger
|
|
|
|
- anything.<br/>
|
|
|
|
- The signature of the *on_user_content* callback function must be:
|
|
|
|
-
|
|
|
|
- - *state*: the `State^` instance of the caller.
|
|
|
|
- - *path*: the path provided to the `get_user_content_url()^` to build the URL.
|
|
|
|
- - *parameters*: An optional dictionary as defined in the `get_user_content_url()^` call.
|
|
|
|
-
|
|
|
|
- The returned HTML content can therefore use both the variables stored in the *state*
|
|
|
|
- and the parameters provided in the call to `get_user_content_url()^`.
|
|
|
|
- state (State^): **Only defined when running in an IPython notebook context.**<br/>
|
|
|
|
- The unique instance of `State^` that you can use to change bound variables
|
|
|
|
- directly, potentially impacting the user interface in real-time.
|
|
|
|
-
|
|
|
|
!!! note
|
|
!!! note
|
|
- This class belongs to and is documented in the `taipy.gui` package but it is
|
|
|
|
|
|
+ This class belongs to and is documented in the `taipy.gui` package, but it is
|
|
accessible from the top `taipy` package to simplify its access, allowing to
|
|
accessible from the top `taipy` package to simplify its access, allowing to
|
|
use:
|
|
use:
|
|
```py
|
|
```py
|
|
@@ -341,13 +253,110 @@ class Gui:
|
|
|
|
|
|
# default actions
|
|
# default actions
|
|
self.on_action: t.Optional[t.Callable] = None
|
|
self.on_action: t.Optional[t.Callable] = None
|
|
|
|
+ """The function called when a control triggers an action, as the result of an end-user's interaction.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_action()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, actions will not trigger anything.<br/>
|
|
|
|
+ The signature of the *on_action* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *id* (optional): a string representing the identifier of the caller.
|
|
|
|
+ - *payload* (optional): an optional payload from the caller.
|
|
|
|
+ """
|
|
self.on_change: t.Optional[t.Callable] = None
|
|
self.on_change: t.Optional[t.Callable] = None
|
|
|
|
+ """The function called when a control modifies bound variables, as the result of an end-user's interaction.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_change()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, user interactions will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+ The signature of the *on_change* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *var_name* (str): The name of the variable that triggered this callback.
|
|
|
|
+ - *var_value* (any): The new value for this variable.
|
|
|
|
+ """
|
|
self.on_init: t.Optional[t.Callable] = None
|
|
self.on_init: t.Optional[t.Callable] = None
|
|
|
|
+ """The function that is called on the first connection of a new client.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_init()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, the first connection will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+
|
|
|
|
+ The signature of the *on_init* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ """
|
|
self.on_page_load: t.Optional[t.Callable] = None
|
|
self.on_page_load: t.Optional[t.Callable] = None
|
|
|
|
+ """This callback is invoked just before the page content is sent to the front-end.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_page_load()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, page loads will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+
|
|
|
|
+ The signature of the *on_page_load* callback function must be:
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *page_name*: the name of the page that is being loaded.
|
|
|
|
+ """
|
|
self.on_navigate: t.Optional[t.Callable] = None
|
|
self.on_navigate: t.Optional[t.Callable] = None
|
|
|
|
+ """The function that is called when a page is requested.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_navigate()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, page requests will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+
|
|
|
|
+ The signature of the *on_navigate* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *page_name*: the name of the page the user is navigating to.
|
|
|
|
+ - *params* (Optional): the query parameters provided in the URL.
|
|
|
|
+
|
|
|
|
+ The *on_navigate* callback function must return the name of the page the user should be
|
|
|
|
+ directed to.
|
|
|
|
+ """
|
|
self.on_exception: t.Optional[t.Callable] = None
|
|
self.on_exception: t.Optional[t.Callable] = None
|
|
|
|
+ """The function that is called an exception occurs on user code.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_exception()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, exceptions will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+
|
|
|
|
+ The signature of the *on_exception* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *function_name*: the name of the function that raised the exception.
|
|
|
|
+ - *exception*: the exception object that was raised.
|
|
|
|
+ """
|
|
self.on_status: t.Optional[t.Callable] = None
|
|
self.on_status: t.Optional[t.Callable] = None
|
|
|
|
+ """The function that is called when the status page is shown.
|
|
|
|
+
|
|
|
|
+ It defaults to the `on_status()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, status page content shows only the status of the
|
|
|
|
+ server.<br/>
|
|
|
|
+
|
|
|
|
+ The signature of the *on_status* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+
|
|
|
|
+ It must return raw and valid HTML content as a string.
|
|
|
|
+ """
|
|
self.on_user_content: t.Optional[t.Callable] = None
|
|
self.on_user_content: t.Optional[t.Callable] = None
|
|
|
|
+ """The function that is called when a specific URL (generated by `get_user_content_url()^`) is requested.
|
|
|
|
+
|
|
|
|
+ This callback function must return the raw HTML content of the page to be displayed on
|
|
|
|
+ the browser.
|
|
|
|
+
|
|
|
|
+ This attribute defaults to the `on_user_content()` global function defined in the Python
|
|
|
|
+ application. If there is no such function, those specific URLs will not trigger
|
|
|
|
+ anything.<br/>
|
|
|
|
+ The signature of the *on_user_content* callback function must be:
|
|
|
|
+
|
|
|
|
+ - *state*: the `State^` instance of the caller.
|
|
|
|
+ - *path*: the path provided to the `get_user_content_url()^` to build the URL.
|
|
|
|
+ - *parameters*: An optional dictionary as defined in the `get_user_content_url()^` call.
|
|
|
|
+
|
|
|
|
+ The returned HTML content can therefore use both the variables stored in the *state*
|
|
|
|
+ and the parameters provided in the call to `get_user_content_url()^`.
|
|
|
|
+ """
|
|
|
|
|
|
# sid from client_id
|
|
# sid from client_id
|
|
self.__client_id_2_sid: t.Dict[str, t.Set[str]] = {}
|
|
self.__client_id_2_sid: t.Dict[str, t.Set[str]] = {}
|
|
@@ -2773,6 +2782,11 @@ class Gui:
|
|
if _is_in_notebook():
|
|
if _is_in_notebook():
|
|
# Allow gui.state.x in notebook mode
|
|
# Allow gui.state.x in notebook mode
|
|
self.state = self.__state
|
|
self.state = self.__state
|
|
|
|
+ """Only defined when running in an IPython notebook context.
|
|
|
|
+
|
|
|
|
+ The unique instance of State that you can use to change bound variables directly,
|
|
|
|
+ potentially impacting the user interface in real-time.
|
|
|
|
+ """
|
|
|
|
|
|
self.__bind_default_function()
|
|
self.__bind_default_function()
|
|
|
|
|