我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用PyQt5.QtWidgets.QMessageBox.Cancel()。
def yes_no_cancel_dlg(parent,text): if parent!=None: msgBox = QMessageBox(parent) msgBox.setIcon(QMessageBox.Question) msgBox.setText("Question") msgBox.setInformativeText(text) msgBox.setStandardButtons(QMessageBox.Yes| QMessageBox.No| QMessageBox.Cancel ) msgBox.setDefaultButton(QMessageBox.No) reply = msgBox.exec_() if reply == QMessageBox.Yes: return "yes" elif reply == QMessageBox.No: return "no" else: return "cancel" else: reply = input(text+"y/n/c") if reply == "y": return "yes" elif reply == "n": return "no" else: return "cancel"
def _save_as(self): path, ok = QFileDialog.getSaveFileName(self.modeler, caption="Save OPC UA XML", filter="XML Files (*.xml *.XML)") if ok: if os.path.isfile(path): reply = QMessageBox.question( self.modeler, "OPC UA Modeler", "File already exit, do you really want to save to this file?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel ) if reply != QMessageBox.Yes: return if self._last_model_dir != os.path.dirname(path): self._last_model_dir = os.path.dirname(path) self.settings.setValue("last_model_dir", self._last_model_dir) self._model_mgr.save_model(path)
def closeEvent(self, event): """ close window event :return: """ if not hasattr(self, 'case_edit_window'): # case_edit_window is not exist self.close() return if not self.case_edit_window.isVisible(): # case_edit_window is not visible self.close() return # signal for case_edit_window's closeEvent self.case_edit_window.close_cancel_signal.connect(self.editor_close_ignore, Qt.DirectConnection) # case_edit_window is visible reply = self.message_box.question(self, "Confirm Close?", "The editor is opened, still close?", QMessageBox.Yes | QMessageBox.Cancel) if reply == QMessageBox.Yes: self.is_editor_close_cancel = False self.case_edit_window.close() if self.is_editor_close_cancel: # editor close is canceled event.ignore() return self.close() else: event.ignore()
def handle_message_box_apply(self, event): """ message box :param event: :return: """ reply = self.message_box.question(self, "Save Changes?", "The case has been modified, save changes?", QMessageBox.Save | QMessageBox.Cancel | QMessageBox.Discard) if reply == QMessageBox.Save: # update case info self.save_case(event) # check case data widget isVisible if hasattr(self, 'case_data_widget') and self.case_data_widget.isVisible(): self.case_data_widget.close() elif reply == QMessageBox.Discard: # check case data widget isVisible if hasattr(self, 'case_data_widget') and self.case_data_widget.isVisible(): self.case_data_widget.close() self.close() return else: self.close_cancel_signal.emit() event.ignore()
def slot_new(self): """ ???? ?? ? ?? :return: """ if not self.is_saved: reply = QMessageBox.information( self, self.tr("Save"), self.tr("??? ??? ?????????"), QMessageBox.Save | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Save) if reply == QMessageBox.Save: if not self.slot_save(): return # ?? ?? elif reply == QMessageBox.No: pass else: return # ?? ?? self.init_setting()
def set_databaseconnection(): ''' Setting connection with SQLite ''' # TODO explicitly close database connection on exit filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'ResourceFiles', 'Database', 'Intg_osdag.sqlite') db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(filepath) if not db.open(): QMessageBox.critical(None, qApp.tr("Cannot open database"), qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information " "how to build it.\n\n" "Click Cancel to exit."), QMessageBox.Cancel) return False
def should_i_save_first(self): close = True if(self.saveaction.isEnabled()): from PyQt5.QtWidgets import QMessageBox msgBox = QMessageBox() msgBox.setText("Current project has been modified.") msgBox.setInformativeText("Do you want to save your changes first?") msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) msgBox.setDefaultButton(QMessageBox.Save) ret = msgBox.exec_() if (ret == QMessageBox.Save): if(not self._save_project()): close = False if (ret == QMessageBox.Cancel): close = False return close
def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) buttonReply = QMessageBox.question(self, 'PyQt5 message', "Do you want to save?", QMessageBox.YesToAll | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Cancel) print(int(buttonReply)) if buttonReply == QMessageBox.Yes: print('Yes clicked.') if buttonReply == QMessageBox.No: print('No clicked.') if buttonReply == QMessageBox.Cancel: print('Cancel') self.show()
def yes_no_cancel_dlg(parent,text): msgBox = QMessageBox(parent) msgBox.setIcon(QMessageBox.Question) msgBox.setText("Question") msgBox.setInformativeText(text) msgBox.setStandardButtons(QMessageBox.Yes| QMessageBox.No| QMessageBox.Cancel ) msgBox.setDefaultButton(QMessageBox.No) reply = msgBox.exec_() if reply == QMessageBox.Yes: return "yes" elif reply == QMessageBox.No: return "no" else: return "cancel"
def try_close_model(self): if self._model_mgr.modified: reply = QMessageBox.question( self.modeler, "OPC UA Modeler", "Model is modified, do you really want to close model?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel ) if reply != QMessageBox.Yes: return False self._model_mgr.close_model(force=True) return True
def launchError(self, error): if error != QProcess.Crashed: QMessageBox.critical(None, "Failed to launch the example", "Could not launch the example. Ensure that it has been " "built.", QMessageBox.Cancel)
def remove_user(self): reply = message.information(self, 'Remove User?', remove_user_message, message.Ok, message.Cancel) return reply == message.Ok
def remove_subreddit(self): reply = message.information(self, 'Remove Subreddit?', remove_subreddit_message, message.Ok, message.Cancel) return reply == message.Ok
def remove_user_list(self): reply = message.warning(self, 'Remove User List?', remove_user_list_message, message.Ok, message.Cancel) return reply == message.Ok
def remove_subreddit_list(self): reply = message.warning(self, 'Remove Subreddit List?', remove_subreddit_list_message, message.Ok, message.Cancel) return reply == message.Ok
def downloader_running_warning(self): text = 'The user finder is still currently running. Closing now may cause unexpected behaviour and corrupted ' \ 'files. Are you sure you want to close?' reply = message.warning(self, 'User Finder Still Running', text, message.Ok, message.Cancel) return reply == message.Ok
def update_reddit_objects_message(self): text = "Saved reddit objects are from a previous version of the program and are no\n" \ "longer compatible. These objects will now be updated to the latest version\n" \ "and the application will be saved. All of the objects settings and download list\n" \ "will be carried over to new objects.\n" \ "If you do not update these objects, the saved objects will not work correctly\n" \ "and will most likely cause the application to crash" reply = message.information(self, "Update Reddit Objects", text, message.Ok, message.Cancel) return reply == message.Ok
def unsaved_close_message(self): text = "Save changes to Downloader For Reddit?" reply = message.question(self, "Save Changes?", text, message.Yes | message.No | message.Cancel, message.Cancel) if reply == message.Yes: return "SAVE" elif reply == message.No: return "CLOSE" else: return "CANCEL"
def __init__(self): """ A small class to display an unfinished dialog message to the user. It is made into its own class so the names of the buttons can be renamed to be better understood in the situation it is used in """ QDialog.__init__(self) self.setupUi(self) self.button_box.button(QDialogButtonBox.Ok).setText('Close Anyway') self.button_box.button(QDialogButtonBox.Cancel).setText('Do Not Close') self.button_box.accepted.connect(self.accept) self.button_box.rejected.connect(self.close)
def set_databaseconnection(): ''' Setting connection with SQLite ''' filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'ResourceFiles', 'Database', 'Intg_osdag.sqlite') db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(filepath) # db.open() if not db.open(): QMessageBox.critical(None, qApp.tr("Cannot open database"), qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information" "how to build it.\n\n" "Click Cancel to exit."), QMessageBox.Cancel) return False # def set_databaseconnection(): # ''' # Setting connection with MySQL database # ''' # db = QSqlDatabase.addDatabase("QMYSQL") # db.setHostName("localhost") # db.setPort(3306) # db.setDatabaseName("OSDAG") # db.setUserName("root") # db.setPassword("root") # db.open() # logger.info("feching records from database")
def set_databaseconnection(): ''' Setting connection with SQLite ''' filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'ResourceFiles', 'Database', 'Intg_osdag.sqlite') db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(filepath) # db.open() if not db.open(): QMessageBox.critical(None, qApp.tr("Cannot open database"), qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information " "how to build it.\n\n" "Click Cancel to exit."), QMessageBox.Cancel) return False # def set_databaseconnection(): # ''' # Setting connection with MySQL database # ''' # db = QSqlDatabase.addDatabase("QMYSQL") # db.setHostName("localhost") # db.setPort(3306) # db.setDatabaseName("OSDAG") # db.setUserName("root") # db.setPassword("root") # db.open() # logger.info("feching records from database")
def set_databaseconnection(): ''' Setting connection with SQLite ''' filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'ResourceFiles', 'Database', 'Intg_osdag.sqlite') # filepath = "D:\EclipseWorkspace\OsdagWorkshop\Database\CleatSections" # db = QSqlDatabase.database("QSQLITE") # if db.IsValid(): # return True db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(filepath) # db.open() if not db.open(): QMessageBox.critical(None, qApp.tr("Cannot open database"), qApp.tr("Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information " "how to build it.\n\n" "Click Cancel to exit."), QMessageBox.Cancel) return False # def set_databaseconnection(): # ''' # Setting connection with MySQL database # ''' # db = QSqlDatabase.addDatabase("QMYSQL") # db.setHostName("localhost") # db.setPort(3306) # db.setDatabaseName("OSDAG") # db.setUserName("root") # db.setPassword("root") # db.open() # logger.info("feching records from database")