From 6eb502730c0530f7f7e8905d07272a54338c2a14 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Wed, 6 Jul 2016 16:30:34 +0200 Subject: [PATCH] Add reusable messagebox based on QML MessageDialog Contributes to CURA-1730 and CURA-1850 --- cura/CuraApplication.py | 16 ++++++++++++++++ resources/qml/Cura.qml | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e34a537953..feaa700d48 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -47,6 +47,7 @@ import cura.Settings from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS from PyQt5.QtGui import QColor, QIcon +from PyQt5.QtWidgets import QMessageBox from PyQt5.QtQml import qmlRegisterUncreatableType, qmlRegisterSingletonType, qmlRegisterType import platform @@ -155,6 +156,8 @@ class CuraApplication(QtApplication): self._cura_actions = None self._started = False + self._message_box_callback = None + self._i18n_catalog = i18nCatalog("cura") self.getController().getScene().sceneChanged.connect(self.updatePlatformActivity) @@ -251,6 +254,19 @@ class CuraApplication(QtApplication): def _onEngineCreated(self): self._engine.addImageProvider("camera", CameraImageProvider.CameraImageProvider()) + ## A reusable dialogbox + # + showMessageBox = pyqtSignal(str, str, str, str, int, int, arguments = ["title", "text", "informativeText", "detailedText", "buttons", "icon"]) + def messageBox(self, title, text, informativeText = "", detailedText = "", buttons = QMessageBox.Ok, icon = QMessageBox.NoIcon, callback = None): + self._message_box_callback = callback + self.showMessageBox.emit(title, text, informativeText, detailedText, buttons, icon) + + @pyqtSlot(int) + def messageBoxClosed(self, button): + if self._message_box_callback: + self._message_box_callback(button) + self._message_box_callback = None + showPrintMonitor = pyqtSignal(bool, arguments = ["show"]) ## Cura has multiple locations where instance containers need to be saved, so we need to handle this differently. diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index e805991df4..f70dffa3cc 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -683,6 +683,35 @@ UM.MainWindow } } + MessageDialog + { + id: messageDialog + modality: Qt.ApplicationModal + onAccepted: Printer.messageBoxClosed(clickedButton) + onApply: Printer.messageBoxClosed(clickedButton) + onDiscard: Printer.messageBoxClosed(clickedButton) + onHelp: Printer.messageBoxClosed(clickedButton) + onNo: Printer.messageBoxClosed(clickedButton) + onRejected: Printer.messageBoxClosed(clickedButton) + onReset: Printer.messageBoxClosed(clickedButton) + onYes: Printer.messageBoxClosed(clickedButton) + } + + Connections + { + target: Printer + onShowMessageBox: + { + messageDialog.title = title + messageDialog.text = text + messageDialog.informativeText = informativeText + messageDialog.detailedText = detailedText + messageDialog.standardButtons = buttons + messageDialog.icon = icon + messageDialog.visible = true + } + } + Connections { target: Cura.Actions.addMachine