Skip to content

Commit

Permalink
Addon Manager: Set parent for most modals
Browse files Browse the repository at this point in the history
  • Loading branch information
chennes committed Jan 13, 2023
1 parent e1dc7bd commit b933d46
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Mod/AddonManager/AddonManager.py
Expand Up @@ -169,6 +169,7 @@ def launch(self) -> None:
self.dialog = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "AddonManager.ui")
)
self.dialog.setObjectName("AddonManager_Main_Window")
# self.dialog.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint, True)

# cleanup the leftovers from previous runs
Expand Down
19 changes: 11 additions & 8 deletions src/Mod/AddonManager/addonmanager_installer_gui.py
Expand Up @@ -159,7 +159,7 @@ def _handle_disallowed_python(self, python_requires: List[str]) -> bool:
message += "</ul>"
message += "To ignore this error and install anyway, press OK."
r = QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Missing Requirement"),
message,
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel,
Expand Down Expand Up @@ -205,7 +205,7 @@ def _report_missing_workbenches(self, wbs) -> bool:
message += "</ul>"
message += translate("AddonsInstaller", "Press OK to install anyway.")
r = QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Missing Requirement"),
message,
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel,
Expand Down Expand Up @@ -249,7 +249,7 @@ def _check_python_version(self, missing: MissingDependencies) -> bool:
if sys.version_info.minor < minor_required:
# pylint: disable=line-too-long
QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Incompatible Python version"),
translate(
"AddonsInstaller",
Expand Down Expand Up @@ -326,6 +326,7 @@ def _run_dependency_installer(self, addons, python_requires, python_optional):
translate("AddonsInstaller", "Installing dependencies"),
translate("AddonsInstaller", "Installing dependencies") + "...",
QtWidgets.QMessageBox.Cancel,
parent=utils.get_main_am_window()
)
self.dependency_installation_dialog.rejected.connect(
self._cancel_dependency_installation
Expand All @@ -345,7 +346,7 @@ def _report_no_python_exe(self) -> None:
self.dependency_installation_dialog.hide()
# pylint: disable=line-too-long
result = QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Cannot execute Python"),
translate(
"AddonsInstaller",
Expand All @@ -369,7 +370,7 @@ def _report_no_pip(self, command: str) -> None:
self.dependency_installation_dialog.hide()
# pylint: disable=line-too-long
result = QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Cannot execute pip"),
translate(
"AddonsInstaller",
Expand Down Expand Up @@ -397,7 +398,7 @@ def _report_dependency_failure(self, short_message: str, details: str) -> None:
)
FreeCAD.Console.PrintError(details + "\n")
result = QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Package installation failed"),
short_message
+ "\n\n"
Expand Down Expand Up @@ -449,6 +450,7 @@ def install(self) -> None:
self.addon_to_install.display_name
),
QtWidgets.QMessageBox.Cancel,
parent=utils.get_main_am_window()
)
self.installing_dialog.rejected.connect(self._cancel_addon_installation)
self.installer.finished.connect(self.installing_dialog.hide)
Expand All @@ -462,6 +464,7 @@ def _cancel_addon_installation(self):
self.addon_to_install.display_name
),
QtWidgets.QMessageBox.NoButton,
parent=utils.get_main_am_window()
)
dlg.show()
if self.worker_thread.isRunning():
Expand All @@ -483,7 +486,7 @@ def _cancel_addon_installation(self):
def _installation_succeeded(self):
"""Called if the installation was successful."""
QtWidgets.QMessageBox.information(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Success"),
translate("AddonsInstaller", "{} was installed successfully").format(
self.addon_to_install.name
Expand All @@ -496,7 +499,7 @@ def _installation_succeeded(self):
def _installation_failed(self, addon, message):
"""Called if the installation failed."""
QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Installation Failed"),
translate("AddonsInstaller", "Failed to install {}").format(addon.name)
+ "\n"
Expand Down
8 changes: 5 additions & 3 deletions src/Mod/AddonManager/addonmanager_uninstaller_gui.py
Expand Up @@ -28,6 +28,7 @@
from PySide import QtCore, QtWidgets

from addonmanager_uninstaller import AddonUninstaller, MacroUninstaller
import addonmanager_utilities as utils

translate = FreeCAD.Qt.translate

Expand Down Expand Up @@ -78,7 +79,7 @@ def _confirm_uninstallation(self) -> bool:
"""Present a modal dialog asking the user if they really want to uninstall. Returns True to
continue with the uninstallation, or False to stop the process."""
confirm = QtWidgets.QMessageBox.question(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Confirm remove"),
translate(
"AddonsInstaller", "Are you sure you want to uninstall {}?"
Expand All @@ -96,6 +97,7 @@ def _show_progress_dialog(self):
)
+ "...",
QtWidgets.QMessageBox.Cancel,
parent = utils.get_main_am_window()
)
self.progress_dialog.rejected.connect(self._cancel_removal)
self.progress_dialog.show()
Expand All @@ -114,7 +116,7 @@ def _succeeded(self, addon):
if self.progress_dialog:
self.progress_dialog.hide()
QtWidgets.QMessageBox.information(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Uninstall complete"),
translate("AddonInstaller", "Finished removing {}").format(
addon.display_name
Expand All @@ -128,7 +130,7 @@ def _failed(self, addon, message):
if self.progress_dialog:
self.progress_dialog.hide()
QtWidgets.QMessageBox.critical(
None,
utils.get_main_am_window(),
translate("AddonsInstaller", "Uninstall failed"),
translate("AddonInstaller", "Failed to remove some files")
+ ":\n"
Expand Down
1 change: 1 addition & 0 deletions src/Mod/AddonManager/addonmanager_update_all_gui.py
Expand Up @@ -89,6 +89,7 @@ def __init__(self, addons: List[Addon]):
self.dialog = FreeCADGui.PySideUic.loadUi(
os.path.join(os.path.dirname(__file__), "update_all.ui")
)
self.dialog.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint, True)
self.row_map = {}
self.in_process_row = None
self.active_installer = None
Expand Down
17 changes: 17 additions & 0 deletions src/Mod/AddonManager/addonmanager_utilities.py
Expand Up @@ -451,3 +451,20 @@ def run_interruptable_subprocess(args) -> object:
if return_code is None or return_code != 0:
raise subprocess.CalledProcessError(return_code, args, stdout, stderr)
return subprocess.CompletedProcess(args, return_code, stdout, stderr)

def get_main_am_window():
windows = QtWidgets.QApplication.topLevelWidgets()
for widget in windows:
if widget.objectName() == "AddonManager_Main_Window":
return widget
# If there is no main AM window, we may be running unit tests: see if the Test Runner window
# exists:
for widget in windows:
if widget.objectName() == "TestGui__UnitTest":
return widget
# If we still didn't find it, try to locate the main FreeCAD window:
for widget in windows:
if hasattr(widget, "centralWidget"):
return widget.centralWidget()
# Why is this code even getting called?
return None

0 comments on commit b933d46

Please sign in to comment.