def _createNew(self):
        a = ArgSetter(
            'New camera calibration', {
                'camera name': {
                    'value': 'change me',
                    'dtype': str
                },
                'bit depth': {
                    'value': 16,
                    'limits': [8, 12, 14, 16, 24, 32],
                    'dtype': int,
                    'tip': 'e.g. 16 for 16 bit'
                }
            })
        a.exec_()
        if a.result():
            c = CameraCalibration()
            c.path = None
            self.calibrations.append(c)

            name = a.args['camera name']
            depth = a.args['bit depth']
            c.setCamera(name, depth)
            self.calibrations.append(c)
            self.pModified.setValue(True)
            l = list(self.pCal.opts['limits'])
            l.append(name)
            self.pCal.setLimits(l)
            self.pDepth.setValue(depth)
            [p.show() for p in self.pCal.childs]
    def _createNew(self):
        a = ArgSetter('New camera calibration', {
                'camera name':{
                                'value': 'change me', 
                                'dtype':str},
                'bit depth': {
                                'value':16, 
                                'limits':[8,12,14,16,24,32], 
                                'dtype':int,
                                'tip':'e.g. 16 for 16 bit'} })
        a.exec_()
        if a.result():
            c = CameraCalibration()
            self.calibrations.append(c)

            name = a.args['camera name']
            c.setCamera(name,a.args['bit depth'])
            self.calibrations.append(c)
            self.pModified.setValue(True)
            l = list(self.pCal.opts['limits'])
            l.append(name)
            self.pCal.setLimits(l)
            [p.show() for p in self.pCal.childs]
    def _loadFromFile(self):
        d = self.display.workspace.gui.dialogs.getOpenFileName(
                            filter='*%s' %CameraCalibration.ftype)
        if d:
            self._cal_file_path = d
            self._last_dir = d.dirname()
            
            c = CameraCalibration.loadFromFile(d) 
            self.calibrations.append(c)
            
            [p.show() for p in self.pCal.childs]
            self._curIndex = -1
            self.pCal.setLimits([c.coeffs['name'] for c in self.calibrations])

            self._updateInfo()
    def __init__(self, display):
        super().__init__(display)
        _import()

        self.calibrations = []

        #self._last_dir = None
        #self._cal_file_path = None
        self._curIndex = 0
        self._genericCal = CameraCalibration()

        pa = self.setParameterMenu()

        pNew = pa.addChild({'name': 'New', 'type': 'action'})
        pNew.sigActivated.connect(self._createNew)

        pLoad = pa.addChild({'name': 'Load', 'type': 'action'})
        pLoad.sigActivated.connect(self._loadFromFile)

        self.pCal = pa.addChild({
            'name': 'Calibration',
            'type': 'list',
            'value': '-'
        })
        self.pCal.sigValueChanged.connect(self._pCalChanged)

        self.pAutosave = self.pCal.addChild({
            'name': 'Autosave',
            'type': 'bool',
            'visible': True
        })

        self.pModified = self.pCal.addChild({
            'name': 'Modified',
            'type': 'bool',
            'visible': False,
            'readonly': True
        })

        self.pAutosave.sigValueChanged.connect(self._pAutoSaveChanged)

        pSave = self.pCal.addChild({
            'name': 'Save as',
            'type': 'action',
            'visible': False
        })
        pSave.sigActivated.connect(lambda: self._saveToFile())

        #         pUnload = self.pCal.addChild({
        #             'name': 'Unload',
        #             'type': 'action',
        #             'visible':False
        #             })
        #         pUnload.sigActivated.connect(self._unloadCalibration)

        self.pDepth = self.pCal.addChild({
            'name': 'Bit Depth',
            'type': 'str',
            'value': '',
            'visible': False,
            'readonly': True
        })

        self.pLight = self.pCal.addChild({
            'name': 'Light spectra',
            'type': 'list',
            'limits': [],
            'value': '',
            'visible': False
        })
        self.pLight.sigValueChanged.connect(self._updateInfo)

        for name in ('dark current', 'flat field', 'lens', 'noise', 'psf',
                     'balance'):

            pDates = self.pCal.addChild({
                'name': name,
                'type': 'list',
                'limits': [],
                'value': '',
                'visible': False
            })

            aView = QtWidgets.QAction('View', self)
            aDel = QtWidgets.QAction('Remove', self)
            aView.triggered.connect(
                lambda _checked, n=name: self._viewCurrentCoeff(n))
            aDel.triggered.connect(
                lambda _checked, n=name: self._removeCurrentCoeff(n))
            pDates.addChild({
                'name': 'Info',
                'type': 'str',
                'readonly': True,
                'value': '',
                'addToContextMenu': [aView, aDel]
            })
            pDates.sigValueChanged.connect(
                lambda p, v, n=name: self._pDatesChanged(p, v, n))
 def _loadWithPath(self, path):
     #self._last_dir = path.dirname()
     c = CameraCalibration.loadFromFile(path)
     self.calibrations.append(c)
     c.path = path