diff --git a/uilib/widgets/grainPreviewWidget.py b/uilib/widgets/grainPreviewWidget.py index f2651f9..2b70a00 100644 --- a/uilib/widgets/grainPreviewWidget.py +++ b/uilib/widgets/grainPreviewWidget.py @@ -20,6 +20,11 @@ def __init__(self): self.ui.tabRegression.setupImagePlot() self.ui.tabAreaGraph.setupGraphPlot() + # Used to navigate back to the tab the user was on after they clear alerts + self.lastNonAlertTab = 1 + + self.ui.tabWidget.currentChanged.connect(self.onTabChanged) + self.previewReady.connect(self.updateView) def loadGrain(self, grain): @@ -31,8 +36,18 @@ def loadGrain(self, grain): for alert in geomAlerts: if alert.level == motorlib.simResult.SimAlertLevel.ERROR: + # Go to alerts tab and clear up graph/images + self.ui.tabWidget.setCurrentIndex(0) + self.ui.tabFace.cleanup() + self.ui.tabRegression.cleanup() + self.ui.tabAreaGraph.cleanup() return + # If they were on the alert tab, go to their last image/graph tab. Otherwise, let them stay + if self.ui.tabWidget.currentIndex() == 0: + self.ui.tabWidget.setCurrentIndex(self.lastNonAlertTab) + + # Generate the contents to show on the image/graph tabs dataThread = Thread(target=self._genData, args=[grain]) dataThread.start() @@ -60,7 +75,12 @@ def updateView(self, data): self.ui.tabAreaGraph.cleanup() self.ui.tabAreaGraph.showGraph(points) + def onTabChanged(self, tabIndex): + if tabIndex != 0: + self.lastNonAlertTab = tabIndex + def cleanup(self): + self.lastNonAlertTab = 1 self.ui.tabAlerts.clear() self.ui.tabRegression.cleanup() self.ui.tabFace.cleanup() diff --git a/uilib/widgets/nozzlePreviewWidget.py b/uilib/widgets/nozzlePreviewWidget.py index 7c9cf22..470090e 100644 --- a/uilib/widgets/nozzlePreviewWidget.py +++ b/uilib/widgets/nozzlePreviewWidget.py @@ -42,6 +42,7 @@ def loadNozzle(self, nozzle): for alert in geomAlerts: if alert.level == motorlib.simResult.SimAlertLevel.ERROR: + self.ui.tabWidget.setCurrentIndex(0) return convAngle = radians(nozzle.props['convAngle'].getValue()) @@ -84,6 +85,8 @@ def loadNozzle(self, nozzle): self.lower.setPolygon(lower) self.rescale() + self.ui.tabWidget.setCurrentIndex(1) + def rescale(self): self.scene.setSceneRect(self.scene.itemsBoundingRect()) self.ui.tabCrossSection.fitInView(self.scene.sceneRect(), Qt.AspectRatioMode.KeepAspectRatio) diff --git a/uilib/widgets/propertyEditor.py b/uilib/widgets/propertyEditor.py index 2af8e38..834806e 100644 --- a/uilib/widgets/propertyEditor.py +++ b/uilib/widgets/propertyEditor.py @@ -12,6 +12,8 @@ class PropertyEditor(QWidget): valueChanged = pyqtSignal() + # Emitted when the user presses shift+enter and wants to close the collection editor + applyChanges = pyqtSignal() def __init__(self, parent, prop, preferences): super(PropertyEditor, self).__init__(QWidget(parent)) @@ -40,6 +42,7 @@ def __init__(self, parent, prop, preferences): self.editor.setValue(motorlib.units.convert(self.prop.getValue(), prop.unit, self.dispUnit)) self.editor.valueChanged.connect(self.valueChanged.emit) + self.editor.valueChanged.connect(self.checkApplyChanges) self.layout().addWidget(self.editor) elif isinstance(prop, motorlib.properties.IntProperty): @@ -115,3 +118,6 @@ def getValue(self): return self.editor.getTabs() return None + + def checkApplyChanges(self): + print('hello')