taipy.gui.Gui
Entry point for the Graphical User Interface generation.
Attributes:
Name | Type | Description |
---|---|---|
on_action |
Callable
|
The function that is called when a control
triggers an action, as the result of an interaction with the end-user.
|
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.
|
on_init |
Callable
|
The function that is called on the first connection of a new client. The signature of the on_init callback function must be:
|
on_navigate |
Callable
|
The function that is called when a page is requested.
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.
|
on_status |
Callable
|
The function that is called when the status page is shown.
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
This attribute defaults to the
The returned HTML content can therefore use both the variables stored in the state
and the parameters provided in the call to |
state |
State
|
Only defined when running in an IPython notebook context. |
Note
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:
from taipy import Gui
__init__(page=None, pages=None, css_file=None, path_mapping=None, env_filename=None, libraries=None, flask=None)
¶
Initialize a new Gui instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page |
Optional[Union[str, Page]]
|
An optional |
None
|
pages |
Optional[dict]
|
Used if you want to initialize this instance with a set
of pages. |
None
|
css_file |
Optional[str]
|
A pathname to a CSS file that gets used as a style sheet in
all the pages. |
None
|
path_mapping |
Optional[dict]
|
A dictionary that associates a URL prefix to
a path in the server file system. |
None
|
env_filename |
Optional[str]
|
An optional file from which to load application
configuration variables (see the
Configuration section
of the User Manual for details.) |
None
|
libraries |
Optional[List[ElementLibrary]]
|
An optional list of extension library
instances that pages can reference. |
None
|
flask |
Optional[Flask]
|
An optional instance of a Flask application object. |
None
|
__pre_render_pages()
¶
Pre-render all pages to have a proper initialization of all variables
add_library(library)
staticmethod
¶
Add a custom visual element library.
This application will be able to use custom visual elements defined in this library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library |
ElementLibrary
|
The custom visual element library to add to this application. |
required |
Multiple libraries with the same name can be added. This allows to split multiple custom visual
elements in several ElementLibrary
instances, but still refer to these elements with the same
prefix in the page definitions.
add_page(name, page, style='')
¶
Add a page to the Graphical User Interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the page. |
required |
page |
Union[str, Page]
|
required | |
style |
Optional[str]
|
Additional CSS style to apply to this page.
|
''
|
Note that page names cannot start with the slash ('/') character and that each page must have a unique name.
add_pages(pages=None)
¶
Add several pages to the Graphical User Interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pages |
Union[dict[str, Union[str, Page]], str]
|
The pages to add.
|
None
|
Reading pages from a directory
If pages is a string that holds the path to a readable directory, then this directory is traversed, recursively, to find files that Taipy can build pages from.
For every new directory that is traversed, a new hierarchical level for pages is created.
For every file that is found:
- If the filename extension is .md, it is read as Markdown content and a new page is created with the base name of this filename.
- If the filename extension is .html, it is read as HTML content and a new page is created with the base name of this filename.
For example, say you have the following directory structure:
reports
├── home.html
├── budget/
│ ├── expenses/
│ │ ├── marketing.md
│ │ └── production.md
│ └── revenue/
│ ├── EMAE.md
│ ├── USA.md
│ └── ASIA.md
└── cashflow/
├── weekly.md
├── monthly.md
└── yearly.md
Calling gui.add_pages('reports')
is equivalent to calling:
gui.add_pages({
"reports/home", Html("reports/home.html"),
"reports/budget/expenses/marketing", Markdown("reports/budget/expenses/marketing.md"),
"reports/budget/expenses/production", Markdown("reports/budget/expenses/production.md"),
"reports/budget/revenue/EMAE", Markdown("reports/budget/revenue/EMAE.md"),
"reports/budget/revenue/USA", Markdown("reports/budget/revenue/USA.md"),
"reports/budget/revenue/ASIA", Markdown("reports/budget/revenue/ASIA.md"),
"reports/cashflow/weekly", Markdown("reports/cashflow/weekly.md"),
"reports/cashflow/monthly", Markdown("reports/cashflow/monthly.md"),
"reports/cashflow/yearly", Markdown("reports/cashflow/yearly.md")
})
add_partial(page)
¶
Create a new Partial
.
The User Manual section on Partials gives details on when and how to use this class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page |
Union[str, Page]
|
The page to create a new Partial from.
|
required |
Returns:
Type | Description |
---|---|
Partial
|
The new |
add_shared_variable(*names)
staticmethod
¶
Add shared variables.
The variables will be synchronized between all clients when updated. Note that only variables from the main module will be registered.
This is a synonym for add_shared_variables()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
str
|
The names of the variables that become shared, as a list argument. |
()
|
add_shared_variables(*names)
staticmethod
¶
Add shared variables.
The variables will be synchronized between all clients when updated. Note that only variables from the main module will be registered.
This is a synonym for add_shared_variable()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
str
|
The names of the variables that become shared, as a list argument. |
()
|
get_flask_app()
¶
Get the internal Flask application.
This method must be called after run()
was invoked.
Returns:
Type | Description |
---|---|
Flask
|
The Flask instance used. |
register_content_provider(content_type, content_provider)
staticmethod
¶
Add a custom content provider.
The application can use custom content for the part
block when its content property is set to an object with type type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content_type |
type
|
The type of the content that triggers the content provider. |
required |
content_provider |
Callable[..., str]
|
The function that converts content of type type into an HTML string. |
required |
reload()
¶
Reload the web server.
This function reloads the underlying web server only in the situation where
it was run in a separated thread: the run_in_thread parameter to the
run
method was set to True, or you are running in an IPython notebook
context.
run(run_server=True, run_in_thread=False, async_mode='gevent', **kwargs)
¶
Start the server that delivers pages to web clients.
Once you enter run()
, users can run web browsers and point to the web server
URL that Gui
serves. The default is to listen to the localhost address
(127.0.0.1) on the port number 5000. However, the configuration of this Gui
object may impact that (see the
Configuration
section of the User Manual for details).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
run_server |
bool
|
Whether or not to run a web server locally. If set to False, a web server is not created and started. |
True
|
run_in_thread |
bool
|
Whether or not to run a web server in a separated thread.
If set to True, the web server runs is a separated thread. |
False
|
async_mode |
str
|
The asynchronous model to use for the Flask-SocketIO.
Valid values are:
The default value is "gevent" |
'gevent'
|
**kwargs |
dict[str, any]
|
Additional keyword arguments that configure how this |
{}
|
Returns:
Type | Description |
---|---|
Optional[Flask]
|
The Flask instance if run_server is False else None. |