mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-12-22 23:57:51 +00:00
Improved layout.
This commit is contained in:
parent
fb002d0745
commit
d094d7eae9
5 changed files with 200 additions and 33 deletions
|
@ -10,9 +10,13 @@ class MeasurementController(ModuleController):
|
||||||
|
|
||||||
def start_measurement(self):
|
def start_measurement(self):
|
||||||
logger.debug("Start measurement clicked")
|
logger.debug("Start measurement clicked")
|
||||||
self.module.nqrduck_signal.emit("start_measurement", None)
|
self.module.view.measurement_dialog.show()
|
||||||
|
self.module.nqrduck_signal.emit("start_measurement", None)
|
||||||
|
|
||||||
def process_signals(self, key: str, value: Measurement):
|
def process_signals(self, key: str, value: Measurement):
|
||||||
if key == "single_measurement":
|
logger.debug("Measurement Dialog is visible: " + str(self.module.view.measurement_dialog.isVisible()))
|
||||||
|
|
||||||
|
if key == "measurement_data" and self.module.view.measurement_dialog.isVisible():
|
||||||
logger.debug("Received single measurement.")
|
logger.debug("Received single measurement.")
|
||||||
self.module.model.single_measurement = value
|
self.module.model.single_measurement = value
|
||||||
|
self.module.view.measurement_dialog.hide()
|
||||||
|
|
BIN
src/nqrduck_measurement/resources/duck_kick.gif
Normal file
BIN
src/nqrduck_measurement/resources/duck_kick.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
|
@ -11,7 +11,7 @@
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -21,9 +21,57 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="settingsLayout" stretch="0,0,0,0,0">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="titleLable">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Single Frequency Measurement: </string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="spectrometerLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="spectrometerLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Spectrometer:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Target Frequency</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="lineEdit_2"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Averages</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="lineEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="buttonStart">
|
<widget class="QPushButton" name="buttonStart">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -32,18 +80,31 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labelSpectrometer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>Spectrometer:</string>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="plotterLayout" stretch="0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="MplWidget" name="plotter" native="true"/>
|
<widget class="MplWidget" name="plotter" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -55,7 +116,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>MplWidget</class>
|
<class>MplWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>contrib/mplwidget.h</header>
|
<header>nqrduck/contrib/mplwidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import logging
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PyQt6.QtWidgets import QWidget
|
from pathlib import Path
|
||||||
from PyQt6.QtCore import pyqtSlot
|
import matplotlib as mpl
|
||||||
from .widget import Ui_Form
|
from PyQt6.QtWidgets import QWidget, QDialog, QLabel, QVBoxLayout
|
||||||
|
from PyQt6.QtGui import QMovie
|
||||||
|
from PyQt6.QtCore import pyqtSlot, Qt
|
||||||
from nqrduck.module.module_view import ModuleView
|
from nqrduck.module.module_view import ModuleView
|
||||||
|
from .widget import Ui_Form
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -11,15 +14,50 @@ class MeasurementView(ModuleView):
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
super().__init__(module)
|
super().__init__(module)
|
||||||
|
|
||||||
|
mpl.rcParams.update({
|
||||||
|
"figure.facecolor": (0.0, 0.0, 0.0, 0.00), # transparent
|
||||||
|
"axes.facecolor": (0.0, 1.0, 0.0, 0.03), # green
|
||||||
|
"savefig.facecolor": (0.0, 0.0, 0.0, 0.0), # transparent
|
||||||
|
})
|
||||||
|
|
||||||
|
# Set custom matplotlib parameters
|
||||||
|
mpl.rcParams['figure.subplot.bottom'] = 0.2
|
||||||
|
mpl.rcParams['axes.linewidth'] = 1.5
|
||||||
|
mpl.rcParams['xtick.major.width'] = 1.5
|
||||||
|
mpl.rcParams['ytick.major.width'] = 1.5
|
||||||
|
mpl.rcParams['xtick.minor.width'] = 1.5
|
||||||
|
mpl.rcParams['ytick.minor.width'] = 1.5
|
||||||
|
mpl.rcParams['xtick.major.size'] = 6
|
||||||
|
mpl.rcParams['ytick.major.size'] = 6
|
||||||
|
mpl.rcParams['xtick.minor.size'] = 4
|
||||||
|
mpl.rcParams['ytick.minor.size'] = 4
|
||||||
|
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
self._ui_form = Ui_Form()
|
self._ui_form = Ui_Form()
|
||||||
self._ui_form.setupUi(self)
|
self._ui_form.setupUi(self)
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
|
|
||||||
|
# Initialize plotter
|
||||||
|
self.init_plotter()
|
||||||
|
logger.debug("Facecolor %s" % str(self._ui_form.plotter.canvas.ax.get_facecolor()))
|
||||||
|
|
||||||
|
# Measurement dialog
|
||||||
|
self.measurement_dialog = self.MeasurementDialog()
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
self.module.model.single_measurement_changed.connect(self.update_single_measurement)
|
self.module.model.single_measurement_changed.connect(self.update_single_measurement)
|
||||||
self._ui_form.buttonStart.clicked.connect(self.on_measurement_start_button_clicked)
|
self._ui_form.buttonStart.clicked.connect(self.on_measurement_start_button_clicked)
|
||||||
|
|
||||||
|
def init_plotter(self):
|
||||||
|
plotter = self._ui_form.plotter
|
||||||
|
plotter.canvas.ax.set_xlim(0, 100)
|
||||||
|
plotter.canvas.ax.set_ylim(0, 1)
|
||||||
|
plotter.canvas.ax.set_xlabel("Time (µs)")
|
||||||
|
plotter.canvas.ax.set_ylabel("Amplitude (a.u.)")
|
||||||
|
plotter.canvas.ax.set_title("Measurement data")
|
||||||
|
plotter.canvas.ax.grid()
|
||||||
|
plotter.canvas.draw()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def update_single_measurement(self):
|
def update_single_measurement(self):
|
||||||
logger.debug("Updating single measurement view.")
|
logger.debug("Updating single measurement view.")
|
||||||
|
@ -28,15 +66,44 @@ class MeasurementView(ModuleView):
|
||||||
tdy = self.module.model.single_measurement.tdy
|
tdy = self.module.model.single_measurement.tdy
|
||||||
#correcting a offset in the time domain by subtracting the mean
|
#correcting a offset in the time domain by subtracting the mean
|
||||||
tdy_mean = tdy[:,0]-np.mean(tdy)
|
tdy_mean = tdy[:,0]-np.mean(tdy)
|
||||||
self._ui_form.plotter.canvas.ax.clear() # Clear the axes for the new plot
|
|
||||||
self._ui_form.plotter.canvas.ax.plot(tdx, tdy_mean)
|
|
||||||
self._ui_form.plotter.canvas.ax.set_xlabel("Time (µs)")
|
self._ui_form.plotter.canvas.ax.set_xlabel("Time (µs)")
|
||||||
self._ui_form.plotter.canvas.ax.set_ylabel("Amplitude (a.u.)")
|
self._ui_form.plotter.canvas.ax.set_ylabel("Amplitude (a.u.)")
|
||||||
self._ui_form.plotter.canvas.ax.set_title("Single measurement")
|
self._ui_form.plotter.canvas.ax.set_title("Measurement data")
|
||||||
|
self._ui_form.plotter.canvas.ax.clear() # Clear the axes for the new plot
|
||||||
|
self._ui_form.plotter.canvas.ax.plot(tdx, tdy_mean)
|
||||||
self._ui_form.plotter.canvas.ax.grid()
|
self._ui_form.plotter.canvas.ax.grid()
|
||||||
self._ui_form.plotter.canvas.draw()
|
self._ui_form.plotter.canvas.draw()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_measurement_start_button_clicked(self):
|
def on_measurement_start_button_clicked(self):
|
||||||
logger.debug("Measurement start button clicked.")
|
logger.debug("Measurement start button clicked.")
|
||||||
self.module.controller.start_measurement()
|
self.module.controller.start_measurement()
|
||||||
|
|
||||||
|
class MeasurementDialog(QDialog):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.finished = True
|
||||||
|
self.setModal(True)
|
||||||
|
self.setWindowFlag(Qt.WindowType.FramelessWindowHint)
|
||||||
|
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||||
|
|
||||||
|
path = Path(__file__).parent
|
||||||
|
self.spinner_movie = QMovie(str(path / "resources/duck_kick.gif")) # Replace with your own spinner gif
|
||||||
|
self.spinner_label = QLabel(self)
|
||||||
|
self.spinner_label.setMovie(self.spinner_movie)
|
||||||
|
|
||||||
|
self.layout = QVBoxLayout(self)
|
||||||
|
self.layout.addWidget(self.spinner_label)
|
||||||
|
|
||||||
|
self.spinner_movie.finished.connect(self.on_movie_finished)
|
||||||
|
|
||||||
|
self.spinner_movie.start()
|
||||||
|
|
||||||
|
def on_movie_finished(self):
|
||||||
|
self.finished = True
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
while not self.finished:
|
||||||
|
continue
|
||||||
|
self.spinner_movie.stop()
|
||||||
|
super().hide()
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Ui_Form(object):
|
||||||
def setupUi(self, Form):
|
def setupUi(self, Form):
|
||||||
Form.setObjectName("Form")
|
Form.setObjectName("Form")
|
||||||
Form.resize(1920, 1080)
|
Form.resize(1920, 1080)
|
||||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Minimum)
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||||
sizePolicy.setHorizontalStretch(0)
|
sizePolicy.setHorizontalStretch(0)
|
||||||
sizePolicy.setVerticalStretch(0)
|
sizePolicy.setVerticalStretch(0)
|
||||||
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
|
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
|
||||||
|
@ -22,21 +22,54 @@ class Ui_Form(object):
|
||||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||||
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
|
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
|
||||||
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
|
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
|
||||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
|
self.settingsLayout = QtWidgets.QVBoxLayout()
|
||||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
self.settingsLayout.setObjectName("settingsLayout")
|
||||||
|
self.titleLable = QtWidgets.QLabel(parent=Form)
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
font.setWeight(75)
|
||||||
|
self.titleLable.setFont(font)
|
||||||
|
self.titleLable.setObjectName("titleLable")
|
||||||
|
self.settingsLayout.addWidget(self.titleLable)
|
||||||
|
self.spectrometerLayout = QtWidgets.QHBoxLayout()
|
||||||
|
self.spectrometerLayout.setObjectName("spectrometerLayout")
|
||||||
|
self.spectrometerLabel = QtWidgets.QLabel(parent=Form)
|
||||||
|
self.spectrometerLabel.setObjectName("spectrometerLabel")
|
||||||
|
self.spectrometerLayout.addWidget(self.spectrometerLabel)
|
||||||
|
self.settingsLayout.addLayout(self.spectrometerLayout)
|
||||||
|
self.gridLayout = QtWidgets.QGridLayout()
|
||||||
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
|
self.label = QtWidgets.QLabel(parent=Form)
|
||||||
|
self.label.setObjectName("label")
|
||||||
|
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
|
||||||
|
self.lineEdit_2 = QtWidgets.QLineEdit(parent=Form)
|
||||||
|
self.lineEdit_2.setObjectName("lineEdit_2")
|
||||||
|
self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1)
|
||||||
|
self.label_2 = QtWidgets.QLabel(parent=Form)
|
||||||
|
self.label_2.setObjectName("label_2")
|
||||||
|
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
|
||||||
|
self.lineEdit = QtWidgets.QLineEdit(parent=Form)
|
||||||
|
self.lineEdit.setObjectName("lineEdit")
|
||||||
|
self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
|
||||||
|
self.settingsLayout.addLayout(self.gridLayout)
|
||||||
self.buttonStart = QtWidgets.QPushButton(parent=Form)
|
self.buttonStart = QtWidgets.QPushButton(parent=Form)
|
||||||
self.buttonStart.setObjectName("buttonStart")
|
self.buttonStart.setObjectName("buttonStart")
|
||||||
self.verticalLayout_2.addWidget(self.buttonStart)
|
self.settingsLayout.addWidget(self.buttonStart)
|
||||||
self.labelSpectrometer = QtWidgets.QLabel(parent=Form)
|
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||||
self.labelSpectrometer.setObjectName("labelSpectrometer")
|
self.settingsLayout.addItem(spacerItem)
|
||||||
self.verticalLayout_2.addWidget(self.labelSpectrometer)
|
self.horizontalLayout_2.addLayout(self.settingsLayout)
|
||||||
self.horizontalLayout_2.addLayout(self.verticalLayout_2)
|
self.plotterLayout = QtWidgets.QVBoxLayout()
|
||||||
self.verticalLayout = QtWidgets.QVBoxLayout()
|
self.plotterLayout.setObjectName("plotterLayout")
|
||||||
self.verticalLayout.setObjectName("verticalLayout")
|
|
||||||
self.plotter = MplWidget(parent=Form)
|
self.plotter = MplWidget(parent=Form)
|
||||||
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Expanding)
|
||||||
|
sizePolicy.setHorizontalStretch(0)
|
||||||
|
sizePolicy.setVerticalStretch(0)
|
||||||
|
sizePolicy.setHeightForWidth(self.plotter.sizePolicy().hasHeightForWidth())
|
||||||
|
self.plotter.setSizePolicy(sizePolicy)
|
||||||
self.plotter.setObjectName("plotter")
|
self.plotter.setObjectName("plotter")
|
||||||
self.verticalLayout.addWidget(self.plotter)
|
self.plotterLayout.addWidget(self.plotter)
|
||||||
self.horizontalLayout_2.addLayout(self.verticalLayout)
|
self.horizontalLayout_2.addLayout(self.plotterLayout)
|
||||||
|
self.horizontalLayout_2.setStretch(1, 1)
|
||||||
self.horizontalLayout.addLayout(self.horizontalLayout_2)
|
self.horizontalLayout.addLayout(self.horizontalLayout_2)
|
||||||
|
|
||||||
self.retranslateUi(Form)
|
self.retranslateUi(Form)
|
||||||
|
@ -45,7 +78,9 @@ class Ui_Form(object):
|
||||||
def retranslateUi(self, Form):
|
def retranslateUi(self, Form):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
Form.setWindowTitle(_translate("Form", "Form"))
|
Form.setWindowTitle(_translate("Form", "Form"))
|
||||||
|
self.titleLable.setText(_translate("Form", "Single Frequency Measurement: "))
|
||||||
|
self.spectrometerLabel.setText(_translate("Form", "Spectrometer:"))
|
||||||
|
self.label.setText(_translate("Form", "Target Frequency"))
|
||||||
|
self.label_2.setText(_translate("Form", "Averages"))
|
||||||
self.buttonStart.setText(_translate("Form", "Start Measurement"))
|
self.buttonStart.setText(_translate("Form", "Start Measurement"))
|
||||||
self.labelSpectrometer.setText(_translate("Form", "Spectrometer:"))
|
|
||||||
|
|
||||||
from nqrduck.contrib.mplwidget import MplWidget
|
from nqrduck.contrib.mplwidget import MplWidget
|
||||||
|
|
Loading…
Reference in a new issue