[education/rkward/devel/workspace_output] rkward/dialogs: Avoid setting window modality, manually, for setup wizard (does not appear to work well on Mac)

Thomas Friedrichsmeier null at kde.org
Mon Mar 7 20:12:28 GMT 2022


Git commit b6a879394c5063b0f566da7639bfa07d40b28181 by Thomas Friedrichsmeier.
Committed on 07/03/2022 at 20:11.
Pushed by tfry into branch 'devel/workspace_output'.

Avoid setting window modality, manually, for setup wizard (does not appear to work well on Mac)

M  +15   -7    rkward/dialogs/rksetupwizard.cpp
M  +4    -0    rkward/dialogs/rksetupwizard.h

https://invent.kde.org/education/rkward/commit/b6a879394c5063b0f566da7639bfa07d40b28181

diff --git a/rkward/dialogs/rksetupwizard.cpp b/rkward/dialogs/rksetupwizard.cpp
index e4787793..11bb80dc 100644
--- a/rkward/dialogs/rksetupwizard.cpp
+++ b/rkward/dialogs/rksetupwizard.cpp
@@ -25,6 +25,7 @@
 #include <QGridLayout>
 #include <QIcon>
 #include <QPushButton>
+#include <QTimer>
 
 #include <KLocalizedString>
 #include <KMessageBox>
@@ -138,9 +139,9 @@ RKSetupWizard::RKSetupWizard(QWidget* parent, InvokationReason reason, const QLi
 		intro += i18n("<p>The setup assistant has been invoked, automatically, because a problem has been detected in your setup.</p>");
 	}
 	l->addWidget(RKCommonFunctions::wordWrappedLabel(intro));
-	auto waiting_to_start_label = RKCommonFunctions::wordWrappedLabel(i18n("<b>Waiting for R backend...</b>") + "<p> </p><p> </p>");
+	waiting_to_start_label = RKCommonFunctions::wordWrappedLabel(i18n("<b>Waiting for R backend...</b>") + "<p> </p><p> </p>");
 	l->addWidget(waiting_to_start_label);
-	auto firstpageref = addPage (firstpage, i18n("RKWard Setup Assistant"));
+	firstpageref = addPage (firstpage, i18n("RKWard Setup Assistant"));
 	setValid(firstpageref, false);
 
 	// Basic installation page
@@ -188,16 +189,23 @@ RKSetupWizard::RKSetupWizard(QWidget* parent, InvokationReason reason, const QLi
 	current_layout->setRowStretch(++current_row, 1);
 	addPage(current_page, i18n("Basic installation"));
 
-	// Wait for R Interface, then start dialog
-	setWindowModality(Qt::ApplicationModal);
-	show();
-	while (!RKGlobals::rInterface()->backendIsIdle()) {
+	// Next we'll want to wait for the R backend to start up. Previous solution was to set Qt::ApplicationModal, and wait, calling processEvents().
+	// This does not seem to work well on mac, however, so instead we return, here, so exec will be called from outside, then fire a timer to finish constuction.
+	QTimer::singleShot(10, this, &RKSetupWizard::setupWizardPhase2);
+}
+
+void RKSetupWizard::setupWizardPhase2() {
+	// Wait for R Interface, then enable dialog
+	if (!RKGlobals::rInterface()->backendIsIdle()) {
 		if (RKGlobals::rInterface()->backendIsDead()) {
 			waiting_to_start_label->setText(i18n("<b>R backend has crashed. Click \"Cancel\" to exit setup assistant.</b>"));
 		} else {
-			QApplication::processEvents(QEventLoop::AllEvents, 1000);
+			QTimer::singleShot(100, this, &RKSetupWizard::setupWizardPhase2);
 		}
+		return;
 	}
+	RK_TRACE(APP);
+
 	waiting_to_start_label->setText(i18n("<b>R backend has started. Click \"Next\" to continue.</b>"));
 	setValid(firstpageref, true);
 
diff --git a/rkward/dialogs/rksetupwizard.h b/rkward/dialogs/rksetupwizard.h
index 9c22d479..e66ea315 100644
--- a/rkward/dialogs/rksetupwizard.h
+++ b/rkward/dialogs/rksetupwizard.h
@@ -45,6 +45,10 @@ public:
 	void markSoftwareForInstallation(const QString &name, const QString &download_url, bool install);
 	void markRPackageForInstallation(const QString &name, bool install);
 private:
+	void setupWizardPhase2();
+	KPageWidgetItem* firstpageref;
+	QLabel* waiting_to_start_label;
+
 	QStringList software_to_install;
 	QStringList software_to_install_urls;
 	QStringList packages_to_install;


More information about the rkward-tracker mailing list