From 462e95910058871c369e870f75d52a8fd9ba6fbe Mon Sep 17 00:00:00 2001 From: gwm17 Date: Wed, 29 Mar 2023 16:02:25 -0400 Subject: [PATCH] Added delete functionality to SPANC calibration peaks --- spspy/Spanc.py | 6 ++++++ spspy/SpancUI.py | 3 +++ spspy/ui/PeakDialog.py | 12 +++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spspy/Spanc.py b/spspy/Spanc.py index 5a2117f..30e5b2d 100644 --- a/spspy/Spanc.py +++ b/spspy/Spanc.py @@ -79,6 +79,12 @@ class Spanc: data.peakID = len(self.calibrations) self.calibrations[data.peakID] = data return + + def remove_calibration(self, data: Peak) -> bool: + if data.peakID not in self.calibrations.keys(): + return False + self.calibrations.pop(data.peakID) + return True def add_output(self, data: Peak) -> None: if data.peakID == INVALID_PEAK_ID: diff --git a/spspy/SpancUI.py b/spspy/SpancUI.py index c3946a1..4c8d569 100644 --- a/spspy/SpancUI.py +++ b/spspy/SpancUI.py @@ -237,8 +237,11 @@ class SpancGUI(QMainWindow): peakData = self.spanc.calibrations[row] calDia = PeakDialog(PeakType.CALIBRATION, self.spanc.reactions.keys(), self, peak=peakData) calDia.new_peak.connect(self.spanc.add_calibration) + calDia.delete_peak.connect(self.spanc.remove_calibration) if calDia.exec(): self.update_calibration_table() + if self.spanc.isFit == True: + self.handle_run_fit() return def handle_new_output(self) -> None: diff --git a/spspy/ui/PeakDialog.py b/spspy/ui/PeakDialog.py index 782be62..4b0550c 100644 --- a/spspy/ui/PeakDialog.py +++ b/spspy/ui/PeakDialog.py @@ -2,11 +2,12 @@ from ..Spanc import Peak, PeakType, INVALID_PEAK_ID from PySide6.QtWidgets import QLabel from PySide6.QtWidgets import QVBoxLayout, QFormLayout, QGroupBox from PySide6.QtWidgets import QComboBox, QDoubleSpinBox -from PySide6.QtWidgets import QDialog, QDialogButtonBox +from PySide6.QtWidgets import QDialog, QDialogButtonBox, QPushButton from PySide6.QtCore import Signal class PeakDialog(QDialog): new_peak = Signal(Peak) + delete_peak = Signal(Peak) def __init__(self, peakType: PeakType, rxnList: list[str], parent=None, peak: Peak=None): super().__init__(parent) @@ -29,6 +30,9 @@ class PeakDialog(QDialog): self.set_calibration_inputs(peak) self.peakID = peak.peakID self.buttonBox.accepted.connect(self.send_update_calibration_peak) + self.deleteButton = QPushButton("Delete", self) + self.deleteButton.clicked.connect(self.send_delete_calibration_peak) + self.centralLayout.addWidget(self.deleteButton) else: self.buttonBox.accepted.connect(self.send_calibration_peak) elif peakType == PeakType.OUTPUT: @@ -114,6 +118,12 @@ class PeakDialog(QDialog): peak = Peak(excitation=self.exInput.value(), excitationErr=self.uexInput.value(), position=self.xInput.value(), positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=self.peakID) self.new_peak.emit(peak) + + def send_delete_calibration_peak(self) -> None: + peak = Peak(excitation=self.exInput.value(), excitationErr=self.uexInput.value(), position=self.xInput.value(), + positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(), rxnName=self.rxnNameBox.currentText(), peakID=self.peakID) + self.delete_peak.emit(peak) + self.done(3) def send_output_peak(self) -> None: peak = Peak(position=self.xInput.value(), positionErrStat=self.uxstatInput.value(), positionErrSys=self.uxsysInput.value(),