|
@@ -187,7 +187,7 @@ class Gui:
|
|
|
env_filename: t.Optional[str] = None,
|
|
|
libraries: t.Optional[t.List[ElementLibrary]] = None,
|
|
|
flask: t.Optional[Flask] = None,
|
|
|
- script_paths: t.Optional[t.Union[str, Path, t.List[t.Union[str, Path]]]] = None
|
|
|
+ script_paths: t.Optional[t.Union[str, Path, t.List[t.Union[str, Path]]]] = None,
|
|
|
):
|
|
|
"""Initialize a new Gui instance.
|
|
|
|
|
@@ -434,8 +434,12 @@ class Gui:
|
|
|
continue
|
|
|
script_path = Path(script_path)
|
|
|
|
|
|
- if isinstance(script_path,
|
|
|
- Path) and script_path.exists() and script_path.is_file() and script_path.suffix == ".js":
|
|
|
+ if (
|
|
|
+ isinstance(script_path, Path)
|
|
|
+ and script_path.exists()
|
|
|
+ and script_path.is_file()
|
|
|
+ and script_path.suffix == ".js"
|
|
|
+ ):
|
|
|
self.__script_files.append(str(script_path))
|
|
|
else:
|
|
|
_warn(f"Script path '{script_path}' does not exist, is not a file, or is not a JavaScript file.")
|
|
@@ -506,6 +510,7 @@ class Gui:
|
|
|
from plotly.graph_objs import Figure as PlotlyFigure # type: ignore[reportMissingImports]
|
|
|
|
|
|
if isinstance(content, PlotlyFigure):
|
|
|
+
|
|
|
def get_plotly_content(figure: PlotlyFigure):
|
|
|
return figure.to_html()
|
|
|
|
|
@@ -517,6 +522,7 @@ class Gui:
|
|
|
from matplotlib.figure import Figure as MatplotlibFigure
|
|
|
|
|
|
if isinstance(content, MatplotlibFigure):
|
|
|
+
|
|
|
def get_matplotlib_content(figure: MatplotlibFigure):
|
|
|
import base64
|
|
|
from io import BytesIO
|
|
@@ -830,12 +836,12 @@ class Gui:
|
|
|
if var_name.startswith(_TaipyBase._HOLDER_PREFIX):
|
|
|
for hp in _TaipyBase._get_holder_prefixes():
|
|
|
if var_name.startswith(hp):
|
|
|
- var_name = var_name[len(hp):]
|
|
|
+ var_name = var_name[len(hp) :]
|
|
|
break
|
|
|
suffix_var_name = ""
|
|
|
if "." in var_name:
|
|
|
first_dot_index = var_name.index(".")
|
|
|
- suffix_var_name = var_name[first_dot_index + 1:]
|
|
|
+ suffix_var_name = var_name[first_dot_index + 1 :]
|
|
|
var_name = var_name[:first_dot_index]
|
|
|
var_name_decode, module_name = _variable_decode(self._get_expr_from_hash(var_name))
|
|
|
current_context = self._get_locals_context()
|
|
@@ -1232,7 +1238,8 @@ class Gui:
|
|
|
if ret_payload:
|
|
|
break
|
|
|
except Exception as e: # pragma: no cover
|
|
|
- _warn(f"Exception raised in '{lib_name}.get_data({lib_name}, payload, {user_var_name}, value)'", # noqa: E501
|
|
|
+ _warn(
|
|
|
+ f"Exception raised in '{lib_name}.get_data({lib_name}, payload, {user_var_name}, value)'", # noqa: E501
|
|
|
e,
|
|
|
)
|
|
|
if not isinstance(ret_payload, dict):
|
|
@@ -1306,9 +1313,9 @@ class Gui:
|
|
|
k: v
|
|
|
for k, v in vars(self._get_data_scope()).items()
|
|
|
if not k.startswith("_")
|
|
|
- and not callable(v)
|
|
|
- and "TpExPr" not in k
|
|
|
- and not isinstance(v, (ModuleType, FunctionType, LambdaType, type, Page))
|
|
|
+ and not callable(v)
|
|
|
+ and "TpExPr" not in k
|
|
|
+ and not isinstance(v, (ModuleType, FunctionType, LambdaType, type, Page))
|
|
|
}
|
|
|
function_data = {
|
|
|
k: v
|
|
@@ -1970,6 +1977,12 @@ class Gui:
|
|
|
self.__add_pages_in_folder(child_dir_name, child_dir_path)
|
|
|
|
|
|
# Proxy methods for LocalsContext
|
|
|
+ def _get_locals_context_obj(self) -> _LocalsContext:
|
|
|
+ return self.__locals_context
|
|
|
+
|
|
|
+ def _get_variable_directory_obj(self) -> _VariableDirectory:
|
|
|
+ return self.__var_dir
|
|
|
+
|
|
|
def _get_locals_bind(self) -> t.Dict[str, t.Any]:
|
|
|
return self.__locals_context.get_locals()
|
|
|
|
|
@@ -2055,7 +2068,7 @@ class Gui:
|
|
|
raise Exception("name is required for add_page() function.")
|
|
|
if not Gui.__RE_PAGE_NAME.match(name): # pragma: no cover
|
|
|
raise SyntaxError(
|
|
|
- f'Page name "{name}" is invalid. It must only contain letters, digits, dash (-), underscore (_), and forward slash (/) characters.' # noqa: E501
|
|
|
+ f'Page name "{name}" is invalid. It must only contain letters, digits, dash (-), underscore (_), and forward slash (/) characters.' # noqa: E501
|
|
|
)
|
|
|
if name.startswith("/"): # pragma: no cover
|
|
|
raise SyntaxError(f'Page name "{name}" cannot start with forward slash (/) character.')
|
|
@@ -2254,7 +2267,7 @@ class Gui:
|
|
|
self._bind(encoded_var_name, bind_locals[var_name])
|
|
|
else:
|
|
|
_warn(
|
|
|
- f"Variable '{var_name}' is not available in either the '{self._get_locals_context()}' or '__main__' modules." # noqa: E501
|
|
|
+ f"Variable '{var_name}' is not available in either the '{self._get_locals_context()}' or '__main__' modules." # noqa: E501
|
|
|
)
|
|
|
return encoded_var_name
|
|
|
|
|
@@ -2623,7 +2636,7 @@ class Gui:
|
|
|
_warn(f"Using webapp_path: '{_conf_webapp_path}'.")
|
|
|
else: # pragma: no cover
|
|
|
_warn(
|
|
|
- f"webapp_path: '{_conf_webapp_path}' is not a valid directory. Falling back to '{_webapp_path}'." # noqa: E501
|
|
|
+ f"webapp_path: '{_conf_webapp_path}' is not a valid directory. Falling back to '{_webapp_path}'." # noqa: E501
|
|
|
)
|
|
|
return _webapp_path
|
|
|
|
|
@@ -2938,7 +2951,7 @@ class Gui:
|
|
|
glob_ctx[lib_context[0]] = lib_context[1]
|
|
|
elif lib_context:
|
|
|
_warn(
|
|
|
- f"Method {name}.on_init() should return a Tuple[str, Any] where the first element must be a valid Python identifier." # noqa: E501
|
|
|
+ f"Method {name}.on_init() should return a Tuple[str, Any] where the first element must be a valid Python identifier." # noqa: E501
|
|
|
)
|
|
|
except Exception as e: # pragma: no cover
|
|
|
if not self._call_on_exception(f"{name}.on_init", e):
|