Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinAV committed Oct 3, 2024
2 parents d544492 + fbc23d2 commit cd0f701
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Data

# demo files
demo-*
demo_*/
demo_*
.airflow
*.dags
data_sources
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Reporting bugs is through [GitHub issues](https://github.com/Avaiga/taipy/issues
Please report relevant information and preferably code that exhibits the problem. We provide templates to help you
describe the issue.

The Taipy team will analyse and try to reproduce the bug to provide feedback. If confirmed, we will add a priority
The Taipy team will analyze and try to reproduce the bug to provide feedback. If confirmed, we will add a priority
to the issue and add it in our backlog. Feel free to propose a pull request to fix it.

## Issue reporting, feedback, proposal, design or any other comment
Expand All @@ -44,12 +44,12 @@ Do not hesitate to create an issue or pull request directly on the
## Implement Features

The Taipy team manages its backlog in private. Each issue that is or is going to be engaged by the
Taipy team is attached to the "🔒 Staff only" label or has already assigned to a Taipy team member.
Taipy team is attached to the "🔒 Staff only" label or has already been assigned to a Taipy team member.
Please, do not work on it, the Taipy team is on it.

All other issues are sorted by labels and are available for a contribution. If you are new to the
project, you can start with the "good first issue" or "🆘 Help wanted" label. You can also start with
issue with higher priority like "Critical" or "High". The higher the priority, the more value it
issues with higher priority, like "Critical" or "High". The higher the priority, the more value it
will bring to Taipy.

If you want to work on an issue, please add a comment and wait to be assigned to the issue to inform
Expand Down
25 changes: 25 additions & 0 deletions doc/gui/examples/controls/date_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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>
# -----------------------------------------------------------------------------------------
import datetime

from taipy.gui import Gui

date = datetime.datetime(1789, 7, 14, 17, 5, 12)

page = "<|{date}|date|format=eeee LLLL do, y|>"

if __name__ == "__main__":
Gui(page).run(title="Date - Format")
File renamed without changes.
25 changes: 25 additions & 0 deletions doc/gui/examples/controls/date_not_editable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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>
# -----------------------------------------------------------------------------------------
import datetime

from taipy.gui import Gui

date = datetime.datetime(1789, 7, 14, 17, 5, 12)

page = "<|{date}|date|not editable|>"

if __name__ == "__main__":
Gui(page).run(title="Date - Not editable")
25 changes: 25 additions & 0 deletions doc/gui/examples/controls/date_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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>
# -----------------------------------------------------------------------------------------
import datetime

from taipy.gui import Gui

date = datetime.datetime(1789, 7, 14, 17, 5, 12)

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

if __name__ == "__main__":
Gui(page).run(title="Date - Simple")
32 changes: 32 additions & 0 deletions doc/gui/examples/controls/date_styling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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>
# -----------------------------------------------------------------------------------------
import datetime

from taipy.gui import Gui, Markdown

date = datetime.datetime(1989, 7, 14, 17, 5, 12)
color = {"color": "green"}

page = Markdown(
"<|{date}|date|>",
style={
".taipy-date": {".MuiInputBase-root": {"&": color, ".MuiIconButton-root": color}},
".MuiDateCalendar-root": {"&": color, ".MuiPickersDay-root": color},
},
)

if __name__ == "__main__":
Gui(page).run(title="Date - Styling")
25 changes: 25 additions & 0 deletions doc/gui/examples/controls/date_with_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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>
# -----------------------------------------------------------------------------------------
import datetime

from taipy.gui import Gui

date = datetime.datetime(1789, 7, 14, 17, 5, 12)

page = "<|{date}|date|with_time|>"

if __name__ == "__main__":
Gui(page).run(title="Date - With time")
3 changes: 2 additions & 1 deletion taipy/common/config/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
# 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.

"""Exceptions raised by the `taipy.common.config` package functionalities."""
"""# Exceptions raised by the `taipy.common.config` package."""

from .exceptions import *
15 changes: 9 additions & 6 deletions taipy/gui/_renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,29 +428,29 @@ def _get_lov_adapter( # noqa: C901
var_type = self.__gui._get_unique_type_adapter(type(elt).__name__)
if adapter is None:
adapter = self.__gui._get_adapter_for_type(var_type)
elif var_type == str.__name__ and callable(adapter):
elif var_type == str.__name__ and isroutine(adapter):
var_type += (
f"__lambda_{id(adapter)}"
_get_lambda_id(t.cast(LambdaType, adapter))
if adapter.__name__ == "<lambda>"
else _get_expr_var_name(adapter.__name__)
)
if lov_name:
if adapter is None:
adapter = self.__gui._get_adapter_for_type(lov_name)
else:
self.__gui._add_type_for_var(lov_name, var_type)
self.__gui._add_type_for_var(lov_name, t.cast(str, var_type))
if value_name := self.__hashes.get("value"):
if adapter is None:
adapter = self.__gui._get_adapter_for_type(value_name)
else:
self.__gui._add_type_for_var(value_name, var_type)
self.__gui._add_type_for_var(value_name, t.cast(str, var_type))
if adapter is not None:
self.__gui._add_adapter_for_type(var_type, adapter) # type: ignore

if default_lov is not None and lov:
for elt in lov:
ret = self.__gui._run_adapter(
t.cast(t.Callable, adapter), elt, adapter.__name__ if callable(adapter) else "adapter"
t.cast(t.Callable, adapter), elt, adapter.__name__ if isroutine(adapter) else "adapter"
) # type: ignore
if ret is not None:
default_lov.append(ret)
Expand All @@ -460,7 +460,10 @@ def _get_lov_adapter( # noqa: C901
val_list = value if isinstance(value, list) else [value]
for val in val_list:
ret = self.__gui._run_adapter(
t.cast(t.Callable, adapter), val, adapter.__name__ if callable(adapter) else "adapter", id_only=True
t.cast(t.Callable, adapter),
val,
adapter.__name__ if isroutine(adapter) else "adapter",
id_only=True,
) # type: ignore
if ret is not None:
ret_list.append(ret)
Expand Down
17 changes: 11 additions & 6 deletions taipy/gui/builder/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import inspect
import re
import typing as t
import uuid
from abc import ABC, abstractmethod
from collections.abc import Iterable
from types import FrameType, FunctionType

from .._warnings import _warn
from ..utils import _getscopeattr
from ..utils import _get_lambda_id, _getscopeattr
from ._context_manager import _BuilderContextManager
from ._factory import _BuilderFactory
from ._utils import _LambdaByName, _python_builtins, _TransformVarToValue
Expand All @@ -37,10 +36,10 @@ class _Element(ABC):
_ELEMENT_NAME = ""
_DEFAULT_PROPERTY = ""
__RE_INDEXED_PROPERTY = re.compile(r"^(.*?)__([\w\d]+)$")
_NEW_LAMBDA_NAME = "new_lambda"
_TAIPY_EMBEDDED_PREFIX = "_tp_embedded_"
_EMBEDDED_PROPERTIES = ["decimator"]
_TYPES: t.Dict[str, str] = {}
__LAMBDA_VALUE_IDX = 0

def __new__(cls, *args, **kwargs):
obj = super(_Element, cls).__new__(cls)
Expand All @@ -67,6 +66,12 @@ def update(self, **kwargs):
self._properties.update(kwargs)
self.parse_properties()

@staticmethod
def __get_lambda_index():
_Element.__LAMBDA_VALUE_IDX += 1
_Element.__LAMBDA_VALUE_IDX %= 0xFFFFFFF0
return _Element.__LAMBDA_VALUE_IDX

def _evaluate_lambdas(self, gui: Gui):
for k, lmbd in self._lambdas.items():
expr = gui._evaluate_expr(lmbd, lambda_expr=True)
Expand Down Expand Up @@ -100,8 +105,8 @@ def _parse_property(self, key: str, value: t.Any) -> t.Any:
if key.startswith("on_") or self._is_callable(key):
return value if value.__name__.startswith("<") else value.__name__
# Parse lambda function_is_callable
if (lambda_name := self.__parse_lambda_property(key, value)) is not None:
return lambda_name
if (lambda_call := self.__parse_lambda_property(key, value)) is not None:
return lambda_call
# Embed value in the caller frame
if not isinstance(value, str) and key in self._EMBEDDED_PROPERTIES:
return self.__embed_object(value, is_expression=False)
Expand Down Expand Up @@ -131,7 +136,7 @@ def __parse_lambda_property(self, key: str, value: t.Any) -> t.Any:
tree = _TransformVarToValue(self.__calling_frame, args + targets + _python_builtins).visit(lambda_fn)
ast.fix_missing_locations(tree)
lambda_text = ast.unparse(tree)
lambda_name = f"__lambda_{uuid.uuid4().hex}"
lambda_name = _get_lambda_id(value, index=(_Element.__get_lambda_index()))
self._lambdas[lambda_name] = lambda_text
return f'{{{lambda_name}({", ".join(args)})}}'
except Exception as e:
Expand Down
18 changes: 14 additions & 4 deletions taipy/gui/builder/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,28 @@ def __init__(self, element_name: str, lineno: int, lambdas: t.Dict[str, ast.Lamb

def visit_Call(self, node):
if getattr(node.func, "attr", None) == self.element_name:
if self.lambdas.get(_LambdaByName._DEFAULT_NAME, None) is None:
self.lambdas[_LambdaByName._DEFAULT_NAME] = next(
if self.lambdas.get(_LambdaByName._DEFAULT_NAME, None) is None and (
a_lambda := next(
(
arg
for arg in node.args
if isinstance(arg, ast.Lambda) and self.lineno >= arg.lineno and self.lineno <= arg.end_lineno
if isinstance(arg, ast.Lambda)
and arg.lineno is not None
and arg.end_lineno is not None
and self.lineno >= arg.lineno
and self.lineno <= arg.end_lineno
),
None,
)
):
self.lambdas[_LambdaByName._DEFAULT_NAME] = a_lambda

for kwd in node.keywords:
if (
isinstance(kwd.value, ast.Lambda)
kwd.arg is not None
and isinstance(kwd.value, ast.Lambda)
and kwd.value.lineno is not None
and kwd.value.end_lineno is not None
and self.lineno >= kwd.value.lineno
and self.lineno <= kwd.value.end_lineno
):
Expand Down
4 changes: 2 additions & 2 deletions taipy/gui/extension/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def __init__(
*react_component* is ignored.
Arguments:
default_property (str): the name of the default property for this element.
properties (List[ElementProperty]): The list of properties for this element.
default_property (str): The name of the default property for this element.
properties (Dict[str, ElementProperty]): The dictionary containing the properties of this element, where the keys are the property names and the values are instances of ElementProperty.
inner_properties (Optional[List[ElementProperty]]): The optional list of inner properties for this element.<br/>
Default values are set/binded automatically.
react_component (Optional[str]): The name of the component to be created on the front-end.<br/>
Expand Down
Loading

0 comments on commit cd0f701

Please sign in to comment.