Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TGB in GS #773

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/getting_started/hello_world_tgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import taipy as tp
from taipy import Config, Core, Gui
import taipy.gui.builder as tgb


################################################################
# Configure application #
################################################################
def build_message(name):
return f"Hello {name}!"


# A first data node configuration to model an input name.
input_name_data_node_cfg = Config.configure_data_node(id="input_name")
# A second data node configuration to model the message to display.
message_data_node_cfg = Config.configure_data_node(id="message")
# A task configuration to model the build_message function.
build_msg_task_cfg = Config.configure_task("build_msg", build_message, input_name_data_node_cfg, message_data_node_cfg)
# The scenario configuration represents the whole execution graph.
scenario_cfg = Config.configure_scenario("scenario", task_configs=[build_msg_task_cfg])

################################################################
# Design graphical interface #
################################################################

input_name = "Taipy"
message = None


def submit_scenario(state):
state.scenario.input_name.write(state.input_name)
state.scenario.submit()
state.message = scenario.message.read()

with tgb.Page() as page:
tgb.text("Name:")
tgb.input("{input_name}")
FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved
tgb.button("Submit", on_action=submit_scenario)

tgb.text("Message {message}")

if __name__ == "__main__":
################################################################
# Instantiate and run Core service #
################################################################
Core().run()

################################################################
# Manage scenarios and data nodes #
################################################################
scenario = tp.create_scenario(scenario_cfg)

################################################################
# Instantiate and run Gui service #
################################################################

Gui(page).run()

124 changes: 87 additions & 37 deletions docs/getting_started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,62 +116,112 @@ While we've used Taipy's Python APIs to handle our scenario, it usually works se
graphical interface, also created using Taipy, to provide a more user-friendly experience.
Here's a simple GUI set up for our "Hello World" scenario:

```python linenums="1"
import taipy as tp
!!! example "GUI creation"

# Previous configuration of scenario
...
=== "Markdown"

page = """
Name: <|{input_name}|input|>
<|submit|button|on_action=submit_scenario|>
Taipy pages can be defined in multiple ways: Markdown, Html or Python. *page* is the Markdown representation of the page.
FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved

Message: <|{message}|text|>
"""
```python linenums="1"
import taipy as tp

input_name = "Taipy"
message = None
# Previous configuration of scenario
...

page = """
Name: <|{input_name}|input|>
<|submit|button|on_action=submit_scenario|>

def submit_scenario(state):
state.scenario.input_name.write(state.input_name)
state.scenario.submit(wait=True)
state.message = scenario.message.read()
Message: <|{message}|text|>
"""

input_name = "Taipy"
message = None

if __name__ == "__main__":
tp.Core().run()
scenario = tp.create_scenario(scenario_cfg)
tp.Gui(page).run()
```

[Get the whole code](./hello_world.py){: .tp-btn target='blank'}
def submit_scenario(state):
state.scenario.input_name.write(state.input_name)
state.scenario.submit(wait=True)
state.message = scenario.message.read()

Now, let’s explain the key elements of this code:

```python
import taipy as tp
if __name__ == "__main__":
tp.Core().run()
scenario = tp.create_scenario(scenario_cfg)
tp.Gui(page).run()
```

[Get the whole code](./hello_world_md.py){: .tp-btn target='blank'}

Now, let’s explain the key elements of this code:

```python
import taipy as tp


page = """
Name: <|{input_name}|input|>
<|submit|button|on_action=submit_scenario|>
Message: <|{message}|text|>
"""
```

=== "Python"

Taipy pages can be defined in multiple ways: Markdown, Html or Python. *page* is built through the Taipy Gui Builder.
FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved

```python linenums="1"
import taipy as tp
import taipy.gui.builder as tgb

# Previous configuration of scenario
...

with tgb.Page() as page:
tgb.text("Name:")
tgb.input("{input_name}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that, when Avaiga/taipy#635 is merged, that can be written:
tgb.input(input_name)

If I were you, I would give this a shot.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I didn't know about this one. This is impressive

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is for 3.1

tgb.button("Submit", on_action=submit_scenario)
tgb.text("Message {message}")


input_name = "Taipy"
message = None


def submit_scenario(state):
state.scenario.input_name.write(state.input_name)
state.scenario.submit(wait=True)
state.message = scenario.message.read()


if __name__ == "__main__":
tp.Core().run()
scenario = tp.create_scenario(scenario_cfg)
tp.Gui(page).run()
```

[Get the whole code](./hello_world_tgb.py){: .tp-btn target='blank'}

Now, let’s explain the key elements of this code:

```python
import taipy as tp

page = """
Name: <|{input_name}|input|>
<|submit|button|on_action=submit_scenario|>
Message: <|{message}|text|>
"""
```

**Pages**
with tgb.Page() as page:
tgb.text("Name:")
tgb.input("{input_name}")
FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved
tgb.button("Submit", on_action=submit_scenario)
tgb.text("Message {message}")
```

Taipy pages can be defined in multiple ways: Markdown, Html or Python. The *page*
variable is a Markdown representation of the user interface.
It uses standard Markdown syntax as well as visual elements.

**Visual elements**

Taipy offers various visual elements that can interact with your Python variables and
environment. It allows you to display variables, modify them, and interact with the application.

Here is a generic example of one: `<|{variable}|visual_element_type|...|>`. *variable* is
Here is a generic example of one: `<|{variable}|visual_element_type|...|>` with Markdown or `tgb.visual_element_type("{variable}", ...)` with the Python API. *variable* is
FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved
the main property of the visual element and is usually what is displayed or modified through the
visual element.

Expand All @@ -185,7 +235,7 @@ In our initial example:
## Interactivity Through Actions

Actions, like `on_action=submit_scenario`, allow visual elements like buttons to trigger
specific functions, enhancing the interactivity of the application.
specific functions.

```python
def submit_scenario(state):
Expand Down Expand Up @@ -218,7 +268,7 @@ if __name__ == "__main__":
```

The main part of the application starts by setting up the Core service, generating a scenario,
and starting the GUI, which makes the interactive interface active and functional.
and starting the GUI, which makes the interface active and functional.

![GUI Result](result.png){width=50% style="margin:auto;display:block;border: 4px solid rgb(210,210,210);border-radius:7px" }

Expand Down
Loading