From fbe9f80eb01fa888f1a7bc33c8c6e92a6f350d47 Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Thu, 1 May 2025 12:47:02 -0700 Subject: [PATCH 1/6] Move the dialogs to the ADR code base --- .../core/utils/report_remote_server.py | 68 ++++++++++++++----- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index 34d6bf6df..9b3da637d 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -1276,12 +1276,20 @@ def create_new_local_database( except OSError as e: if not os.path.isdir(db_dir): if parent and has_qt: # pragma: no cover - msg = QtWidgets.QApplication.translate( - "nexus", "The selected directory could not be accessed." - ) + if exec_basis and ansys_version: + if trasnlated_dlg not in sys.modules: + sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + import translated_dlg + msg = translated_dlg.error_dir_selection() + top_banner = translated_dlg.banner_error_dir_selection() + else: + msg = QtWidgets.QApplication.translate( + "nexus", "The selected directory could not be accessed." + ) + top_banner = QtWidgets.QApplication.translate("nexus", "Invalid database location") QtWidgets.QMessageBox.critical( parent, - QtWidgets.QApplication.translate("nexus", "Invalid database location"), + top_banner, msg, ) @@ -1298,12 +1306,18 @@ def create_new_local_database( os.path.join(db_dir, "db.sqlite3") ): if parent and has_qt: - msg = QtWidgets.QApplication.translate( - "nexus", "The selected directory already appears to have a database in it." - ) - QtWidgets.QMessageBox.critical( - parent, QtWidgets.QApplication.translate("nexus", "Invalid database location"), msg - ) + if exec_basis and ansys_version: + if trasnlated_dlg not in sys.modules: + sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + import translated_dlg + msg = translated_dlg.error_existing_db() + top_banner = translated_dlg.banner_error_existing_db() + else: + msg = QtWidgets.QApplication.translate( + "nexus", "The selected directory already appears to have a database in it." + ) + top_banner = QtWidgets.QApplication.translate("nexus", "Invalid database location") + QtWidgets.QMessageBox.critical(parent, top_banner, msg) if raise_exception: raise exceptions.DBExistsError( @@ -1400,12 +1414,21 @@ def create_new_local_database( except Exception as e: if parent and has_qt: - msg = QtWidgets.QApplication.translate( - "nexus", "The creation of a new, local database failed with the error:" - ) + if exec_basis and ansys_version: + if trasnlated_dlg not in sys.modules: + if trasnlated_dlg not in sys.modules: + sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + import translated_dlg + msg = translated_dlg.error_generic_db() + top_banner = translated_dlg.banner_error_generic_db() + else: + msg = QtWidgets.QApplication.translate( + "nexus", "The creation of a new, local database failed with the error:" + ) + top_banner = QtWidgets.QApplication.translate("nexus", "Database creation failed") QtWidgets.QMessageBox.critical( parent, - QtWidgets.QApplication.translate("nexus", "Database creation failed"), + top_banner, msg + str(e), ) @@ -1421,12 +1444,21 @@ def create_new_local_database( return True if parent and has_qt: - msg = QtWidgets.QApplication.translate( - "nexus", "A new Nexus database has been created in the folder:" - ) + if exec_basis and ansys_version: + if trasnlated_dlg not in sys.modules: + if trasnlated_dlg not in sys.modules: + sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + import translated_dlg + msg = translated_dlg.success_db() + top_banner = translated_dlg.banner_success_db() + else: + msg = QtWidgets.QApplication.translate( + "nexus", "A new Nexus database has been created in the folder:" + ) + top_banner = QtWidgets.QApplication.translate("nexus", "Database creation successful") QtWidgets.QMessageBox.information( parent, - QtWidgets.QApplication.translate("nexus", "Database creation successful"), + top_banner, msg + str(db_dir), ) return True From d040556ea020daec0bf718683d89f0c19ab6daa0 Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Thu, 1 May 2025 12:57:39 -0700 Subject: [PATCH 2/6] Fix the style --- .../core/utils/report_remote_server.py | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index 9b3da637d..bd19425cf 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -1278,7 +1278,14 @@ def create_new_local_database( if parent and has_qt: # pragma: no cover if exec_basis and ansys_version: if trasnlated_dlg not in sys.modules: - sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + sys.path.append( + os.path.join( + exec_basis, + "nexus" + report_ver, + "template_editor", + "translated_dlg.py", + ) + ) import translated_dlg msg = translated_dlg.error_dir_selection() top_banner = translated_dlg.banner_error_dir_selection() @@ -1286,7 +1293,9 @@ def create_new_local_database( msg = QtWidgets.QApplication.translate( "nexus", "The selected directory could not be accessed." ) - top_banner = QtWidgets.QApplication.translate("nexus", "Invalid database location") + top_banner = QtWidgets.QApplication.translate( + "nexus", "Invalid database location" + ) QtWidgets.QMessageBox.critical( parent, top_banner, @@ -1308,7 +1317,11 @@ def create_new_local_database( if parent and has_qt: if exec_basis and ansys_version: if trasnlated_dlg not in sys.modules: - sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + sys.path.append( + os.path.join( + exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py" + ) + ) import translated_dlg msg = translated_dlg.error_existing_db() top_banner = translated_dlg.banner_error_existing_db() @@ -1417,7 +1430,14 @@ def create_new_local_database( if exec_basis and ansys_version: if trasnlated_dlg not in sys.modules: if trasnlated_dlg not in sys.modules: - sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + sys.path.append( + os.path.join( + exec_basis, + "nexus" + report_ver, + "template_editor", + "translated_dlg.py", + ) + ) import translated_dlg msg = translated_dlg.error_generic_db() top_banner = translated_dlg.banner_error_generic_db() @@ -1447,7 +1467,11 @@ def create_new_local_database( if exec_basis and ansys_version: if trasnlated_dlg not in sys.modules: if trasnlated_dlg not in sys.modules: - sys.path.append( os.path.join(exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py")) + sys.path.append( + os.path.join( + exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py" + ) + ) import translated_dlg msg = translated_dlg.success_db() top_banner = translated_dlg.banner_success_db() From df99824ce7febc9d38577e6e3d5ddb9ac6426e67 Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Tue, 6 May 2025 10:21:22 -0700 Subject: [PATCH 3/6] Simplify code for translation --- .../core/utils/report_remote_server.py | 170 ++++++++---------- 1 file changed, 72 insertions(+), 98 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index bd19425cf..adac0f591 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -38,6 +38,24 @@ from .encoders import BaseEncoder +def single_dialog(exec_basis: str, ansys_version: str, input_msg: str): + if exec_basis and ansys_version: + if trasnlated_dlg not in sys.modules: + sys.path.append( + os.path.join( + exec_basis, + "nexus" + report_ver, + "template_editor", + "translated_dlg.py", + ) + ) + import translated_dlg + tr_widget = translated_dlg.transl_qwid(input_msg) + else: + tr_widget = QtWidgets.QApplication.translate("nexus", input_msg) + return tr_widget + + def disable_warn_logging(func): # Decorator to suppress harmless warning messages @functools.wraps(func) @@ -721,8 +739,8 @@ def copy_items( nobjs += 1 n = 0 if progress: - if progress_qt and has_qt: - s = QtWidgets.QApplication.translate("nexus", "Importing:") + if progress_qt and has_qt: # pragma: no cover + s = single_dialog(exec_basis, ansys_version, "Importing:") s += report_utils.from_local_8bit(obj_type) else: s = f"Importing: {obj_type}" @@ -918,7 +936,7 @@ def export_report_as_pdf( query["print"] = "pdf" url = self.build_url_with_query(report_guid, query, item_filter) file_path = os.path.abspath(file_name) - if has_qt and (parent is not None): + if has_qt and (parent is not None): # pragma: no cover from .report_download_pdf import NexusPDFSave app = QtGui.QGuiApplication.instance() @@ -1259,8 +1277,8 @@ def create_new_local_database( """Create a new, empty sqlite database If parent is not None, a QtGui will be used.""" if parent and has_qt: # pragma: no cover - title = QtWidgets.QApplication.translate( - "nexus", "Select an empty folder to create the database in" + title = single_dialog( + exec_basis, ansys_version, "Select an empty folder to create the database in" ) fn = QtWidgets.QFileDialog.getExistingDirectory(parent, title, directory) if len(fn) == 0: @@ -1276,26 +1294,10 @@ def create_new_local_database( except OSError as e: if not os.path.isdir(db_dir): if parent and has_qt: # pragma: no cover - if exec_basis and ansys_version: - if trasnlated_dlg not in sys.modules: - sys.path.append( - os.path.join( - exec_basis, - "nexus" + report_ver, - "template_editor", - "translated_dlg.py", - ) - ) - import translated_dlg - msg = translated_dlg.error_dir_selection() - top_banner = translated_dlg.banner_error_dir_selection() - else: - msg = QtWidgets.QApplication.translate( - "nexus", "The selected directory could not be accessed." - ) - top_banner = QtWidgets.QApplication.translate( - "nexus", "Invalid database location" - ) + msg = single_dialog( + exec_basis, ansys_version, "The selected directory could not be accessed." + ) + top_banner = single_dialog(exec_basis, ansys_version, "Invalid database location") QtWidgets.QMessageBox.critical( parent, top_banner, @@ -1315,21 +1317,12 @@ def create_new_local_database( os.path.join(db_dir, "db.sqlite3") ): if parent and has_qt: - if exec_basis and ansys_version: - if trasnlated_dlg not in sys.modules: - sys.path.append( - os.path.join( - exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py" - ) - ) - import translated_dlg - msg = translated_dlg.error_existing_db() - top_banner = translated_dlg.banner_error_existing_db() - else: - msg = QtWidgets.QApplication.translate( - "nexus", "The selected directory already appears to have a database in it." - ) - top_banner = QtWidgets.QApplication.translate("nexus", "Invalid database location") + msg = single_dialog( + exec_basis, + ansys_version, + "The selected directory already appears to have a database in it.", + ) + top_banner = single_dialog(exec_basis, ansys_version, "Invalid database location") QtWidgets.QMessageBox.critical(parent, top_banner, msg) if raise_exception: @@ -1427,25 +1420,12 @@ def create_new_local_database( except Exception as e: if parent and has_qt: - if exec_basis and ansys_version: - if trasnlated_dlg not in sys.modules: - if trasnlated_dlg not in sys.modules: - sys.path.append( - os.path.join( - exec_basis, - "nexus" + report_ver, - "template_editor", - "translated_dlg.py", - ) - ) - import translated_dlg - msg = translated_dlg.error_generic_db() - top_banner = translated_dlg.banner_error_generic_db() - else: - msg = QtWidgets.QApplication.translate( - "nexus", "The creation of a new, local database failed with the error:" - ) - top_banner = QtWidgets.QApplication.translate("nexus", "Database creation failed") + msg = single_dialog( + exec_basis, + ansys_version, + "The creation of a new, local database failed with the error:", + ) + top_banner = single_dialog(exec_basis, ansys_version, "Database creation failed") QtWidgets.QMessageBox.critical( parent, top_banner, @@ -1464,22 +1444,10 @@ def create_new_local_database( return True if parent and has_qt: - if exec_basis and ansys_version: - if trasnlated_dlg not in sys.modules: - if trasnlated_dlg not in sys.modules: - sys.path.append( - os.path.join( - exec_basis, "nexus" + report_ver, "template_editor", "translated_dlg.py" - ) - ) - import translated_dlg - msg = translated_dlg.success_db() - top_banner = translated_dlg.banner_success_db() - else: - msg = QtWidgets.QApplication.translate( - "nexus", "A new Nexus database has been created in the folder:" - ) - top_banner = QtWidgets.QApplication.translate("nexus", "Database creation successful") + msg = single_dialog( + exec_basis, ansys_version, "A new Nexus database has been created in the folder:" + ) + top_banner = single_dialog(exec_basis, ansys_version, "Database creation successful") QtWidgets.QMessageBox.information( parent, top_banner, @@ -1761,10 +1729,10 @@ def launch_local_database_server( if no_directory_prompt: db_dir = os.path.abspath(directory) else: - f = QtWidgets.QApplication.translate("nexus", "Nexus database (db.sqlite3)") + f = single_dialog(exec_basis, ansys_version, "Nexus database (db.sqlite3)") fn = QtWidgets.QFileDialog.getOpenFileName( parent, - QtWidgets.QApplication.translate("nexus", "Select the database file"), + single_dialog(exec_basis, ansys_version, "Select the database file"), directory, f, f, @@ -1778,12 +1746,13 @@ def launch_local_database_server( # we expect to see: 'manage.py' and 'media' in this folder if not validate_local_db(db_dir): - msg = QtWidgets.QApplication.translate( - "nexus", "The selected database file does not appear to be a valid database." - ) - QtWidgets.QMessageBox.critical( - parent, QtWidgets.QApplication.translate("nexus", "Invalid database"), msg + msg = single_dialog( + exec_basis, + ansys_version, + "The selected database file does not appear to be a valid database.", ) + top_banner = single_dialog(exec_basis, ansys_version, "Invalid database") + QtWidgets.QMessageBox.critical(parent, top_banner, msg) if local_lock: local_lock.release() if raise_exception: @@ -1852,13 +1821,14 @@ def launch_local_database_server( # validate will throw exceptions or return a float. _ = tmp_server.validate() # if we have a valid version number, then do not start a server!!! - if parent and has_qt: - msg = QtWidgets.QApplication.translate( - "nexus", + if parent and has_qt: # pragma: no cover + msg = single_dialog( + exec_basis, + ansys_version, "There appears to be a local Nexus server already running on that port.\nPlease stop that server first or select a different port.", ) QtWidgets.QMessageBox.critical( - parent, QtWidgets.QApplication.translate("nexus", "Server already running"), msg + parent, single_dialog(exec_basis, ansys_version, "Server already running"), msg ) if local_lock: local_lock.release() @@ -1871,7 +1841,7 @@ def launch_local_database_server( pass # Start the busy cursor - if parent and has_qt: + if parent and has_qt: # pragma: no cover QtWidgets.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) # Here we run nexus_launcher with the following command line: @@ -1939,13 +1909,15 @@ def launch_local_database_server( # Note: this process only returns if the server is shutdown or there is an error monitor_process = subprocess.Popen(command, **params) except Exception as e: - if parent and has_qt: + if parent and has_qt: # pragma: no cover QtWidgets.QApplication.restoreOverrideCursor() - msg = QtWidgets.QApplication.translate( - "nexus", "Launching a server for the selected local database failed. Error:" + msg = single_dialog( + exec_basis, + ansys_version, + "Launching a server for the selected local database failed. Error:", ) QtWidgets.QMessageBox.critical( - parent, QtWidgets.QApplication.translate("nexus", "Unable to launch"), msg + str(e) + parent, single_dialog(exec_basis, ansys_version, "Unable to launch"), msg + str(e) ) if local_lock: local_lock.release() @@ -1961,13 +1933,15 @@ def launch_local_database_server( monitor_alive = monitor_process.poll() is None # if we ran out of patience or the monitor process is dead, we have an error if ((time.time() - t0) > server_timeout) or (not monitor_alive): - if parent and has_qt: + if parent and has_qt: # pragma: no cover QtWidgets.QApplication.restoreOverrideCursor() - msg = QtWidgets.QApplication.translate( - "nexus", "Unable to connect to the launched local Nexus server." + msg = single_dialog( + exec_basis, + ansys_version, + "Unable to connect to the launched local Nexus server.", ) QtWidgets.QMessageBox.critical( - parent, QtWidgets.QApplication.translate("nexus", "Unable to launch"), msg + parent, single_dialog(exec_basis, ansys_version, "Unable to launch"), msg ) # If it is still alive, try to tell the monitor to shut down if monitor_alive: @@ -2010,14 +1984,14 @@ def launch_local_database_server( if local_lock: local_lock.release() - if parent and has_qt: + if parent and has_qt: # pragma: no cover QtWidgets.QApplication.restoreOverrideCursor() if verbose: hostname = settings.get("server_hostname", "127.0.0.1") - msg = QtWidgets.QApplication.translate("nexus", "A new server has been launched at") + msg = single_dialog(exec_basis, ansys_version, "A new server has been launched at") msg += f" http://{hostname}:{port}" QtWidgets.QMessageBox.information( - parent, QtWidgets.QApplication.translate("nexus", "Nexus server launched"), msg + parent, single_dialog(exec_basis, ansys_version, "Nexus server launched"), msg ) # go ahead and assign the connection to any server we were passed if connect is not None: From e71b92aeac40b71ae4833ffae035d52635ef2c8b Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Tue, 6 May 2025 12:58:49 -0700 Subject: [PATCH 4/6] Fix imports --- .../core/utils/report_remote_server.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index adac0f591..f1d50134b 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -39,12 +39,19 @@ def single_dialog(exec_basis: str, ansys_version: str, input_msg: str): + if ansys_version is None: + ansys_version = str(report_utils.ceiversion_nexus_suffix()) + else: + ansys_version = str(ansys_version) + if exec_basis is None: + exec_basis = report_utils.enve_home() if exec_basis and ansys_version: - if trasnlated_dlg not in sys.modules: + if 'trasnlated_dlg' not in sys.modules: + print("It is not imported yet") sys.path.append( os.path.join( exec_basis, - "nexus" + report_ver, + "nexus" + ansys_version, "template_editor", "translated_dlg.py", ) From d17d5290b22cd92ac3f417596b66b25e099afcb0 Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Tue, 6 May 2025 13:00:22 -0700 Subject: [PATCH 5/6] Fix typos --- src/ansys/dynamicreporting/core/utils/report_remote_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index f1d50134b..3518ca812 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -42,11 +42,11 @@ def single_dialog(exec_basis: str, ansys_version: str, input_msg: str): if ansys_version is None: ansys_version = str(report_utils.ceiversion_nexus_suffix()) else: - ansys_version = str(ansys_version) + ansys_version = str(ansys_version) if exec_basis is None: exec_basis = report_utils.enve_home() if exec_basis and ansys_version: - if 'trasnlated_dlg' not in sys.modules: + if "trasnlated_dlg" not in sys.modules: print("It is not imported yet") sys.path.append( os.path.join( From c8af75151cb8716043083d20b8b6b5e74b0788d1 Mon Sep 17 00:00:00 2001 From: "U-ANSYS\\mgalvagn" Date: Tue, 6 May 2025 13:48:41 -0700 Subject: [PATCH 6/6] Remove debug print statement --- src/ansys/dynamicreporting/core/utils/report_remote_server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/dynamicreporting/core/utils/report_remote_server.py b/src/ansys/dynamicreporting/core/utils/report_remote_server.py index 3518ca812..a6c9c7aa5 100755 --- a/src/ansys/dynamicreporting/core/utils/report_remote_server.py +++ b/src/ansys/dynamicreporting/core/utils/report_remote_server.py @@ -47,7 +47,6 @@ def single_dialog(exec_basis: str, ansys_version: str, input_msg: str): exec_basis = report_utils.enve_home() if exec_basis and ansys_version: if "trasnlated_dlg" not in sys.modules: - print("It is not imported yet") sys.path.append( os.path.join( exec_basis,