def askWhichAction(self): """ Ask the user what to do if no chunk worked: - Try again - Re-test the current last working chunk - Cancel :return: An integer value indicating the pressed button: - 0 if the user wants to try again - 1 if the user wants to re-test - 2 if the user wants to cancel """ messageBox = QMessageBox() messageBox.setWindowTitle(Strings.searcherTabAskActionMessageBoxTitle) messageBox.setText(Strings.searcherTabAskActionMessageBoxText) tryAgainButton = messageBox.addButton( Strings.searcherTabAskActionMessageBoxButtonTryAgainText, QMessageBox.RejectRole) reTestButton = messageBox.addButton( Strings.searcherTabAskActionMessageBoxButtonReTestText, QMessageBox.NoRole) cancelButton = messageBox.addButton( Strings.searcherTabAskActionMessageBoxButtonCancelText, QMessageBox.YesRole) messageBox.exec_() if messageBox.clickedButton() == tryAgainButton: return 0 elif messageBox.clickedButton() == reTestButton: return 1 elif messageBox.clickedButton() == cancelButton: return 2
def query_user(platform): msg_box = QMessageBox() msg_box.setWindowTitle("This plaform is not installed!") ok = msg_box.addButton("Install now", QMessageBox.AcceptRole) later = msg_box.addButton("Install later", QMessageBox.RejectRole) msg_box.setEscapeButton(later) msg_box.setDefaultButton(ok) msg_box.setIcon(QMessageBox.Warning) msg_box.setText("Do you want to install target\n{} ?".format(platform)) msg_box.exec_() return msg_box.clickedButton() == ok
def append_output(self): if self.process is None: # Can happen when manually interrupting return lines = strip_ansi_codes(to_str(self.process.readAllStandardOutput())) self.add_output_lines(lines) # We manually deal with keyboard input in the output if 'Export already made! Do you want to erase everything? (y)es / (n)o' in lines: msg = QMessageBox() msg.setIcon(QMessageBox.Question) msg.setWindowTitle('Erase everything?') msg.setText( 'Export already made! Do you want to erase everything?') msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) answer = msg.exec_() if answer == QMessageBox.Yes: answer_string = 'y' else: answer_string = 'n' elif 'Do you want SpyKING CIRCUS to export PCs? (a)ll / (s)ome / (n)o' in lines: msg = QMessageBox() msg.setIcon(QMessageBox.Question) msg.setWindowTitle('Export PCs?') msg.setText('Do you want SpyKING CIRCUS to export PCs?') no_button = msg.addButton('No', QMessageBox.NoRole) some_button = msg.addButton('Some', QMessageBox.YesRole) all_button = msg.addButton('All', QMessageBox.YesRole) msg.exec_() if msg.clickedButton() == no_button: answer_string = 'n' elif msg.clickedButton() == some_button: answer_string = 's' elif msg.clickedButton() == all_button: answer_string = 'a' else: answer_string = 'n' else: answer_string = '' if answer_string: self.process.write(answer_string + '\n') self.add_output_lines(answer_string + '\n')
def closeEvent(self, event): if self.process is not None: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle('Confirm process interruption') msg.setText('Closing the window will terminate the running process. ' 'Do you really want to exit?') msg.setInformativeText('Interrupting the process may leave partly ' 'created files that cannot be used for ' 'further analysis.') close_button = msg.addButton("Stop and close", QMessageBox.YesRole) cancel_button = msg.addButton("Cancel", QMessageBox.NoRole) msg.setDefaultButton(cancel_button) msg.exec_() if msg.clickedButton() == close_button: self.stop(force=True) super(LaunchGUI, self).closeEvent(event) else: event.ignore()
def stop(self, force=False): if self.process is not None: if not force: msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle('Confirm process termination') msg.setText( 'This will terminate the running process. Are you sure ' 'you want to do this?') msg.setInformativeText( 'Interrupting the process may leave partly ' 'created files that cannot be used for ' 'further analysis.') msg.addButton('Stop process', QMessageBox.YesRole) cancel_button = msg.addButton('Cancel', QMessageBox.NoRole) msg.setDefaultButton(cancel_button) msg.exec_() if msg.clickedButton() == cancel_button: # Continue to run return self._interrupted = True # Terminate child processes as well pid = int(self.process.pid()) if sys.platform == 'win32' and pid != 0: # The returned value is not a PID but a pointer lp = ctypes.cast(pid, LPWinProcInfo) pid = lp.contents.dwProcessID if pid != 0: process = psutil.Process(pid) children = process.children(recursive=True) for proc in children: proc.terminate() gone, alive = psutil.wait_procs(children, timeout=3) for proc in alive: proc.kill() self.process.terminate() self.process = None
def __abortComputationBox(self): tit = self.tr("Aborting Batch Computation") txt = self.tr("Reduce is currently evaluating several groups in " "batch. Do you want to interrupt only the current " "computation or all?") diag = QMessageBox(self.model.controller.mainWindow) diag.setWindowTitle(tit) diag.setIcon(QMessageBox.Question) diag.setText(txt) abortAll = diag.addButton("Abort All",QMessageBox.YesRole) abortCurrent = diag.addButton("Abort Current",QMessageBox.YesRole) cancel = diag.addButton(QMessageBox.StandardButton.Cancel) diag.setDefaultButton(abortAll) diag.setEscapeButton(cancel) diag.setWindowModality(Qt.WindowModal) diag.exec_() ans = diag.clickedButton() if ans == abortAll: return 'all' elif ans == abortCurrent: return 'current' elif ans == cancel: return 'cancel' traceLogger.critical("unidentifiable button %s" % ans)