Skip to content

Commit

Permalink
Move class attribute doc from the class docstring to each attribute d… (
Browse files Browse the repository at this point in the history
#1969)

* Move class attribute doc from the class docstring to each attribute docstinrg

* Removed useless attributes doc

---------

Co-authored-by: Fabien Lelaquais <[email protected]>
  • Loading branch information
jrobinAV and FabienLelaquais authored Oct 13, 2024
1 parent 6a50d5a commit 3297952
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 98 deletions.
192 changes: 103 additions & 89 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,96 +119,8 @@
class Gui:
"""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
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
use:
```py
Expand Down Expand Up @@ -341,13 +253,110 @@ def __init__(

# default actions
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
"""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
"""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
"""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
"""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
"""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
"""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
"""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
self.__client_id_2_sid: t.Dict[str, t.Set[str]] = {}
Expand Down Expand Up @@ -2773,6 +2782,11 @@ def run(
if _is_in_notebook():
# Allow gui.state.x in notebook mode
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()

Expand Down
13 changes: 4 additions & 9 deletions taipy/gui/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class Icon:
[button](../../../../../refmans/gui/viselements/generic/button.md)
or items in a [menu](../../../../../refmans/gui/viselements/generic/menu.md).
Attributes:
path (str): The path to the image file.
text (Optional[str]): The text associated to the image or None if there is none.
svg (Optional[bool]): True if the image is svg.
If a text is associated to an icon, it is rendered by the visual elements that
uses this Icon.
"""
Expand Down Expand Up @@ -56,12 +51,12 @@ def __init__(
light_path (Optional[str]): The path to the light theme image (fallback to *path* if not defined).
dark_path (Optional[str]): The path to the dark theme image (fallback to *path* if not defined).
"""
self.path = path
self.text = text
self.path: str = path
self.text: t.Optional[str] = text
if light_path is not None:
self.light_path = light_path
self.light_path: t.Optional[str] = light_path
if dark_path is not None:
self.dark_path = dark_path
self.dark_path: t.Optional[str] = dark_path

def _to_dict(self, a_dict: t.Optional[dict] = None) -> dict:
if a_dict is None:
Expand Down

0 comments on commit 3297952

Please sign in to comment.