Skip to content

Commit

Permalink
some UI updates on toggles/fields
Browse files Browse the repository at this point in the history
  • Loading branch information
rboston628 committed Dec 5, 2024
1 parent 40daa45 commit 036454c
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 66 deletions.
12 changes: 8 additions & 4 deletions src/snapred/ui/view/BackendRequestView.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from qtpy.QtWidgets import QGridLayout, QLineEdit, QWidget
from qtpy.QtWidgets import QGridLayout, QWidget

from snapred.backend.api.InterfaceController import InterfaceController
from snapred.ui.threading.worker_pool import WorkerPool
from snapred.ui.widget.LabeledCheckBox import LabeledCheckBox
from snapred.ui.widget.LabeledField import LabeledField
from snapred.ui.widget.LabeledToggle import LabeledToggle
from snapred.ui.widget.MultiSelectDropDown import MultiSelectDropDown
from snapred.ui.widget.SampleDropDown import SampleDropDown
from snapred.ui.widget.TrueFalseDropDown import TrueFalseDropDown
Expand All @@ -22,11 +23,14 @@ def __init__(self, parent=None):
self.layout = QGridLayout()
self.setLayout(self.layout)

def _labeledField(self, label, field=None):
return LabeledField(label, field, self)
def _labeledField(self, label, field=None, text=None):
return LabeledField(label, field=field, text=text, parent=self)

def _labeledLineEdit(self, label):
return LabeledField(label, QLineEdit(parent=self), self)
return LabeledField(label, field=None, text=None, parent=self)

def _labeledToggle(self, label, state):
return LabeledToggle(label, state, parent=self)

def _labeledCheckBox(self, label):
return LabeledCheckBox(label, self)
Expand Down
13 changes: 5 additions & 8 deletions src/snapred/ui/view/DiffCalAssessmentView.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from typing import List

from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import QComboBox, QGridLayout, QLabel, QMessageBox, QPushButton, QWidget
from qtpy.QtWidgets import QComboBox, QLabel, QMessageBox, QPushButton

from snapred.backend.dao.indexing.IndexEntry import IndexEntry
from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.presenter.CalibrationAssessmentPresenter import CalibrationAssessmentPresenter
from snapred.ui.widget.LabeledField import LabeledField
from snapred.ui.view.BackendRequestView import BackendRequestView


