def __init__(self, dev):
        self.dev = dev
        Qt.QWidget.__init__(self)
        self.layout = Qt.QVBoxLayout()
        self.setLayout(self.layout)
        chans = self.dev.listChannels()
        self.widgets = {}
        # self.uis = {}
        self.defaults = {}
        for ch in chans:
            wid = Qt.QWidget()
            ui = Ui_Form()
            ui.setupUi(wid)
            self.layout.addWidget(wid)
            ui.analogCtrls = [ui.scaleDefaultBtn, ui.scaleSpin, ui.offsetDefaultBtn, ui.offsetSpin, ui.scaleLabel,
                              ui.offsetLabel]
            # ui.channel = ch
            for s in dir(ui):
                i = getattr(ui, s)
                if isinstance(i, Qt.QWidget):
                    i.channel = ch

            self.widgets[ch] = ui
            ui.nameLabel.setText(str(ch))
            ui.channelCombo.addItem("%s (%s)" % (ch, chans[ch]['channel']))

            holding = chans[ch].get('holding', 0)

            if chans[ch]['type'] in ['ao', 'ai']:
                ui.inputRadio.setEnabled(False)
                ui.outputRadio.setEnabled(False)
                ui.invertCheck.hide()
                scale = chans[ch].get('scale', 1)
                units = chans[ch].get('units', 'V')
                offset = chans[ch].get('offset', 0)
                ui.offsetSpin.setOpts(suffix='V', siPrefix=True, dec=True, step=1.0, minStep=1e-4)
                ui.offsetSpin.setValue(offset)
                ui.offsetSpin.sigValueChanged.connect(self.offsetSpinChanged)
                ui.offsetDefaultBtn.setText("Default (%s)" % siFormat(offset, suffix='V'))
                ui.offsetDefaultBtn.clicked.connect(self.offsetDefaultBtnClicked)
                if chans[ch]['type'] == 'ao':
                    ui.outputRadio.setChecked(True)
                    ui.scaleDefaultBtn.setText("Default (%s)" % siFormat(scale, suffix='V/' + units))
                    ui.scaleSpin.setOpts(suffix='V/' + units, siPrefix=True, dec=True, step=1.0, minStep=1e-9)
                    ui.holdingSpin.setOpts(suffix=units, siPrefix=True, step=0.01)
                    ui.holdingSpin.setValue(holding)
                    ui.holdingSpin.sigValueChanged.connect(self.holdingSpinChanged)
                elif chans[ch]['type'] == 'ai':
                    ui.inputRadio.setChecked(True)
                    ui.holdingLabel.hide()
                    ui.holdingSpin.hide()
                    ui.scaleDefaultBtn.setText("Default (%s)" % siFormat(scale, suffix=units + '/V'))
                    # ui.scaleDefaultBtn.clicked.connect(self.scaleDefaultBtnClicked)
                    ui.scaleSpin.setOpts(suffix=units + '/V', siPrefix=True, dec=True)
                ui.scaleSpin.setValue(scale)
                ui.scaleDefaultBtn.clicked.connect(self.scaleDefaultBtnClicked)
                ui.scaleSpin.sigValueChanged.connect(self.scaleSpinChanged)
                self.defaults[ch] = {
                    'scale': scale,
                    'offset': offset}
            elif chans[ch]['type'] in ['do', 'di']:
                for item in ui.analogCtrls:
                    item.hide()
                if chans[ch].get('invert', False):
                    ui.invertCheck.setChecked(True)
                if chans[ch]['type'] == 'do':
                    ui.outputRadio.setChecked(True)
                    ui.holdingSpin.setOpts(bounds=[0, 1], step=1)
                    ui.holdingSpin.setValue(holding)
                    ui.holdingSpin.sigValueChanged.connect(self.holdingSpinChanged)
                elif chans[ch]['type'] == 'di':
                    ui.inputRadio.setChecked(True)
                    ui.holdingLabel.hide()
                    ui.holdingSpin.hide()
                ui.invertCheck.toggled.connect(self.invertToggled)
        # Qt.QObject.connect(self.dev, Qt.SIGNAL('holdingChanged'), self.holdingChanged)
        self.dev.sigHoldingChanged.connect(self.holdingChanged)