Skip to content

Commit

Permalink
Merge branch 'develop' into issue/848
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLL-Avaiga authored Nov 26, 2024
2 parents 7cd9814 + f22e739 commit 9aff560
Show file tree
Hide file tree
Showing 61 changed files with 1,327 additions and 625 deletions.
11 changes: 5 additions & 6 deletions doc/gui/examples/controls/chat_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
# Human-computer dialog UI based on the chat control.
# -----------------------------------------------------------------------------------------
from math import cos, pi, sin, sqrt, tan # noqa: F401
from typing import Optional

from taipy.gui import Gui

# The user interacts with the Python interpreter
users = ["human", "Result"]
messages: list[tuple[str, str, str, Optional[str]]] = []
messages: list[tuple[str, str, str]] = []


def evaluate(state, var_name: str, payload: dict):
# Retrieve the callback parameters
(_, _, expression, sender_id, image_url) = payload.get("args", [])
(_, _, expression, sender_id, _) = payload.get("args", [])
# Add the input content as a sent message
messages.append((f"{len(messages)}", expression, sender_id, image_url))
messages.append((f"{len(messages)}", expression, sender_id))
# Default message used if evaluation fails
result = "Invalid expression"
try:
Expand All @@ -38,12 +37,12 @@ def evaluate(state, var_name: str, payload: dict):
except Exception:
pass
# Add the result as an incoming message
messages.append((f"{len(messages)}", result, users[1], None))
messages.append((f"{len(messages)}", result, users[1]))
state.messages = messages


page = """
<|{messages}|chat|users={users}|sender_id={users[0]}|on_action=evaluate|>
<|{messages}|chat|users={users}|sender_id={users[0]}|on_action=evaluate|don't allow_send_images|>
"""

Gui(page).run(title="Chat - Calculator")
6 changes: 4 additions & 2 deletions doc/gui/examples/controls/chat_discuss.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from taipy.gui.gui_actions import navigate, notify

username = ""
users: list[Union[str, Icon]] = []
users: list[tuple[str, Union[str, Icon]]] = []
messages: list[tuple[str, str, str, Optional[str]]] = []

