Source code for spinningdiskanalyzer.frontend.pages.page

"""Defines the base class for a wizard page."""

from PySide6.QtWidgets import QWidget
from PySide6.QtWidgets import QMessageBox
from PySide6.QtCore    import Signal
from PySide6.QtCore    import QCoreApplication
from PySide6.QtCore    import Qt


[docs] class Page(QWidget): """Represents an individual wizard page.""" go_next = Signal() """Emitted when all is good and we can proceed.""" go_back = Signal() """Emitted when the user wants to go back one step.""" status_update = Signal(str) """Emitted with a message when the status bar should be updated.""" status_clear = Signal() """Emitted when the status bar should be cleared."""
[docs] def on_enter(self): """Called by the parent widget when entering this page."""
[docs] def on_leave(self): """Called by the parent widget when leaving this page."""
[docs] def status(self, message: str): """Updates the status bar with the given message.""" self.status_update.emit(message)
[docs] def flush(self): """Displays status now even if application busy.""" QCoreApplication.processEvents()
[docs] def confirm_close(self): """ Returns whether this page may be closed right now. Reimplement this method in order to get user confirmation if, for example, background tasks are still running. """ return True
class NavNext: """ Mix-in class handling visibility of the "next" button. We are assuming the user interface contains a button named `next` alongside widgets named `content` and `settings`. The state of these (enabled, visible) is altered depending whether the app is busy or not. """ def mark_busy(self): """Has user interface indicate that application is busy with tasks.""" self.setCursor(Qt.BusyCursor) self.ui.content.setEnabled(False) self.ui.settings.setEnabled(False) self.ui.next.setVisible(False) def mark_ready(self): """Has user interface indicate that application is ready for input.""" self.status_clear.emit() self.ui.content.setEnabled(True) self.ui.settings.setEnabled(True) self.ui.next.setVisible(True) self.setCursor(Qt.ArrowCursor) class NavRedoNext: """ Mix-in class handling visibility of "redo" and "next" buttons. In addition to [](#NavNext), we are also managing a button named `redo`. The page this class here is mixed into must provide a method named `parameters_different()` that we call to decide which button to show. """ def mark_busy(self): """Has user interface indicate that application is busy with tasks.""" self.setCursor(Qt.BusyCursor) self.ui.content.setEnabled(False) self.ui.settings.setEnabled(False) self.ui.redo.setVisible(False) self.ui.next.setVisible(False) def mark_ready(self): """Has user interface indicate that application is ready for input.""" self.status_clear.emit() self.ui.content.setEnabled(True) self.ui.settings.setEnabled(True) self.navigation_update() self.setCursor(Qt.ArrowCursor) def navigation_update(self): """Updates the visibility of navigation buttons.""" if not self.ui.settings.isEnabled(): # For some reason we get called here when disabling the settings # panel in `mark_busy()`, but we don't want to interfere with the # visibility of the navigation buttons in that case. return if self.parameters_different(): self.ui.redo.setVisible(True) self.ui.next.setVisible(False) else: self.ui.redo.setVisible(False) self.ui.next.setVisible(True) class NavRedoExit: """ Mix-in class handling the redo and next buttons on a page. Like [](#NavRedoNext), but instead of the "next" button we have an "exit" button on the page. """ def mark_busy(self): """Has user interface indicate that application is busy with tasks.""" self.setCursor(Qt.BusyCursor) self.ui.content.setEnabled(False) self.ui.settings.setEnabled(False) self.ui.redo.setVisible(False) self.ui.exit.setVisible(False) def mark_ready(self): """Has user interface indicate that application is ready for input.""" self.status_clear.emit() self.ui.content.setEnabled(True) self.ui.settings.setEnabled(True) self.navigation_update() self.setCursor(Qt.ArrowCursor) def navigation_update(self): """Updates the visibility of navigation buttons.""" if not self.ui.settings.isEnabled(): # For some reason we get called here when disabling the settings # panel in `mark_busy()`, but we don't want to interfere with the # visibility of the navigation buttons in that case. return if self.parameters_different(): self.ui.redo.setVisible(True) self.ui.exit.setVisible(False) else: self.ui.redo.setVisible(False) self.ui.exit.setVisible(True) class ConfirmClose: """Mix-in class for page with a background task.""" def confirm_close(self): """ Returns whether this page may be closed right now. If the background task is currently running, we warn the user and ask for confirmation. """ if not self.task: return True question = ( 'Processing is under way. If you quit the application now, ' 'background processes may, in some cases, keep running. ' 'Keep an eye on the Task Manager and look for a Python process ' 'using a lot of CPU. Terminate it if that is the case.\n' '\n' 'Are you sure you want to quit now?' ) answer = QMessageBox.question(self, 'Confirm', question) if answer == QMessageBox.No: return False if self.task: self.task.blockSignals(True) self.task.terminate() self.task.wait() return True