def __kdeWarning(parent, title, text, buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton): """ Function to show a modal warning message box. @param parent parent widget of the message box @param title caption of the message box @param text text to be shown by the message box @param buttons flags indicating which buttons to show (QMessageBox.StandardButtons) @param defaultButton flag indicating the default button (QMessageBox.StandardButton) @return button pressed by the user (QMessageBox.StandardButton) """ if __nrButtons(buttons) == 1: KMessageBox.sorry(parent, text, title) return buttons if __nrButtons(buttons) == 2: if defaultButton == QMessageBox.NoButton: defaultButton = __getLowestFlag(buttons) noButton = defaultButton noItem = __getGuiItem(noButton) yesButton = int(buttons & ~noButton) yesItem = __getGuiItem(yesButton) res = KMessageBox.warningYesNo(parent, text, title, yesItem, noItem) if res == KMessageBox.Yes: return yesButton else: return noButton if __nrButtons(buttons) == 3: if defaultButton == QMessageBox.NoButton: defaultButton = __getLowestFlag(buttons) yesButton = defaultButton yesItem = __getGuiItem(yesButton) buttons = buttons & ~yesButton noButton = __getLowestFlag(buttons) noItem = __getGuiItem(noButton) cancelButton = int(buttons & ~noButton) cancelItem = __getGuiItem(cancelButton) res = KMessageBox.warningYesNoCancel(parent, text, title, yesItem, noItem, cancelItem) if res == KMessageBox.Yes: return yesButton elif res == KMessageBox.No: return noButton else: return cancelButton raise RuntimeError("More than three buttons are not supported.")
def queryClose(self): """ Gets invoked by Qt if the window is about to be closed Returns True if it is allowed to close """ self.kate.writeConfig(self.autoSaveConfigGroup().config()) if self.editor.document().isModified(): ret = KMessageBox.warningYesNoCancel(self, i18n('Save changes to document?')) if ret == KMessageBox.Yes: return self.editor.document().documentSave() else: return ret == KMessageBox.No else: return True
def queryClose(self): """Ask user if document modified and saves if desired.""" # Many stuff copied from KatePart if not self.doc or not self.isModified(): return True res = KMessageBox.warningYesNoCancel(self.app.mainwin, i18n( "The document \"%1\" has been modified.\n" "Do you want to save your changes or discard them?", self.documentName()), i18n("Close Document"), KStandardGuiItem.save(), KStandardGuiItem.discard()) if res == KMessageBox.Yes: self.save() elif res == KMessageBox.No: return True else: # cancel return False