def __init__(self, hardware_name, connection_name='-', parent=None):
        QWidget.__init__(self, parent)

        self._connection_name = connection_name
        self._hardware_name = hardware_name

        label_text = (self._hardware_name + ' - ' + self._connection_name)
        self._label = QLabel(label_text)
        self._label.setAlignment(Qt.AlignCenter)
        self._label.setSizePolicy(QSizePolicy.MinimumExpanding,
                                  QSizePolicy.Minimum)

        self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)

        # Create widgets
        self._widgets = {}
        self._widgets['gate'] = DigitalOutput('Enabled')
        self._widgets['freq'] = AnalogOutput('',
                                             display_name='Frequency',
                                             horizontal_alignment=True)
        self._widgets['amp'] = AnalogOutput('',
                                            display_name='Amplitude',
                                            horizontal_alignment=True)
        self._widgets['phase'] = AnalogOutput('',
                                              display_name='Phase',
                                              horizontal_alignment=True)

        # Create grid layout that keeps widgets from expanding and keeps label centred above the widgets
        self._layout = QGridLayout(self)
        self._layout.setVerticalSpacing(0)
        self._layout.setHorizontalSpacing(0)
        self._layout.setContentsMargins(0, 0, 0, 0)

        h_widget = QWidget()
        h_layout = QHBoxLayout(h_widget)
        h_layout.setContentsMargins(0, 0, 0, 0)
        h_layout.addWidget(self._widgets['gate'])
        h_layout.addWidget(self._widgets['freq'])
        h_layout.addWidget(self._widgets['amp'])
        h_layout.addWidget(self._widgets['phase'])

        self._layout.addWidget(self._label, 0, 0)
        #self._layout.addItem(QSpacerItem(0,0,QSizePolicy.MinimumExpanding,QSizePolicy.Minimum),0,1)
        self._layout.addWidget(h_widget, 1, 0)
        #self._layout.addItem(QSpacerItem(0,0,QSizePolicy.MinimumExpanding,QSizePolicy.Minimum),1,1)
        self._layout.addItem(
            QSpacerItem(0, 0, QSizePolicy.Minimum,
                        QSizePolicy.MinimumExpanding), 2, 0)
示例#2
0
 def create_widget(self,
                   display_name=None,
                   horizontal_alignment=False,
                   parent=None):
     widget = AnalogOutput(self._hardware_name, self._connection_name,
                           display_name, horizontal_alignment, parent)
     self.add_widget(widget)
     return widget
    def __init__(self, hardware_name, connection_name='-', parent=None):
        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 = QLabel(label_text)
        self._label.setAlignment(Qt.AlignCenter)
        self._label.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.Minimum)
        
        
        self.setSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.Minimum)
        
        # Create widgets
        self._widgets = {}
        self._widgets['gate'] = DigitalOutput('Enable')
        self._widgets['freq'] = AnalogOutput('',display_name='<i>f&nbsp;</i>', horizontal_alignment=True)
        self._widgets['amp'] = AnalogOutput('',display_name='<i>A</i>', horizontal_alignment=True)
        self._widgets['phase'] = AnalogOutput('',display_name=u'<i>&phi;</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 = QHBoxLayout(self)
        self._outer_layout.setContentsMargins(0, 0, 0, 0)
        # self._layout.setHorizontalSpacing(3)
        self._frame = 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 = QGridLayout(self._frame)
        self._layout.setVerticalSpacing(6)
        self._layout.setHorizontalSpacing(0)
        self._layout.setContentsMargins(0,0,0,0)
        
        v_widget = QFrame()
        v_widget.setFrameStyle(QFrame.StyledPanel)            
        v_layout = 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 = QWidget()
        gate_layout = 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,QSizePolicy.MinimumExpanding,QSizePolicy.Minimum),0,1)
        self._layout.addWidget(v_widget,1,0)            
        #self._layout.addItem(QSpacerItem(0,0,QSizePolicy.MinimumExpanding,QSizePolicy.Minimum),1,1)
        self._layout.addItem(QSpacerItem(0,0,QSizePolicy.Minimum,QSizePolicy.MinimumExpanding),2,0)
示例#4
0
    toolpalette.addWidget(button2)
    my_DO.add_widget(button1)
    my_DO.add_widget(button2)

    # Create an AO object
    my_AO = AO(hardware_name='ao0',
               connection_name='my ao',
               device_name='ni_blah',
               program_function=print_something,
               settings=settings,
               calib_class=None,
               calib_params=None,
               default_units='V',
               min=-10.0,
               max=10.0,
               step=0.01,
               decimals=3)

    # link in two AO widgets
    analog1 = AnalogOutput('AO1')
    analog2 = AnalogOutput('AO1 copy')
    my_AO.add_widget(analog1)
    my_AO.add_widget(analog2)
    toolpalette2.addWidget(analog1)
    toolpalette2.addWidget(analog2)

    # TODO: Add in test case for DDS

    window.show()
    sys.exit(qapplication.exec_())