Source code for spinningdiskanalyzer.frontend.pages.pages

"""Implements the widget holding the wizard pages."""

from .select       import Select
from .original     import Original
from .background   import Background
from .threshold    import Threshold
from .disk         import Disk
from .segmentation import Segmentation
from .fit          import Fit

from PySide6.QtWidgets import QStackedWidget
from PySide6.QtWidgets import QMessageBox
from PySide6.QtCore    import Signal
from PySide6.QtCore    import QTimer


[docs] class Pages(QStackedWidget): """Holds the individual wizard pages.""" status_update = Signal(str) """Emitted with a message when the status bar should be updated.""" status_clear = Signal() """Emitted when the status bar can be cleared.""" def __init__(self, parent=None): super().__init__(parent) # Create pages. self.select = Select(parent=self) self.original = Original(parent=self) self.background = Background(parent=self) self.threshold = Threshold(parent=self) self.disk = Disk(parent=self) self.segmentation = Segmentation(parent=self) self.fit = Fit(parent=self) # Add pages in the intended order. self.pages = ( self.select, self.original, self.background, self.threshold, self.disk, self.segmentation, self.fit, ) for page in self.pages: self.addWidget(page) # Act whenever a "next" or "back" button is pressed. for page in self.pages: page.go_back.connect(self.go_back) page.go_next.connect(self.go_next) # Forward all status messages. for page in self.pages: page.status_update.connect(self.status_update) page.status_clear.connect(self.status_clear) # Enter the first page, but give it time to initialize first. self.timer = QTimer.singleShot(0, self.currentWidget().on_enter)
[docs] def go_next(self): """Orchestrates the transition from one page to the next.""" now = self.currentIndex() new = now + 1 if new < self.count(): try: self.currentWidget().on_leave() except Exception as error: QMessageBox.critical(self, 'Error', str(error)) return self.setCurrentIndex(new) self.currentWidget().on_enter()
[docs] def go_back(self): """Orchestrates the transition from one page to the previous one.""" now = self.currentIndex() new = now - 1 if new >= 0: self.setCurrentIndex(new)
[docs] def invalidate(self, page): """Invalidates results from given page and beyond.""" index = self.pages.index(page) for page in self.pages[index:]: page.invalidate()
[docs] def confirm_close(self): """Returns whether all pages can be closed.""" return all(page.confirm_close() for page in self.pages)