Improved layout.

This commit is contained in:
jupfi 2023-07-17 15:54:49 +02:00
parent fb002d0745
commit d094d7eae9
5 changed files with 200 additions and 33 deletions

View file

@ -10,9 +10,13 @@ class MeasurementController(ModuleController):
def start_measurement(self):
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):
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.")
self.module.model.single_measurement = value
self.module.view.measurement_dialog.hide()

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -11,7 +11,7 @@
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -21,9 +21,57 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<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>
<widget class="QPushButton" name="buttonStart">
<property name="text">
@ -32,18 +80,31 @@
</widget>
</item>
<item>
<widget class="QLabel" name="labelSpectrometer">
<property name="text">
<string>Spectrometer:</string>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="plotterLayout" stretch="0">
<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>
</layout>
</item>
@ -55,7 +116,7 @@
<customwidget>
<class>MplWidget</class>
<extends>QWidget</extends>
<header>contrib/mplwidget.h</header>
<header>nqrduck/contrib/mplwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View file

@ -1,9 +1,12 @@
import logging
import numpy as np
from PyQt6.QtWidgets import QWidget
from PyQt6.QtCore import pyqtSlot
from .widget import Ui_Form
from pathlib import Path
import matplotlib as mpl
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 .widget import Ui_Form
logger = logging.getLogger(__name__)
@ -11,15 +14,50 @@ class MeasurementView(ModuleView):
def __init__(self, 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()
self._ui_form = Ui_Form()
self._ui_form.setupUi(self)
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
self.module.model.single_measurement_changed.connect(self.update_single_measurement)
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()
def update_single_measurement(self):
logger.debug("Updating single measurement view.")
@ -28,15 +66,44 @@ class MeasurementView(ModuleView):
tdy = self.module.model.single_measurement.tdy
#correcting a offset in the time domain by subtracting the mean
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_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.draw()
@pyqtSlot()
def on_measurement_start_button_clicked(self):
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()

View file

@ -13,7 +13,7 @@ class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
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.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
@ -22,21 +22,54 @@ class Ui_Form(object):
self.horizontalLayout.setObjectName("horizontalLayout")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.settingsLayout = QtWidgets.QVBoxLayout()
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.setObjectName("buttonStart")
self.verticalLayout_2.addWidget(self.buttonStart)
self.labelSpectrometer = QtWidgets.QLabel(parent=Form)
self.labelSpectrometer.setObjectName("labelSpectrometer")
self.verticalLayout_2.addWidget(self.labelSpectrometer)
self.horizontalLayout_2.addLayout(self.verticalLayout_2)
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.settingsLayout.addWidget(self.buttonStart)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding)
self.settingsLayout.addItem(spacerItem)
self.horizontalLayout_2.addLayout(self.settingsLayout)
self.plotterLayout = QtWidgets.QVBoxLayout()
self.plotterLayout.setObjectName("plotterLayout")
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.verticalLayout.addWidget(self.plotter)
self.horizontalLayout_2.addLayout(self.verticalLayout)
self.plotterLayout.addWidget(self.plotter)
self.horizontalLayout_2.addLayout(self.plotterLayout)
self.horizontalLayout_2.setStretch(1, 1)
self.horizontalLayout.addLayout(self.horizontalLayout_2)
self.retranslateUi(Form)
@ -45,7 +78,9 @@ class Ui_Form(object):
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
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.labelSpectrometer.setText(_translate("Form", "Spectrometer:"))
from nqrduck.contrib.mplwidget import MplWidget