#####################################################################
# #
# ddsoutput.py #
# #
# Copyright 2013, Monash University #
# #
# This file is part of the labscript suite (see #
# http://labscriptsuite.org) and is licensed under the Simplified #
# BSD License. See the license.txt file in the root of the project #
# for the full license. #
# #
#####################################################################
import sys
from qtutils.qt import QtCore, QtWidgets
from labscript_utils.qtwidgets.analogoutput import AnalogOutput
from labscript_utils.qtwidgets.digitaloutput import DigitalOutput
[docs]
class DDSOutput(QtWidgets.QWidget):
[docs]
def __init__(self, hardware_name, connection_name='-', parent=None):
QtWidgets.QWidget.__init__(self,parent)
self._connection_name = connection_name
self._hardware_name = hardware_name
label_text = (self._hardware_name + '\n' + self._connection_name)
self._label = QtWidgets.QLabel(label_text)
self._label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self._label.setSizePolicy(QtWidgets.QSizePolicy.Policy.MinimumExpanding,QtWidgets.QSizePolicy.Policy.Minimum)
self.setSizePolicy(QtWidgets.QSizePolicy.Policy.MinimumExpanding,QtWidgets.QSizePolicy.Policy.Minimum)
# Create widgets
self._widgets = {}
self._widgets['gate'] = DigitalOutput('Enable')
self._widgets['freq'] = AnalogOutput('',display_name='<i>f </i>', horizontal_alignment=True)
self._widgets['amp'] = AnalogOutput('',display_name='<i>A</i>', horizontal_alignment=True)
self._widgets['phase'] = AnalogOutput('',display_name=u'<i>φ</i>', horizontal_alignment=True)
# Extra layout at the top level with horizontal stretches so that our
# widgets do not grow to take up all available horizontal space:
self._outer_layout = QtWidgets.QHBoxLayout(self)
self._outer_layout.setContentsMargins(0, 0, 0, 0)
# self._layout.setHorizontalSpacing(3)
self._frame = QtWidgets.QFrame(self)
self._outer_layout.addStretch()
self._outer_layout.addWidget(self._frame)
self._outer_layout.addStretch()
# Create grid layout that keeps widgets from expanding and keeps label centred above the widgets
self._layout = QtWidgets.QGridLayout(self._frame)
self._layout.setVerticalSpacing(6)
self._layout.setHorizontalSpacing(0)
self._layout.setContentsMargins(0,0,0,0)
v_widget = QtWidgets.QFrame()
v_widget.setFrameStyle(QtWidgets.QFrame.Shape.StyledPanel)
v_layout = QtWidgets.QVBoxLayout(v_widget)
v_layout.setContentsMargins(6,6,6,6)
# Extra widget with stretches around the enabled button so it doesn't
# stretch out to fill all horizontal space:
self.gate_container = QtWidgets.QWidget()
gate_layout = QtWidgets.QHBoxLayout(self.gate_container)
gate_layout.setContentsMargins(0,0,0,0)
gate_layout.setSpacing(0)
gate_layout.addStretch()
gate_layout.addWidget(self._widgets['gate'])
gate_layout.addStretch()
self._widgets['gate'].setToolTip("Enable")
self._widgets['freq'].setToolTip("Frequency")
self._widgets['amp'].setToolTip("Amplitude")
self._widgets['phase'].setToolTip("Phase")
v_layout.addWidget(self.gate_container)
v_layout.addWidget(self._widgets['freq'])
v_layout.addWidget(self._widgets['amp'])
v_layout.addWidget(self._widgets['phase'])
self._layout.addWidget(self._label,0,0)
#self._layout.addItem(QSpacerItem(0,0,QtWidgets.QSizePolicy.Policy.MinimumExpanding,QtWidgets.QSizePolicy.Policy.Minimum),0,1)
self._layout.addWidget(v_widget,1,0)
#self._layout.addItem(QSpacerItem(0,0,QtWidgets.QSizePolicy.Policy.MinimumExpanding,QtWidgets.QSizePolicy.Policy.Minimum),1,1)
self._layout.addItem(QtWidgets.QSpacerItem(0,0,QtWidgets.QSizePolicy.Policy.Minimum,QtWidgets.QSizePolicy.Policy.MinimumExpanding),2,0)
# A simple test!
if __name__ == '__main__':
qapplication = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout(window)
button = DDSOutput('DDS1')
layout.addWidget(button)
window.show()
sys.exit(qapplication.exec())