# TODO rebase on BackendRequestView
@Resettable
class DiffCalAssessmentView(QWidget):
class DiffCalAssessmentView(BackendRequestView):
"""
The DiffCalAssessmentView serves as a user interface within the SNAPRed application,
Expand All @@ -31,9 +30,6 @@ def __init__(self, parent=None):

self.presenter = CalibrationAssessmentPresenter(self)

self.layout = QGridLayout()
self.setLayout(self.layout)

self.interactionText = QLabel(
"Calibration Complete! Please examine the calibration assessment workspaces. "
"You can also load and examine previous calibration assessments for the same "
Expand All @@ -49,11 +45,12 @@ def __init__(self, parent=None):
self.calibrationRecordDropdown.setEnabled(True)
self.calibrationRecordDropdown.addItem("Select Calibration Record")
self.calibrationRecordDropdown.model().item(0).setEnabled(False)
self.calibrationRecordField = self._labeledField("Calibration Record:", field=self.calibrationRecordDropdown)

self.signalError.connect(self._displayError)

self.layout.addWidget(self.interactionText, 0, 0)
self.layout.addWidget(LabeledField("Calibration Record:", self.calibrationRecordDropdown, self), 1, 0)
self.layout.addWidget(self.calibrationRecordField, 1, 0)
self.layout.addWidget(self.loadButton, 1, 1)
self.layout.addWidget(self.placeHolder)

Expand Down
13 changes: 6 additions & 7 deletions src/snapred/ui/view/DiffCalRequestView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from snapred.meta.decorators.Resettable import Resettable
from snapred.meta.mantid.AllowedPeakTypes import SymmetricPeakEnum
from snapred.ui.view.BackendRequestView import BackendRequestView
from snapred.ui.widget.Toggle import Toggle


@Resettable
Expand All @@ -25,7 +24,7 @@ def __init__(self, samples=[], groups=[], parent=None):

# input fields
self.runNumberField = self._labeledField("Run Number")
self.litemodeToggle = self._labeledField("Lite Mode", Toggle(parent=self, state=True))
self.litemodeToggle = self._labeledToggle("Lite Mode", True)
self.fieldConvergenceThreshold = self._labeledField("Convergence Threshold")
self.fieldNBinsAcrossPeakWidth = self._labeledField("Bins Across Peak Width")

Expand All @@ -36,15 +35,15 @@ def __init__(self, samples=[], groups=[], parent=None):

# checkbox for removing background
# NOTE not enabled unless in CIS mode until remove event background is fixed -- then re-enable
self.removeBackgroundToggle = self._labeledField("RemoveBackground", Toggle(parent=self, state=False))
self.removeBackgroundToggle = self._labeledToggle("RemoveBackground", False)
self.removeBackgroundToggle.setEnabled(Config["cis_mode"])

# set field properties
self.litemodeToggle.setEnabled(True)
self.peakFunctionDropdown.setCurrentIndex(0)

# skip pixel calibration toggle
self.skipPixelCalToggle = self._labeledField("Skip Pixel Calibration", Toggle(parent=self, state=False))
self.skipPixelCalToggle = self._labeledToggle("Skip Pixel Calibration", False)

# add all widgets to layout
self.layout.addWidget(self.runNumberField, 0, 0)
Expand Down Expand Up @@ -75,10 +74,10 @@ def getRunNumber(self):
return self.runNumberField.text()

def getLiteMode(self):
return self.litemodeToggle.field.getState()
return self.litemodeToggle.getState()

def getRemoveBackground(self):
return self.removeBackgroundToggle.field.getState()
return self.removeBackgroundToggle.getState()

def getSkipPixelCalibration(self):
return self.skipPixelCalToggle.field.getState()
return self.skipPixelCalToggle.getState()
21 changes: 9 additions & 12 deletions src/snapred/ui/view/DiffCalSaveView.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import QComboBox, QGridLayout, QLabel, QLineEdit, QWidget
from qtpy.QtWidgets import QComboBox, QLabel

from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.widget.LabeledField import LabeledField
from snapred.ui.view.BackendRequestView import BackendRequestView


# TODO rebase on BackendRequestView
@Resettable
class DiffCalSaveView(QWidget):
class DiffCalSaveView(BackendRequestView):
"""
The DiffCalSaveView is a Qt widget designed for the final step in the calibration process within
Expand All @@ -24,33 +23,31 @@ class DiffCalSaveView(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.currentIterationText = "Current"
self.layout = QGridLayout()
self.setLayout(self.layout)

self.interactionText = QLabel("Assessment Complete! Would you like to save the calibration now?")

self.fieldRunNumber = LabeledField("Run Number :", QLineEdit(parent=self), self)
self.fieldRunNumber = self._labeledField("Run Number :")
self.fieldRunNumber.setEnabled(False)
self.signalRunNumberUpdate.connect(self._updateRunNumber)

self.fieldVersion = LabeledField("Version :", QLineEdit(parent=self), self)
self.fieldVersion = self._labeledField("Version :")
# add tooltip to leave blank for new version
self.fieldVersion.setToolTip("Leave blank for new version!")

self.fieldAppliesTo = LabeledField("Applies To :", QLineEdit(parent=self), self)
self.fieldAppliesTo = self._labeledField("Applies To :")
self.fieldAppliesTo.setToolTip(
"Determines which runs this calibration applies to. 'runNumber', '>runNumber', or \
'<runNumber', default is '>runNumber'."
)

self.fieldComments = LabeledField("Comments :", QLineEdit(parent=self), self)
self.fieldComments = self._labeledField("Comments :")
self.fieldComments.setToolTip("Comments about the calibration, documentation of important information.")

self.fieldAuthor = LabeledField("Author :", QLineEdit(parent=self), self)
self.fieldAuthor = self._labeledField("Author :")
self.fieldAuthor.setToolTip("Author of the calibration.")

self.iterationDropdown = QComboBox(parent=self)
self.iterationWidget = LabeledField("Iteration :", self.iterationDropdown, self)
self.iterationWidget = self._labeledField("Iteration :", field=self.iterationDropdown)
self.iterationWidget.setVisible(False)

self.layout.addWidget(self.interactionText)
Expand Down
14 changes: 6 additions & 8 deletions src/snapred/ui/view/DiffCalTweakPeakView.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import (
QHBoxLayout,
QLineEdit,
QMessageBox,
QPushButton,
)
Expand All @@ -22,7 +21,6 @@
from snapred.meta.mantid.AllowedPeakTypes import SymmetricPeakEnum
from snapred.meta.mantid.FitPeaksOutput import FitOutputEnum
from snapred.ui.view.BackendRequestView import BackendRequestView
from snapred.ui.widget.Toggle import Toggle


@Resettable
Expand Down Expand Up @@ -57,8 +55,8 @@ def __init__(self, samples=[], groups=[], parent=None):

# create the run number field and lite mode toggle
self.runNumberField = self._labeledField("Run Number")
self.litemodeToggle = self._labeledField("Lite Mode", Toggle(parent=self, state=True))
self.maxChiSqField = self._labeledField("Max Chi Sq", QLineEdit(str(self.MAX_CHI_SQ)))
self.litemodeToggle = self._labeledToggle("Lite Mode", True)
self.maxChiSqField = self._labeledField("Max Chi Sq", text=str(self.MAX_CHI_SQ))
self.signalRunNumberUpdate.connect(self._updateRunNumber)
self.signalMaxChiSqUpdate.connect(self._updateMaxChiSq)

Expand All @@ -80,10 +78,10 @@ def __init__(self, samples=[], groups=[], parent=None):
x.setEnabled(False)

# create the peak adjustment controls
self.fieldXtalDMin = self._labeledField("xtal dMin", QLineEdit(str(self.XTAL_DMIN)))
self.fieldXtalDMax = self._labeledField("xtal dMax", QLineEdit(str(self.XTAL_DMAX)))
self.fieldFWHMleft = self._labeledField("FWHM left", QLineEdit(str(self.FWHM.left)))
self.fieldFWHMright = self._labeledField("FWHM right", QLineEdit(str(self.FWHM.right)))
self.fieldXtalDMin = self._labeledField("xtal dMin", text=str(self.XTAL_DMIN))
self.fieldXtalDMax = self._labeledField("xtal dMax", text=str(self.XTAL_DMAX))
self.fieldFWHMleft = self._labeledField("FWHM left", text=str(self.FWHM.left))
self.fieldFWHMright = self._labeledField("FWHM right", text=str(self.FWHM.right))
peakControlLayout = QHBoxLayout()
peakControlLayout.addWidget(self.fieldXtalDMin)
peakControlLayout.addWidget(self.fieldXtalDMax)
Expand Down
3 changes: 1 addition & 2 deletions src/snapred/ui/view/NormalizationRequestView.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.view.BackendRequestView import BackendRequestView
from snapred.ui.widget.Toggle import Toggle


@Resettable
Expand All @@ -21,7 +20,7 @@ def __init__(self, samplePaths=[], groups=[], parent=None):

# input fields
self.runNumberField = self._labeledLineEdit("Run Number:")
self.litemodeToggle = self._labeledField("Lite Mode", Toggle(parent=self, state=True))
self.litemodeToggle = self._labeledToggle("Lite Mode", True)
self.backgroundRunNumberField = self._labeledLineEdit("Background Run Number:")

# drop downs
Expand Down
9 changes: 4 additions & 5 deletions src/snapred/ui/view/NormalizationTweakPeakView.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import (
QHBoxLayout,
QLineEdit,
QMessageBox,
QPushButton,
)
Expand Down Expand Up @@ -51,8 +50,8 @@ def __init__(self, samples=[], groups=[], parent=None):
super().__init__(parent=parent)

# create the run number fields
self.fieldRunNumber = self._labeledField("Run Number", QLineEdit(parent=self))
self.fieldBackgroundRunNumber = self._labeledField("Background Run Number", QLineEdit(parent=self))
self.fieldRunNumber = self._labeledField("Run Number")
self.fieldBackgroundRunNumber = self._labeledField("Background Run Number")
# connect them to signals
self.signalRunNumberUpdate.connect(self._updateRunNumber)
self.signalBackgroundRunNumberUpdate.connect(self._updateBackgroundRunNumber)
Expand All @@ -72,8 +71,8 @@ def __init__(self, samples=[], groups=[], parent=None):

# create the adjustment controls
self.smoothingSlider = self._labeledField("Smoothing", SmoothingSlider())
self.fieldXtalDMin = self._labeledField("xtal dMin", QLineEdit(str(self.XTAL_DMIN)))
self.fieldXtalDMax = self._labeledField("xtal dMax", QLineEdit(str(self.XTAL_DMAX)))
self.fieldXtalDMin = self._labeledField("xtal dMin", text=str(self.XTAL_DMIN))
self.fieldXtalDMax = self._labeledField("xtal dMax", text=str(self.XTAL_DMAX))
peakControlLayout = QHBoxLayout()
peakControlLayout.addWidget(self.smoothingSlider, 2)
peakControlLayout.addWidget(self.fieldXtalDMin)
Expand Down
3 changes: 1 addition & 2 deletions src/snapred/ui/view/reduction/ReductionRequestView.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from snapred.backend.log.logger import snapredLogger
from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.view.BackendRequestView import BackendRequestView
from snapred.ui.widget.Toggle import Toggle

logger = snapredLogger.getLogger(__name__)

Expand Down Expand Up @@ -52,7 +51,7 @@ def __init__(
self.runNumberDisplay.setSortingEnabled(False)

# Lite mode toggle, pixel masks dropdown, and retain unfocused data checkbox
self.liteModeToggle = self._labeledField("Lite Mode", Toggle(parent=self, state=True))
self.liteModeToggle = self._labeledToggle("Lite Mode", True)
self.retainUnfocusedDataCheckbox = self._labeledCheckBox("Retain Unfocused Data")
self.convertUnitsDropdown = self._sampleDropDown(
"Convert Units", ["TOF", "dSpacing", "Wavelength", "MomentumTransfer"]
Expand Down
3 changes: 2 additions & 1 deletion src/snapred/ui/widget/LabeledField.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class LabeledField(QWidget):
def __init__(self, label, field=None, parent=None):
def __init__(self, label, field=None, text=None, parent=None):
super(LabeledField, self).__init__(parent)
self.setStyleSheet("background-color: #F5E9E2;")
layout = QHBoxLayout()
Expand All @@ -13,6 +13,7 @@ def __init__(self, label, field=None, parent=None):
self._field = field
else:
self._field = QLineEdit(parent=self)
self._field.setText(text)

layout.addWidget(self._label)
layout.addWidget(self._field)
Expand Down
30 changes: 30 additions & 0 deletions src/snapred/ui/widget/LabeledToggle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QHBoxLayout, QLabel, QWidget

from snapred.ui.widget.Toggle import Toggle


class LabeledToggle(QWidget):
stateChanged = Signal(bool)

def __init__(self, label, state, parent=None):
super(LabeledToggle, self).__init__(parent)
self.setStyleSheet("background-color: #F5E9E2;")

self._label = QLabel(label + ":", self)
self._toggle = Toggle(state=state, parent=self)

layout = QHBoxLayout()
layout.addWidget(self._label)
layout.addWidget(self._toggle)
layout.addStretch(1)
layout.setContentsMargins(5, 5, 5, 5)
self.setLayout(layout)

self._toggle.stateChanged.connect(self.stateChanged)

def getState(self):
return self._toggle.getState()

def setState(self, state):
self._toggle.setState(state)
11 changes: 8 additions & 3 deletions src/snapred/ui/widget/Toggle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from qtpy.QtCore import Property, QEasingCurve, QPropertyAnimation, Qt
from qtpy.QtCore import Property, QEasingCurve, QPropertyAnimation, Qt, Signal, Slot
from qtpy.QtGui import QLinearGradient, QPainter
from qtpy.QtWidgets import QWidget


class Toggle(QWidget):
stateChanged = Signal(bool)

def __init__(self, parent=None, state=False):
super().__init__(parent=parent)
self._state = state
Expand All @@ -28,9 +30,12 @@ def ellipsePosition(self, pos):
def toggle(self):
self.setState(not self._state)

@Slot(bool)
def setState(self, state):
self._state = state
self.animateClick()
if self._state != state:
self._state = state
self.stateChanged.emit(state)
self.animateClick()

def connectUpdate(self, update): # noqa: ARG002
self.toggleAnimation.finished.connect(update)
Expand Down
Loading

0 comments on commit 036454c

Please sign in to comment.