def newButtonSetOrUpdateCurrent(self): ''' Asks user whether saving of button set is to be to a new file, or an update to the current file. Cancel is offered as well. @return: ButtonSaveResult.NEW_SET, ButtonSaveResult.UPDATE_CURRENT, or ButtonSaveResult.CANCEL @rtype: DialogService.ButtonSaveResult ''' msgBox = QMessageBox() msgBox.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); msgBox.setText('Create new button set, or update current set?') updateCurrButton = QPushButton('Update current') msgBox.addButton(updateCurrButton, QMessageBox.NoRole) newSetButton = QPushButton('Create new set') msgBox.addButton(newSetButton, QMessageBox.YesRole) cancelButton = QPushButton('Cancel'); msgBox.addButton(cancelButton, QMessageBox.RejectRole) value = msgBox.exec_(); return value;
class DialogService(object): class ButtonSaveResult: UPDATE_CURRENT = 0; NEW_SET = 1; CANCEL = 2; #---------------------------------- # Initializer #-------------- def __init__(self, parent=None): # All-purpose error popup message: # Used by self.showErrorMsgByErrorCode(<errorCode>), # or self.showErrorMsg(<string>). Returns a # QErrorMessage without parent, but with QWindowFlags set # properly to be a dialog popup box: self.errorMsgPopup = QErrorMessage.qtHandler(); # Re-parent the popup, retaining the window flags set # by the qtHandler: self.errorMsgPopup.setParent(parent, self.errorMsgPopup.windowFlags()); self.errorMsgPopup.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); self.infoMsg = QMessageBox(parent=parent); self.infoMsg.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); #---------------------------------- # showErrorMsg #-------------- QErrorMessage def showErrorMsg(self,errMsg): ''' Given a string, pop up an error dialog. @param errMsg: The message @type errMsg: string ''' self.errorMsgPopup.showMessage(errMsg); #---------------------------------- # showInfoMsg #-------------- def showInfoMessage(self, text): self.infoMsg.setText(text); self.infoMsg.exec_(); #---------------------------------- # newButtonSetOrUpdateCurrent #-------------- def newButtonSetOrUpdateCurrent(self): ''' Asks user whether saving of button set is to be to a new file, or an update to the current file. Cancel is offered as well. @return: ButtonSaveResult.NEW_SET, ButtonSaveResult.UPDATE_CURRENT, or ButtonSaveResult.CANCEL @rtype: DialogService.ButtonSaveResult ''' msgBox = QMessageBox() msgBox.setStyleSheet(SpeakEasyGUI.stylesheetAppBG); msgBox.setText('Create new button set, or update current set?') updateCurrButton = QPushButton('Update current') msgBox.addButton(updateCurrButton, QMessageBox.NoRole) newSetButton = QPushButton('Create new set') msgBox.addButton(newSetButton, QMessageBox.YesRole) cancelButton = QPushButton('Cancel'); msgBox.addButton(cancelButton, QMessageBox.RejectRole) value = msgBox.exec_(); return value;