def get_permission(message=None, cancel=True, title='Permission', parent=None): """ Shows a permission message box :param message: str, message to show to the user :param cancel: bool, Whether the user can cancel the operation or not :param title: str, title of the window :param parent: QWidget :return: bool """ message_box = QMessageBox() message_box.setWindowTitle(title) flags = message_box.windowFlags( ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint if message: message_box.setText(message) if cancel: message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) else: message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) message_box.setWindowFlags(flags) result = message_box.exec_() if result == QMessageBox.Yes: return True elif result == QMessageBox.No: return False elif result == QMessageBox.Cancel: return None return None
def get_save_permission(message, file_path=None, title='Permission', parent=None): """ Shows a save path message box :param message: str, message to show to the user :param file_path: str, path you want to save :param title: str, title of the window :param parent: QWidget :return: bool """ message_box = QMessageBox() message_box.setWindowTitle(title) flags = message_box.windowFlags( ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint if file_path: path_message = 'Path: {}'.format(file_path) message_box.setInformativeText(path_message) message_box.setWindowFlags(flags) save = message_box.addButton('Save', QMessageBox.YesRole) no_save = message_box.addButton('Do not save', QMessageBox.NoRole) cancel = message_box.addButton('Cancel', QMessageBox.RejectRole) message_box.exec_() if message_box.clickedButton() == save: return True elif message_box.clickedButton() == no_save: return False elif message_box.clickedButton() == cancel: return None return None
def _thread_fun(self, queue, device, show_q): self.queue = queue self.show_q = show_q if self.use_buffer: self.input_buffer = {} try: self.setup_connections() self.start(device) if DEBUG: print(f"{self.name} starting...") try: while True: try: FPS.update(self.name) if self.use_buffer: self.consume_queue_data() self.run() except StopNodeException: break finally: self.end(device) except Exception as e: traceback.print_exc() instance = self.getWrapper().canvasRef().pyFlowInstance threading.Thread(target=stop_pipeline, args=(instance, )).start() msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error occured during node execution!") msg.setInformativeText(str(e)) msg.setDetailedText(traceback.format_exc()) msg.setWindowTitle("Node execution error!") msg.setStandardButtons(QMessageBox.Ok) msg.exec()
def accept(self, *args, **kwargs): selected_file, selected_dir, selected_file_name = self.get_result() if not os.path.isdir(selected_file): if os.path.exists(selected_file): super(BaseOpenFileDialog, self).accept() else: message_box = QMessageBox() message_box.setWindowTitle('Confirme file selection') message_box.setText( 'File "{0}" does not exists!'.format(selected_file)) message_box.exec_()
def show_info_dialog(self, msg, title='Info'): """ Shows a info dialog :param msg: str, message to show with the dialog :param title: str, title of the dialog """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Information) dialog.setWindowTitle(title) dialog.setText(msg) dialog.exec_()
class PopUpWarning(Error): """ display a popup error box with a custom message """ def __init__(self, _msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Warning") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(_msg) self.msg_box.exec_()
class SidNotValid(Error): """ Raised when the file can't be open """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Sid not valid") self.msg_box.exec_()
class NoSelectionError(Error): """ Raised when the user don't select a file needed """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Select a file !") self.msg_box.exec_()
class Error(Exception): """ Basic exeption class """ def __init__(self, msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(msg) self.msg_box.exec_()
def show_warning_dialog(self, msg, detail=None): """ Shows a warning dialog :param msg: str, message to show with the dialog :param detail: str, detail information to show (optional) """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Warning) dialog.setWindowTitle('Warning') dialog.setText(msg) if detail: dialog.setDetailedText(detail) dialog.exec_()
def _fun(self, device): try: self.setup_connections() self.run(device) except Exception as e: traceback.print_exc() self._terminate() msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error occured during node execution!") msg.setInformativeText(str(e)) msg.setDetailedText(traceback.format_exc()) msg.setWindowTitle("Node execution error!") msg.setStandardButtons(QMessageBox.Ok) msg.exec()
def accept(self, *args, **kwargs): selected_file, selected_dir, selected_filename = self.get_result() if not os.path.isdir(selected_file): if os.path.exists(selected_file): message_box = QMessageBox() message_box.setWindowTitle('Confirm File Selection') message_box.setText( 'File "%s" exists.\nDo you want to overwrite it?' % selected_file) message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) message_box.setDefaultButton(QMessageBox.No) rv = message_box.exec_() if rv == QMessageBox.Yes and not os.path.isdir(selected_file): super(BaseSaveFileDialog, self).accept() else: super(BaseSaveFileDialog, self).accept()
def _ask_user_subset_override(self, instance): from Qt.QtWidgets import QMessageBox title = "Subset \"{}\" already exist".format(instance["subset"]) text = ("Instance with subset name \"{}\" already exists." "\n\nDo you want to override existing?").format( instance["subset"]) dialog = QMessageBox() dialog.setWindowTitle(title) dialog.setText(text) dialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No) dialog.setDefaultButton(QMessageBox.Yes) dialog.exec_() if dialog.result() == QMessageBox.Yes: return True return False
def create_new_directory(self): name, ok = QInputDialog.getText(self, 'New directory name', 'Name:', QLineEdit.Normal, 'New Directory') if ok and name: path = os.path.join(self.directory, name) if os.path.exists(path): msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Directory already exists') msg_box.exec_() else: try: os.makedirs(path) self.update_view() except os.error as e: msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Cannot create directory') msg_box.exec_()