diff --git a/examples/toolkit/pyaedt_toolkit/backend/run_backend.py b/examples/toolkit/pyaedt_toolkit/backend/run_backend.py index d65c75ce..1509eca9 100644 --- a/examples/toolkit/pyaedt_toolkit/backend/run_backend.py +++ b/examples/toolkit/pyaedt_toolkit/backend/run_backend.py @@ -2,7 +2,10 @@ from ansys.aedt.toolkits.common.backend.rest_api import app from ansys.aedt.toolkits.common.backend.rest_api import jsonify from ansys.aedt.toolkits.common.backend.rest_api import logger -from ansys.aedt.toolkits.common.backend.rest_api import toolkit_api + +from api import ToolkitBackend + +toolkit_api = ToolkitBackend() @app.route("/create_geometry", methods=["POST"]) diff --git a/examples/toolkit/pyaedt_toolkit/ui/run_frontend.py b/examples/toolkit/pyaedt_toolkit/ui/run_frontend.py index 24898e2d..60657f2e 100644 --- a/examples/toolkit/pyaedt_toolkit/ui/run_frontend.py +++ b/examples/toolkit/pyaedt_toolkit/ui/run_frontend.py @@ -70,6 +70,7 @@ def __init__(self): logger.error(msg) self.settings_menu.signal_flag = False self.settings_menu.aedt_version.addItem("Backend OFF") + self.settings_menu.aedt_session.addItem("Backend OFF") else: # Get default properties be_properties = self.get_properties() @@ -115,8 +116,9 @@ def geometry_menu_clicked(self): # is_left_visible = self.ui.is_left_column_visible() # current_page = self.ui.load_pages.pages.currentIndex() self.ui.set_page(self.geometry_menu.geometry_menu_widget) - - self.ui.toggle_left_column() + is_left_visible = self.ui.is_left_column_visible() + if not is_left_visible: + self.ui.toggle_left_column() self.ui.set_left_column_menu( menu=self.ui.left_column.menus.menu_home, diff --git a/examples/toolkit/pyaedt_toolkit/ui/windows/create_geometry/geometry_menu.py b/examples/toolkit/pyaedt_toolkit/ui/windows/create_geometry/geometry_menu.py index 8cd9d67d..bb882aa8 100644 --- a/examples/toolkit/pyaedt_toolkit/ui/windows/create_geometry/geometry_menu.py +++ b/examples/toolkit/pyaedt_toolkit/ui/windows/create_geometry/geometry_menu.py @@ -20,9 +20,7 @@ def __init__(self, app, selected_project, selected_design, geometry, multiplier) def run(self): self.app.ui.progress.progress = 50 - import time - time.sleep(1) success = self.app.create_geometry_toolkit( self.selected_project, self.selected_design, self.geometry, self.multiplier ) @@ -141,8 +139,8 @@ def geometry_button_clicked(self): self.ui.logger.log(msg) return False - if self.app.backend_busy(): - msg = "toolkit running" + if self.geometry_thread and self.geometry_thread.isRunning() or self.app.backend_busy(): + msg = "Toolkit running" self.ui.logger.log(msg) self.app.logger.debug(msg) return False diff --git a/pyproject.toml b/pyproject.toml index a8f07d4d..1215f270 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ tests = [ "flask", ] doc = [ + "pyaedt[all]", "ansys-sphinx-theme==0.14.0", "numpydoc==1.6.0", "recommonmark==0.7.1", diff --git a/src/ansys/aedt/toolkits/common/backend/api.py b/src/ansys/aedt/toolkits/common/backend/api.py index 6f1b2551..1e334325 100644 --- a/src/ansys/aedt/toolkits/common/backend/api.py +++ b/src/ansys/aedt/toolkits/common/backend/api.py @@ -218,10 +218,20 @@ def installed_aedt_version() -> List: # Detect existing AEDT installation installed_versions = [] + for ver in list_installed_ansysem(): - installed_versions.append( - "20{}.{}".format(ver.replace("ANSYSEM_ROOT", "")[:2], ver.replace("ANSYSEM_ROOT", "")[-1]) - ) + if "ANSYSEMSV_ROOT" in ver: + # Handle the special case + installed_versions.append( + "20{}.{} STUDENT".format( + ver.replace("ANSYSEMSV_ROOT", "")[:2], ver.replace("ANSYSEMSV_ROOT", "")[-1] + ) + ) + else: + installed_versions.append( + "20{}.{}".format(ver.replace("ANSYSEM_ROOT", "")[:2], ver.replace("ANSYSEM_ROOT", "")[-1]) + ) + logger.debug(str(installed_versions)) return installed_versions @@ -356,9 +366,13 @@ def launch_aedt(self) -> bool: logger.debug("Launching AEDT.") pyaedt.settings.use_grpc_api = self.properties.use_grpc pyaedt.settings.enable_logger = self.properties.debug + + version, is_student = self.__get_aedt_version() + desktop_args = { - "specified_version": self.properties.aedt_version, + "specified_version": version, "non_graphical": self.properties.non_graphical, + "student_version": is_student, } # AEDT with COM @@ -428,9 +442,12 @@ def connect_aedt(self) -> bool: pyaedt.settings.enable_logger = self.properties.debug logger.debug("Connecting AEDT.") + version, is_student = self.__get_aedt_version() + desktop_args = { - "specified_version": self.properties.aedt_version, + "specified_version": version, "non_graphical": self.properties.non_graphical, + "student_version": is_student, "new_desktop_session": False, } if self.properties.use_grpc: @@ -524,13 +541,17 @@ def connect_design(self, app_name: Optional[str] = None): active_design = design_name if not self.aedtapp and aedt_app: + + version, is_student = self.__get_aedt_version() + aedt_app_args = { - "specified_version": self.properties.aedt_version, + "specified_version": version, "port": self.properties.selected_process, "non_graphical": self.properties.non_graphical, "new_desktop_session": False, "projectname": project_name, "designname": active_design, + "student_version": is_student, } if self.properties.use_grpc: aedt_app_args["port"] = self.properties.selected_process @@ -734,6 +755,17 @@ def get_design_names(self) -> List[str]: return design_list + def __get_aedt_version(self): + """Get AEDT version and if student version is used.""" + if "STUDENT" in self.properties.aedt_version: + version_text = self.properties.aedt_version.split(" ") + version = version_text[0] + is_student = True + else: + version = self.properties.aedt_version + is_student = False + return version, is_student + def __save_project_info(self): """Save project and design info.""" # Save project and design info diff --git a/src/ansys/aedt/toolkits/common/backend/rest_api.py b/src/ansys/aedt/toolkits/common/backend/rest_api.py index fc7f9b5f..22479bd5 100644 --- a/src/ansys/aedt/toolkits/common/backend/rest_api.py +++ b/src/ansys/aedt/toolkits/common/backend/rest_api.py @@ -21,13 +21,11 @@ # SOFTWARE. from enum import Enum -import json from flask import Flask from flask import jsonify from flask import request -from ansys.aedt.toolkits.common.backend.api import AEDTCommon from ansys.aedt.toolkits.common.backend.api import ToolkitThreadStatus from ansys.aedt.toolkits.common.backend.logger_handler import logger @@ -39,7 +37,16 @@ class BodyErrorMessage(str, Enum): INCORRECT_CONTENT = "Body content is not correct." -toolkit_api = AEDTCommon() +try: + from api import ToolkitBackend + + toolkit_api = ToolkitBackend() + +except ImportError: + from ansys.aedt.toolkits.common.backend.api import AEDTCommon + + toolkit_api = AEDTCommon() + app = Flask(__name__) @@ -133,8 +140,8 @@ def open_project(): logger.error(msg) return jsonify(msg), 500 - data = body.decode("utf-8") - project_path = json.loads(data) + project_path = body.decode("utf-8") + # project_path = json.loads(data) response = toolkit_api.open_project(project_path) if response: diff --git a/src/ansys/aedt/toolkits/common/ui/actions_generic.py b/src/ansys/aedt/toolkits/common/ui/actions_generic.py index 2950aa93..f474c352 100644 --- a/src/ansys/aedt/toolkits/common/ui/actions_generic.py +++ b/src/ansys/aedt/toolkits/common/ui/actions_generic.py @@ -48,13 +48,16 @@ def __init__(self): # Load toolkit icon self.images_path = os.path.join(os.path.dirname(__file__), "images") - def poll_url(self, url: str, timeout: int = 10): - """Perform GET requests on an URL. + @staticmethod + def poll_url(url: str, timeout: int = 10): + """Perform GET requests on URL. Continuously perform GET requests to the specified URL until a valid response is received. Parameters ---------- + url : str + URL to poll. timeout : int, optional Time out in seconds. The default is 10 seconds. @@ -71,7 +74,7 @@ def poll_url(self, url: str, timeout: int = 10): response_content = None response_success = False try: - while not response_success and count < 10: + while not response_success and count < timeout: time.sleep(1) response = requests.get(url) response_success = response.ok @@ -141,10 +144,11 @@ def set_properties(self, data): msg = "Set properties failed" self.log_and_update_progress(msg, log_level="error") - def find_process_ids(self, version): + def find_process_ids(self, version, non_graphical): try: be_properties = self.get_properties() be_properties["aedt_version"] = version + be_properties["non_graphical"] = non_graphical self.set_properties(be_properties) response = requests.get(self.url + "/aedt_sessions") sessions = [] @@ -206,7 +210,7 @@ def open_project(self, selected_project): elif res_idle: self.ui.progress.progress = 0 response = requests.get(self.url + "/health") - if response.ok and response.json() == "toolkit not connected to AEDT": + if response.ok and response.json() == "toolkit is not connected to AEDT.": response = requests.post(self.url + "/open_project", data=selected_project) if response.status_code == 200: msg = "Project opened" diff --git a/src/ansys/aedt/toolkits/common/ui/common_windows/main_window.py b/src/ansys/aedt/toolkits/common/ui/common_windows/main_window.py index 3405ea5c..920ae4fe 100644 --- a/src/ansys/aedt/toolkits/common/ui/common_windows/main_window.py +++ b/src/ansys/aedt/toolkits/common/ui/common_windows/main_window.py @@ -90,10 +90,10 @@ def main_clicked(self): is_progress_visible = self._app.ui.is_progress_visible() self._app.ui.left_menu.select_only_one(selected_menu.objectName()) + if selected_menu.objectName() == "home_menu": - self._app.ui.set_page(self._app.ui.load_pages.home_page) - if selected_menu.objectName() == "home_menu" and not is_left_visible: - self._app.ui.toggle_left_column() + if not is_left_visible: + self._app.ui.toggle_left_column() self._app.ui.set_left_column_menu( menu=self._app.ui.left_column.menus.menu_home, title="Home", @@ -107,13 +107,11 @@ def main_clicked(self): self._app.ui.set_right_column_menu(title="Settings") elif selected_menu.objectName() == "progress_menu": - if is_left_visible: - self._app.ui.toggle_left_column() if is_progress_visible: selected_menu.set_active(False) self._app.ui.toggle_progress() - elif is_left_visible or selected_menu.objectName() == "close_left_column" or is_right_visible: + elif selected_menu.objectName() == "close_left_column" or is_right_visible: if self._app.ui.is_left_column_visible(): selected_menu.set_active(False) self._app.ui.toggle_left_column() diff --git a/src/ansys/aedt/toolkits/common/ui/common_windows/settings_column.py b/src/ansys/aedt/toolkits/common/ui/common_windows/settings_column.py index fe52b2fe..54d33efc 100644 --- a/src/ansys/aedt/toolkits/common/ui/common_windows/settings_column.py +++ b/src/ansys/aedt/toolkits/common/ui/common_windows/settings_column.py @@ -158,8 +158,10 @@ def process_id(self): if self.signal_flag: self.aedt_session.clear() self.aedt_session.addItem("New Session") + non_graphical_pos = self.graphical_mode.position + non_graphical = non_graphical_pos == 24.0 if self.aedt_version.currentText() and self.aedt_version.currentText() != "AEDT not installed": - sessions = self.app.find_process_ids(self.aedt_version.currentText()) + sessions = self.app.find_process_ids(self.aedt_version.currentText(), non_graphical) for pid in sessions: if sessions[pid] == -1: self.aedt_session.addItem("Process {}".format(pid)) diff --git a/tests/backend/tests_rest_api/conftest.py b/tests/backend/tests_rest_api/conftest.py index 5a487b31..6d565bbc 100644 --- a/tests/backend/tests_rest_api/conftest.py +++ b/tests/backend/tests_rest_api/conftest.py @@ -55,6 +55,7 @@ # Update AEDT settings setup_aedt_settings(config) + @pytest.fixture(scope="session") def client(logger, common_temp_dir): """Create a test client.""" @@ -73,7 +74,7 @@ def client(logger, common_temp_dir): timeout = 60 response = client.get("/wait_thread", json=timeout) aedt_file = os.path.join(common_temp_dir, "input_data", f"{PROJECT_NAME}.aedt") - client.post("/open_project", json=aedt_file) + client.post("/open_project", data=aedt_file) assert response.status_code == 200 yield client