diff --git a/src/ansys/fluent/core/services/datamodel_tui.py b/src/ansys/fluent/core/services/datamodel_tui.py index 82a031b89cd..123f47f2665 100644 --- a/src/ansys/fluent/core/services/datamodel_tui.py +++ b/src/ansys/fluent/core/services/datamodel_tui.py @@ -256,31 +256,26 @@ def __dir__(self) -> Iterable[str]: ] def __getattribute__(self, name): - attr = super().__getattribute__(name) - if type(attr) == types.MethodType: - path = self.path + [name] - # if menus are inserted at runtime in Fluent - if PyMenu(self.service, path).get_child_names(): - return TUIMenuGeneric(path, self.service) - return attr - - -class TUIMenuGeneric(TUIMenu): - """Generic menu class for when the explicit menu classes aren't - available.""" - - def __getattribute__(self, name): - if name in ["path", "service"]: - return super().__getattribute__(name) - name = convert_func_name_to_tui_menu(name) - path = self.path + [name] - if PyMenu(self.service, path).get_child_names(): - return TUIMenuGeneric(path, self.service) - else: - return TUICommandGeneric(path, self.service) - + try: + attr = super().__getattribute__(name) + if type(attr) == types.MethodType: + # some runtime submenus are generated as methods during codegen + path = self.path + [name] + if PyMenu(self.service, path).get_child_names(): + return TUIMenu(path, self.service) + return attr + except AttributeError as ex: + if name in dir(self): + # for runtime submenus and commands which are not available during codegen + path = self.path + [name] + if PyMenu(self.service, path).get_child_names(): + return TUIMenu(path, self.service) + else: + return TUICommand(path, self.service) + else: + raise ex -class TUICommandGeneric(TUIMenu): +class TUICommand(TUIMenu): """Generic command class for when the explicit menu classes aren't available.""" diff --git a/src/ansys/fluent/core/session.py b/src/ansys/fluent/core/session.py index f6ccb40d570..91c5dd97a4e 100644 --- a/src/ansys/fluent/core/session.py +++ b/src/ansys/fluent/core/session.py @@ -9,7 +9,7 @@ import grpc from ansys.fluent.core.fluent_connection import _FluentConnection -from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric +from ansys.fluent.core.services.datamodel_tui import TUIMenu from ansys.fluent.core.session_base_meshing import _BaseMeshing from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI from ansys.fluent.core.solver.flobject import get_root as settings_get_root @@ -329,7 +329,7 @@ def tui(self): self._tui = tui_module.main_menu([], self._tui_service) except (ImportError, ModuleNotFoundError): LOG.warning(_CODEGEN_MSG_TUI) - self._tui = TUIMenuGeneric([], self._tui_service) + self._tui = TUIMenu([], self._tui_service) return self._tui @property diff --git a/src/ansys/fluent/core/session_base_meshing.py b/src/ansys/fluent/core/session_base_meshing.py index 0b49cf68757..1892e64cc84 100644 --- a/src/ansys/fluent/core/session_base_meshing.py +++ b/src/ansys/fluent/core/session_base_meshing.py @@ -3,7 +3,7 @@ from ansys.fluent.core.fluent_connection import _FluentConnection from ansys.fluent.core.meshing.meshing import Meshing from ansys.fluent.core.services.datamodel_se import PyMenuGeneric -from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric +from ansys.fluent.core.services.datamodel_tui import TUIMenu from ansys.fluent.core.session_shared import _CODEGEN_MSG_DATAMODEL, _CODEGEN_MSG_TUI from ansys.fluent.core.utils.fluent_version import get_version_for_filepath from ansys.fluent.core.utils.logging import LOG @@ -46,7 +46,7 @@ def tui(self): self._tui = tui_module.main_menu([], self._tui_service) except (ImportError, ModuleNotFoundError): LOG.warning(_CODEGEN_MSG_TUI) - self._tui = TUIMenuGeneric([], self._tui_service) + self._tui = TUIMenu([], self._tui_service) return self._tui @property diff --git a/src/ansys/fluent/core/session_solver.py b/src/ansys/fluent/core/session_solver.py index ff900a5edbd..1367df6e391 100644 --- a/src/ansys/fluent/core/session_solver.py +++ b/src/ansys/fluent/core/session_solver.py @@ -3,7 +3,7 @@ import importlib from ansys.fluent.core.services.datamodel_se import PyMenuGeneric -from ansys.fluent.core.services.datamodel_tui import TUIMenuGeneric +from ansys.fluent.core.services.datamodel_tui import TUIMenu from ansys.fluent.core.session import ( _CODEGEN_MSG_TUI, _BaseSession, @@ -54,7 +54,7 @@ def tui(self): self._tui = tui_module.main_menu([], self._tui_service) except ImportError: LOG.warning(_CODEGEN_MSG_TUI) - self._tui = TUIMenuGeneric([], self._tui_service) + self._tui = TUIMenu([], self._tui_service) return self._tui @property diff --git a/tests/test_tui_api.py b/tests/test_tui_api.py index 93553aa29d1..2268d6f7e00 100644 --- a/tests/test_tui_api.py +++ b/tests/test_tui_api.py @@ -1,6 +1,8 @@ import pytest from util.solver_workflow import new_solver_session # noqa: F401 +from ansys.fluent.core.services.datamodel_tui import TUIMenu + @pytest.mark.skip("randomly failing due to missing transcript capture") def test_report_system_proc_stats_tui(new_solver_session, capsys) -> None: @@ -10,3 +12,10 @@ def test_report_system_proc_stats_tui(new_solver_session, capsys) -> None: new_solver_session.solver.tui.report.system.sys_stats() captured = capsys.readouterr() assert "CPU" in captured.out + +def test_runtime_tui_menus(load_static_mixer_case) -> None: + solver = load_static_mixer_case + solver.tui.define.models.addon_module(3) + rmf = solver.tui.define.models.resolved_MEA_fuelcells + assert rmf is not None + assert rmf.__class__ == TUIMenu \ No newline at end of file