-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add UI elements for dead time settings
- Loading branch information
Showing
7 changed files
with
398 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# third party imports | ||
from qtpy.QtWidgets import QGroupBox, QHBoxLayout, QCheckBox, QPushButton | ||
|
||
|
||
class DeadTimeEntryPoint(QGroupBox): | ||
def __init__(self, title='Dead Time Correction'): | ||
super().__init__(title) | ||
self.initUI() | ||
|
||
def initUI(self): | ||
# Set the stylesheet for the group box to have a border | ||
self.setStyleSheet( | ||
"QGroupBox {" | ||
" border: 1px solid gray;" | ||
" border-radius: 5px;" | ||
" margin-top: 1ex;" # space above the group box | ||
"} " | ||
"QGroupBox::title {" | ||
" subcontrol-origin: margin;" | ||
" subcontrol-position: top center;" # align the title to the center | ||
" padding: 0 3px;" | ||
"}" | ||
) | ||
|
||
self.applyCheckBox = QCheckBox('Apply', self) | ||
self.applyCheckBox.stateChanged.connect(self.toggleSettingsButton) | ||
self.settingsButton = QPushButton('Settings', self) | ||
self.settingsButton.setEnabled(self.applyCheckBox.isChecked()) # enabled if we use the correction | ||
|
||
# Create a horizontal layout for the checkbox and settings button | ||
hbox = QHBoxLayout() | ||
hbox.addWidget(self.applyCheckBox) | ||
hbox.addWidget(self.settingsButton) | ||
hbox.addStretch(1) # This adds a stretchable space after the button (optional) | ||
|
||
# Set the layout for the group box | ||
self.setLayout(hbox) | ||
|
||
def toggleSettingsButton(self, state): | ||
# Enable the settings button if the checkbox is checked, disable otherwise | ||
self.settingsButton.setEnabled(state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# third-party imports | ||
from qtpy.QtWidgets import QDialog, QWidget | ||
from xml.dom.minidom import Document, Element | ||
from typing import Any, Callable, Dict | ||
import os | ||
|
||
from qtpy.uic import loadUi | ||
|
||
|
||
class DeadTimeSettingsModel(): | ||
"""Stores all options for the dead time correction. These are global options""" | ||
|
||
apply_deadtime: bool = False | ||
paralyzable: bool = True | ||
dead_time: float = 4.2 | ||
tof_step: float = 100.0 | ||
|
||
class DeadTimeSettingsView(QDialog): | ||
""" | ||
Dialog to choose the dead time correction options. | ||
""" | ||
|
||
def __init__(self, parent: QWidget): | ||
super().__init__(parent) | ||
filepath = os.path.join(os.path.dirname(__file__), "deadtime_settings.ui") | ||
self.ui = loadUi(filepath, baseinstance=self) | ||
self.options = self.get_state_from_form() | ||
|
||
def set_state(self, paralyzable, dead_time, tof_step): | ||
""" | ||
Store options and populate the form | ||
:param apply_correction: If True, dead time correction will be applied | ||
:param paralyzable: If True, a paralyzable correction will be used | ||
:param dead_time: Value of the dead time in micro second | ||
:param tof_step: TOF binning in micro second | ||
""" | ||
self.ui.use_paralyzable.setChecked(paralyzable) | ||
self.ui.dead_time_value.setValue(dead_time) | ||
self.ui.dead_time_tof.setValue(tof_step) | ||
self.options = self.get_state_from_form() | ||
|
||
def get_state_from_form(self) -> dict: | ||
r"""Read the options from the form. | ||
Returns | ||
------- | ||
Dictionary whose keys must match fields of class `DeadTimeSettingsModel` | ||
""" | ||
return { | ||
'paralyzable': self.ui.use_paralyzable.isChecked(), | ||
'dead_time': self.ui.dead_time_value.value(), | ||
'tof_step': self.ui.dead_time_tof.value(), | ||
} | ||
|
||
def accept(self): | ||
""" | ||
Read in the options on the form when the OK button is | ||
clicked. | ||
""" | ||
self.options = self.get_state_from_form() | ||
self.close() |
Oops, something went wrong.