Skip to content

Commit

Permalink
Merge branch 'develop' into bug/#2278-tree-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLL-Avaiga authored Nov 25, 2024
2 parents e141eed + 4ffb798 commit 19a9d5c
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 310 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")
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
Loading

0 comments on commit 19a9d5c

Please sign in to comment.