Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Hide TaipyGuiWarning
Browse files Browse the repository at this point in the history
+ A few doc improvements
+ linters on examples
  • Loading branch information
FabienLelaquais authored Oct 12, 2023
1 parent 1652bd1 commit 6f94aa9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
27 changes: 15 additions & 12 deletions doc/extension/example_library/example_library.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@

from taipy.gui.extension import ElementLibrary, Element, ElementProperty, PropertyType

class ExampleLibrary(ElementLibrary):

class ExampleLibrary(ElementLibrary):
def __init__(self) -> None:
# Initialize the set of visual elements for this extension library
self.elements = {
# A static element that displays its properties in a fraction
"fraction": Element("numerator", {
"numerator": ElementProperty(PropertyType.number),
"denominator": ElementProperty(PropertyType.number)
"fraction": Element(
"numerator",
{
"numerator": ElementProperty(PropertyType.number),
"denominator": ElementProperty(PropertyType.number),
},
render_xhtml=ExampleLibrary._fraction_render),
render_xhtml=ExampleLibrary._fraction_render,
),
# A dynamic element that decorates its value
"label": Element("value", {
"value": ElementProperty(PropertyType.dynamic_string)
},
"label": Element(
"value",
{"value": ElementProperty(PropertyType.dynamic_string)},
# The name of the React component (ColoredLabel) that implements this custom
# element, exported as ExampleLabel in front-end/src/index.ts
react_component="ExampleLabel")
}
react_component="ExampleLabel",
),
}

# The implementation of the rendering for the "fraction" static element
@staticmethod
Expand All @@ -32,7 +35,7 @@ def _fraction_render(props: dict) -> str:
return f"<span>{numerator}</span>"
# Denominator is zero: display infinity
if int(denominator) == 0:
return "<span style=\"font-size: 1.6em\">&#8734;</span>"
return '<span style="font-size: 1.6em">&#8734;</span>'
# 'Normal' case
return f"<span><sup>{numerator}</sup>/<sub>{denominator}</sub></span>"

Expand Down
18 changes: 10 additions & 8 deletions doc/extension/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Initial value
label = "Here is some text"

page = """
page = """
# Custom elements example
## Fraction:
Expand All @@ -25,13 +25,15 @@
<|Remove a character|button|id=removeChar|>
"""


def on_action(state, id):
if id == "addChar":
# Add a random character to the end of 'label'
state.label += random.choice(string.ascii_letters)
elif id == "removeChar":
# Remove the first character of 'label'
if len(state.label) > 0:
state.label = state.label[1:]
if id == "addChar":
# Add a random character to the end of 'label'
state.label += random.choice(string.ascii_letters)
elif id == "removeChar":
# Remove the first character of 'label'
if len(state.label) > 0:
state.label = state.label[1:]


Gui(page, libraries=[ExampleLibrary()]).run(debug=True)
5 changes: 5 additions & 0 deletions src/taipy/gui/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@


class TaipyGuiWarning(UserWarning):
"""NOT DOCUMENTED
Warning category for Taipy warnings generated in user code.
"""

_tp_debug_mode = False

@staticmethod
Expand Down
9 changes: 4 additions & 5 deletions src/taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class Gui:
"""Entry point for the Graphical User Interface generation.
Attributes:
on_action (Callable): The function that is called when a control
triggers an action, as the result of an interaction with the end-user.<br/>
It defaults to the `on_action()` global function defined in the Python
Expand Down Expand Up @@ -393,7 +392,7 @@ def add_shared_variable(*names: str) -> None:
The variables will be synchronized between all clients when updated.
Note that only variables from the main module will be registered.
This is a synonym for `Gui.add_shared_variables()^`.
This is a synonym for `(Gui.)add_shared_variables()^`.
Arguments:
names: The names of the variables that become shared, as a list argument.
Expand All @@ -409,7 +408,7 @@ def add_shared_variables(*names: str) -> None:
The variables will be synchronized between all clients when updated.
Note that only variables from the main module will be registered.
This is a synonym for `Gui.add_shared_variable()^`.
This is a synonym for `(Gui.)add_shared_variable()^`.
Arguments:
names: The names of the variables that become shared, as a list argument.
Expand Down Expand Up @@ -1818,7 +1817,7 @@ def _register_data_accessor(self, data_accessor_class: t.Type[_DataAccessor]) ->
def get_flask_app(self) -> Flask:
"""Get the internal Flask application.
This method must be called **after** (Gui.)run^ method was invoked.
This method must be called **after** `(Gui.)run()^` was invoked.
Returns:
The Flask instance used.
Expand Down Expand Up @@ -2189,7 +2188,7 @@ def stop(self):
This function stops the underlying web server only in the situation where
it was run in a separated thread: the *run_in_thread* parameter to the
`(Gui.)run^` method was set to True, or you are running in an IPython notebook
`(Gui.)run()^` method was set to True, or you are running in an IPython notebook
context.
"""
if hasattr(self, "_server") and hasattr(self._server, "_thread") and self._server._is_running:
Expand Down
4 changes: 2 additions & 2 deletions src/taipy/gui/gui_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ def get_context_id(state: State) -> t.Any:
def get_module_name_from_state(state: State) -> t.Optional[str]:
"""Get the module name that triggered a callback.
Pages can be defined in different modules yet share callbacks declared elsewhere (typically, the
application's main module).
Pages can be defined in different modules yet refer to callback functions declared elsewhere
(typically, the application's main module).
This function returns the name of the module where the page that holds the control that
triggered the callback was declared. This lets applications implement different behaviors
Expand Down

0 comments on commit 6f94aa9

Please sign in to comment.