Skip to content

Commit

Permalink
Merge branch 'develop' into feature/Avaiga#1248-cover-json-data-node-…
Browse files Browse the repository at this point in the history
…control-new
  • Loading branch information
FredLL-Avaiga authored Nov 8, 2024
2 parents 5a070a7 + ba3d2b7 commit 48463fe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,52 @@
</a>
</div>

<br>
<div align="center">
<img
src="https://img.shields.io/github/license/Avaiga/taipy?style=plastic&color=ff371a&labelColor=1f1f1f"
alt="GitHub License"
height="20px"
/>
<a target="_blank" href="https://github.com/Avaiga/taipy/releases">
<img
alt="GitHub Release"
height="20px"
src="https://img.shields.io/github/v/release/Avaiga/taipy?display_name=release&style=plastic&color=ff371a&labelColor=1f1f1f"
></a>
</div>
<br>
<div align="center">
<img
src="https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-ff371a?style=plastic&labelColor=1f1f1f"
alt="Python version needed: 3.9"
/>

</div>
<br>

<div align="center">
<a target="_blank" href="https://docs.taipy.io/en/latest/">
<img
src="https://img.shields.io/badge/docs-ff371a?style=plastic&labelColor=1f1f1f&label=Explore"
height="20px"
alt="Explore the docs"
></a>
<a target="_blank" href="https://docs.taipy.io/en/latest/gallery/">
<img
src="https://img.shields.io/badge/gallery-ff371a?style=plastic&labelColor=1f1f1f&label=Explore"
height="20px"
alt="Explore Gallery"
></a>
<a target="_blank" href="https://discord.com/invite/SJyz2VJGxV">
<img
src="https://img.shields.io/discord/1125797687476887563?style=plastic&labelColor=1f1f1f&logo=discord&logoColor=ff371a&label=Discord&color=ff371a"
height="20px"
alt="Discord support"
></a>
</div>
<br>

<h1 align="center">
Build Python Data & AI web applications
</h1>
Expand Down
17 changes: 9 additions & 8 deletions taipy/gui/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import inspect
import typing as t
from abc import abstractmethod
from abc import ABCMeta, abstractmethod
from contextlib import nullcontext
from operator import attrgetter
from pathlib import Path
Expand All @@ -26,7 +26,7 @@
from .gui import Gui


class State(SimpleNamespace):
class State(SimpleNamespace, metaclass=ABCMeta):
"""Accessor to the bound variables from callbacks.
`State` is used when you need to access the value of variables
Expand Down Expand Up @@ -114,9 +114,7 @@ def refresh(self, name: str):
val = attrgetter(name)(self)
_attrsetter(self, name, val)

def _set_context(self, gui: "Gui") -> t.ContextManager[None]:
return nullcontext()

@abstractmethod
def broadcast(self, name: str, value: t.Any):
"""Update a variable on all clients.
Expand All @@ -127,9 +125,7 @@ def broadcast(self, name: str, value: t.Any):
name (str): The variable name to update.
value (Any): The new variable value.
"""
with self._set_context(self._gui):
encoded_name = self._gui._bind_var(name)
self._gui._broadcast_all_clients(encoded_name, value)
raise NotImplementedError

def __enter__(self):
self._gui.__enter__()
Expand Down Expand Up @@ -196,6 +192,11 @@ def __filter_var_list(var_list: t.Iterable[str], excluded_attrs: t.Iterable[str]
def get_gui(self) -> "Gui":
return super().__getattribute__(_GuiState.__gui_attr)

def broadcast(self, name: str, value: t.Any):
with self._set_context(self._gui):
encoded_name = self._gui._bind_var(name)
self._gui._broadcast_all_clients(encoded_name, value)

def __getattribute__(self, name: str) -> t.Any:
if name == "__class__":
return _GuiState
Expand Down
16 changes: 16 additions & 0 deletions taipy/gui/state_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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 .state import State


class StateSupport(State):
pass

0 comments on commit 48463fe

Please sign in to comment.