Skip to content

Commit

Permalink
Fred comments:
Browse files Browse the repository at this point in the history
  - Added note on Lambdas as property values
  - Enumerated classes as candidates for *lov*
  • Loading branch information
FabienLelaquais committed Oct 2, 2024
1 parent 2af9e32 commit 414183f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/release-notes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This is the list of changes to Taipy releases as they were published.
class or via the `Page.set_style()^` method.<br/>
See the [section on Styling](../userman/gui/styling/index.md#style-sheets) for more
information.
- *List-of-values* can now be built directly from enumeration classes.<br/>
See [the section on LoVs](../userman/gui/binding.md#list-of-values) for more information.

<h4><strong><code>taipy-core</code></strong> 4.0.0 </h4>

Expand Down Expand Up @@ -93,6 +95,11 @@ This is the list of changes to Taipy releases as they were published.
GUI applications.<br/>
See [issue #1597](https://github.com/Avaiga/taipy/issues/1597) for more details and the
[section on Styling](../userman/gui/styling/index.md#style-sheets).
- The *style* and *style[column_name]* properties of the
[`table`](../refmans/gui/viselements/generic/table.md) control have been
renamed to [*row_class_name*](../refmans/gui/viselements/generic/table.md#p-row_class_name) and
[*cell_class_name[column_name]*](../refmans/gui/viselements/generic/table.md#p-cell_class_name[column_name]),
respectively. A warning message is issued if you use these properties.
- Most visual elements now implement the *width* property, simplifying page layout.<br/>
See [issue #1720](https://github.com/Avaiga/taipy/issues/1720).
- The [`input`](../refmans/gui/viselements/generic/input.md) control has a new
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/articles/chatbot/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def style_conv(state: State, idx: int, row: int) -> str:
We then apply this function to the table by adding the `style` property

```python
<|{conversation}|table|show_all|style=style_conv|>
<|{conversation}|table|show_all|row_class_name=style_conv|>
```

And voilà:
Expand Down
56 changes: 56 additions & 0 deletions docs/userman/gui/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ Each item in a *list of values* can hold:
- A label: a string that is used when displaying the specific item;
- An image: an optional `Icon^` that can be used to display the item as a small
image. Note that icons can also hold a descriptive string.
- A member of an enumeration class.

A *LoV* can have different types, depending on the use case:

Expand Down Expand Up @@ -353,6 +354,61 @@ A *LoV* can have different types, depending on the use case:

The Python type of such a *lov* is: List[Tuple[str, `Icon^`]].

- An enumeration class (i.e. a class that inherits from `Enum`).<br/>
An enumeration class can be used to define a set of predefined values for a control. You can
assign the *lov* (List of Values) property of the control to the enumerated class you want to
use.

For example, consider the following enumeration class definition:
```python
class Color(Enum):
RED = 0
GREEN = 1
BLUE = 2

color = Color.RED
```
In the code above, we also define and initialize the *color* variable, which can then be bound
to a control’s main value. You can directly use this class as the *lov* value in your
control.<br/>

You can directly use this class as a LoV value in you control.<br/>
Here is how you can use the *Color* enumeration class in a
[`toggle`](../../refmans/gui/viselements/generic/toggle.md) control:
!!! example "Enum as LoV"

=== "Markdown"

```
<|{color}|toggle|lov={Color}|>
```

=== "HTML"

```html
<taipy:toggle lov="{Color}">{color}</taipy:toggle>
```

=== "Python"

```python
import taipy.gui.builder as tgb
...
tgb.toggle("{color}", lov="{Color}")
```

When this control is used in a page, the *color* variable will be updated to reflect the
selected value from the Color enumeration.

!!! note "Page Builder API"
If you are working with the Page Builder API, you can assign the enumeration class directly
to the *lov* property:
```python
tgb.toggle("{color}", lov=Color)
```
In this case, the *color* variable will hold the enumeration member value (e.g., 0, 1, 2)
instead of the enumeration member itself (e.g., `Color.RED`).

The "selected" value in controls that use *LoV*s are handled in their *value*
property. This will be the original value of the selection in the *LoV* unless
your control has set the property *value_by_id* to True, then the selected value
Expand Down
23 changes: 23 additions & 0 deletions docs/userman/gui/pages/builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ Compared to the previous example, you can see that the label uses a bold font we

The Page Builder API does support index values that are not Python identifiers or literals.

!!! note "Lambdas as property values"
Using a lambda function as a property value simplifies the creation of dynamic user interfaces
where elements change based on run-time information. This approach is particularly useful when
you need to build loops or handle varying data.

For example, consider the following dictionary:
```python
ages = {
"Albert": 58,
"Beatrix": 71,
"Cecilia": 23
}
```
We want to generate a series of text elements displaying the name and age of each person in the
list. A lambda function makes this straightforward:<br/>
```python
for name in ages:
tgb.text(lambda ages: f"{name} is {ages.get(name)}")
```
In this example, the lambda function accesses the *ages* dictionary from the state. The function
dynamically creates text elements based on local variables, such as *name*, allowing to create
the expected content.

# Binding variables

You can bind your application variables to a property value by setting the property to a string
Expand Down

0 comments on commit 414183f

Please sign in to comment.