Gui.add_shared_variables("messages", "users")
Expand Down Expand Up @@ -82,4 +82,6 @@ def send(state, _: str, payload: dict):
"""

pages = {"register": register_page, "discuss": discuss_page}
gui = Gui(pages=pages).run(title="Chat - Discuss")

if __name__ == "__main__":
gui = Gui(pages=pages).run(title="Chat - Discuss")
47 changes: 47 additions & 0 deletions doc/gui/examples/controls/chat_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# -----------------------------------------------------------------------------------------
# To execute this script, make sure that the taipy-gui package is installed in your
# Python environment and run:
# python <script>
# -----------------------------------------------------------------------------------------
# A chatting application based on the chat control.
# In order to see the users' avatars, the image files must be stored next to this script.
# If you want to test this application locally, you need to use several browsers and/or
# incognito windows so a given user's context is not reused.
# -----------------------------------------------------------------------------------------
from taipy.gui import Gui, Icon

msgs = [
["1", "msg 1", "Alice", None],
["2", "msg From Another unknown User", "Charles", None],
["3", "This from the sender User", "taipy", "./beatrix-avatar.png"],
["4", "And from another known one", "Alice", None],
]
users = [
["Alice", Icon("./alice-avatar.png", "Alice avatar")],
["Charles", Icon("./charles-avatar.png", "Charles avatar")],
["taipy", Icon("./beatrix-avatar.png", "Beatrix avatar")],
]


def on_action(state, id: str, payload: dict):
(reason, varName, text, senderId, imageData) = payload.get("args", [])
msgs.append([f"{len(msgs) +1 }", text, senderId, imageData])
state.msgs = msgs


page = """
<|{msgs}|chat|users={users}|allow_send_images|>
"""

if __name__ == "__main__":
Gui(page).run(title="Chat - Images")
17 changes: 8 additions & 9 deletions doc/gui/examples/controls/chat_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
msgs = [
["1", "msg 1", "Alice", None],
["2", "msg From Another unknown User", "Charles", None],
["3", "This from the sender User", "taipy", "./sample.jpeg"],
["3", "This from the sender User", "taipy", None],
["4", "And from another known one", "Alice", None],
]
users = [
Expand All @@ -25,15 +25,12 @@


def on_action(state, var_name: str, payload: dict):
args = payload.get("args", [])
msgs.append([f"{len(msgs) +1 }", args[2], args[3], args[4]])
(reason, varName, text, senderId, imageData) = payload.get("args", [])
msgs.append([f"{len(msgs) +1 }", text, senderId, imageData])
state.msgs = msgs


Gui(
"""
<|toggle|theme|>
# Test Chat
page="""
<|1 1 1|layout|
<|{msgs}|chat|users={users}|show_sender={True}|>
Expand All @@ -42,5 +39,7 @@ def on_action(state, var_name: str, payload: dict):
<|{msgs}|chat|users={users}|show_sender={True}|not with_input|>
|>
""",
).run()
"""

if __name__ == "__main__":
Gui(page).run(title="Chat - Simple")
16 changes: 16 additions & 0 deletions doc/gui/examples/controls/status_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from taipy.gui import Gui

status = [
("warning", "Task is launched."),
("warning", "Tasks is waiting."),
("error", "Task timeout."),
("success", "Task Succeeded"),
("info", "Process was cancelled.")
]

page = """
<|{status}|status|use_icon|>
"""

if __name__ == "__main__":
Gui(page).run(title="Status - With icons")
20 changes: 20 additions & 0 deletions doc/gui/examples/controls/status_mixed_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from taipy.gui import Gui

status = [
("warning", "Task is launched."),
("warning", "Tasks is waiting."),
("error", "Task timeout."),
("success", "Task Succeeded"),
("info", "Process was cancelled.")
]

# Info: svg icon (pants.svg)
# success: no icon
# warning: default icon
# error: inline svg icon (red disc)
page = """
<|{status}|status|don't use_icon|use_icon[info]=https://www.svgrepo.com/show/530594/pants.svg|use_icon[success]|use_icon[error]=<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24'><circle cx='12' cy='12' r='10' fill='red'/></svg>|>
""" # noqa: E501

if __name__ == "__main__":
Gui(page).run(title="Status - With mixed icons")
16 changes: 16 additions & 0 deletions doc/gui/examples/controls/status_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from taipy.gui import Gui

status = [
("warning", "Task is launched."),
("warning", "Tasks is waiting."),
("error", "Task timeout."),
("success", "Task Succeeded"),
("info", "Process was cancelled.")
]

page = """
<|{status}|status|>
"""

if __name__ == "__main__":
Gui(page).run(title="Status - Simple")
20 changes: 20 additions & 0 deletions doc/gui/examples/controls/status_svg_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from taipy.gui import Gui

status = [
("warning", "Task is launched."),
("warning", "Tasks is waiting."),
("error", "Task timeout."),
("success", "Task Succeeded"),
("info", "Process was cancelled.")
]

# Info: svg icon (pants.svg)
# success: svg icon (hotel.svg)
# warning: svg icon (diving-goggles.svg)
# error: svg icon (hat.svg)
page = """
<|{status}|status|use_icon[info]=https://www.svgrepo.com/show/530594/pants.svg|use_icon[success]=https://www.svgrepo.com/show/530595/hotel.svg|use_icon[warning]=https://www.svgrepo.com/show/530596/diving-goggles.svg|use_icon[error]=https://www.svgrepo.com/show/530597/hat.svg|>
"""

if __name__ == "__main__":
Gui(page).run(title="Status - With SVG icons")
10 changes: 10 additions & 0 deletions doc/gui/extension/example_library/example_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def __init__(self) -> None:
# element, exported as GameTable in front-end/src/index.ts
# react_component="GameTable",
),
"visual_label_list": Element(
"lov",
{
"lov": ElementProperty(PropertyType.lov),
"sort": ElementProperty(PropertyType.string),
},
# The name of the React component (VisualLabelList) that implements this custom
# element, exported as LabeledItemList in front-end/src/index.ts
react_component="VisualLabelList",
)
}

# The implementation of the rendering for the "fraction" static element
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useMemo } from "react";
import { LoV, useLovListMemo } from "taipy-gui";

interface VisualLabelListProps {
lov?: LoV;
defaultLov?: string;
sort?: "asc" | "desc";
}

const styles = {
listItem: {
display: "flex",
alignItems: "center",
},
image: {
marginRight: "8px",
width: "1em",
height: "1em",
},
};

const VisualLabelList: React.FC<VisualLabelListProps> = ({ lov, defaultLov = "", sort }) => {
const lovList = useLovListMemo(lov, defaultLov);

const sortedLovList = useMemo(() => {
if (sort) {
return lovList.slice().sort((a, b) => {
return sort === "asc" ? a.id.localeCompare(b.id) : b.id.localeCompare(a.id);
});
}
return lovList;
}, [lovList, sort]);

return (
<div>
<ul>
{sortedLovList.map((item, index) => (
<li key={index} style={styles.listItem}>
{typeof item.item === "string" ? null : (
<img src={item.item.path} alt={item.item.text} style={styles.image} />
)}
{item.id}
</li>
))}
</ul>
</div>
);
};

export default VisualLabelList;
3 changes: 2 additions & 1 deletion doc/gui/extension/example_library/front-end/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
// the name used in the element declaration in the element library.
import ColoredLabel from "./ColoredLabel";
import GameTable from "./GameTable";
import VisualLabelList from "./VisualLabelList";

export { ColoredLabel as ExampleLabel, GameTable };
export { ColoredLabel as ExampleLabel, GameTable, VisualLabelList };
Binary file added doc/gui/extension/images/cpp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/gui/extension/images/java.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/gui/extension/images/javascript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/gui/extension/images/python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/gui/extension/images/typescript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions doc/gui/extension/visual_label_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
from example_library import ExampleLibrary

from taipy.gui import Gui, Icon

languages = [
["Python", Icon("images/python.png", "Python logo")],
["JavaScript", Icon("images/javascript.png", "JavaScript logo")],
["TypeScript", Icon("images/typescript.png", "TypeScript logo")],
["Java", Icon("images/java.png", "Java logo")],
["C++", Icon("images/cpp.png", "C++ logo")],
]

page = """
<|{languages}|example.visual_label_list|sort=asc|>
"""

if __name__ == "__main__":
Gui(page, libraries=[ExampleLibrary()]).run(title="List of item")
2 changes: 1 addition & 1 deletion frontend/taipy-gui/src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const Router = () => {
) : null}
</Box>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<TaipyNotification alerts={state.alerts} />
<TaipyNotification notifications={state.notifications} />
<UIBlocker block={state.block} />
<Navigate
to={state.navigateTo}
Expand Down
10 changes: 3 additions & 7 deletions frontend/taipy-gui/src/components/Taipy/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useTheme } from "@mui/material";
import Box from "@mui/material/Box";
import Skeleton from "@mui/material/Skeleton";
import Tooltip from "@mui/material/Tooltip";
import merge from "lodash/merge";
import { nanoid } from "nanoid";
import {
Config,
Expand Down Expand Up @@ -300,7 +301,7 @@ const Chart = (props: ChartProp) => {
const theme = useTheme();
const module = useModule();

const refresh = useMemo(() => data?.__taipy_refresh !== undefined ? nanoid() : false, [data]);
const refresh = useMemo(() => (data?.__taipy_refresh !== undefined ? nanoid() : false), [data]);
const className = useClassNames(props.libClassName, props.dynamicClassName, props.className);
const active = useDynamicProperty(props.active, props.defaultActive, true);
const render = useDynamicProperty(props.render, props.defaultRender, true);
Expand Down Expand Up @@ -394,12 +395,7 @@ const Chart = (props: ChartProp) => {
layout.template = template;
}
if (props.figure) {
return {
...(props.figure[0].layout as Partial<Layout>),
...layout,
title: title || layout.title || (props.figure[0].layout as Partial<Layout>).title,
clickmode: "event+select",
} as Layout;
return merge({},props.figure[0].layout as Partial<Layout>, layout, {title: title || layout.title || (props.figure[0].layout as Partial<Layout>).title, clickmode: "event+select"});
}
return {
...layout,
Expand Down
Loading

0 comments on commit 9aff560

Please sign in to comment.