Exemple #1
0
def test_getCRSPhotometers():
    try:
        with mock.patch.dict("sys.modules",{"psychopy.hardware.crs": object()}):
            photoms = list(hw.getAllPhotometers())

            for p in photoms:
                assert p.longName != "CRS ColorCAL"

            assert isinstance(photoms,collections.Iterable)
            # missing crs shouldn't break it
            assert len(photoms) > 0
    except (AssertionError, ImportError):
        """
        I was able to do this fine from a shell:
        >>> from psychopy.hardware import crs
        or
        >>> import psychopy.hardware.crs
        but kept getting an ImportError when running the test locally:
                from . import minolta, pr
        >       from psychopy.hardware import crs
        E       ImportError: cannot import name crs
        hardware/__init__.py:60: ImportError

        or an assert error on travis-ci
        >               assert p.longName != "CRS ColorCAL"
        E               assert 'CRS ColorCAL' != 'CRS ColorCAL'
        E                +  where 'CRS ColorCAL' = <class psychopy.hardware.crs.colorcal.ColorCAL at 0x79b8738>.longName
        """
        pytest.skip()

    # This allows us to test our logic even when pycrsltd is missing
    faked = type("MockColorCAL",(object,),{})
    with mock.patch("psychopy.hardware.crs.ColorCAL", faked, create=True):
        photoms = list(hw.getAllPhotometers())
        assert faked in photoms
Exemple #2
0
def test_getCRSPhotometers():
    try:
        with mock.patch.dict("sys.modules",{"psychopy.hardware.crs": object()}):
            photoms = list(hw.getAllPhotometers())

            for p in photoms:
                assert p.longName != "CRS ColorCAL"

            assert isinstance(photoms, Iterable)
            # missing crs shouldn't break it
            assert len(photoms) > 0
    except (AssertionError, ImportError):
        """
        I was able to do this fine from a shell:
        >>> from psychopy.hardware import crs
        or
        >>> import psychopy.hardware.crs
        but kept getting an ImportError when running the test locally:
                from . import minolta, pr
        >       from psychopy.hardware import crs
        E       ImportError: cannot import name crs
        hardware/__init__.py:60: ImportError

        or an assert error on travis-ci
        >               assert p.longName != "CRS ColorCAL"
        E               assert 'CRS ColorCAL' != 'CRS ColorCAL'
        E                +  where 'CRS ColorCAL' = <class psychopy.hardware.crs.colorcal.ColorCAL at 0x79b8738>.longName
        """
        pytest.skip()

    # This allows us to test our logic even when pycrsltd is missing
    faked = type("MockColorCAL",(object,),{})
    with mock.patch("psychopy.hardware.crs.ColorCAL", faked, create=True):
        photoms = list(hw.getAllPhotometers())
        assert faked in photoms
Exemple #3
0
def test_getCRSPhotometers():
    with mock.patch.dict("sys.modules", {"psychopy.hardware.crs": object()}):
        photoms = list(hw.getAllPhotometers())

        for p in photoms:
            assert p.longName != "CRS ColorCAL"

        assert isinstance(photoms, collections.Iterable)
        # missing crs shouldn't break it
        assert len(photoms) > 0

    # This allows us to test our logic even when pycrsltd is missing
    faked = type("MockColorCAL", (object, ), {})
    with mock.patch("psychopy.hardware.crs.ColorCAL", faked):
        photoms = list(hw.getAllPhotometers())
        assert faked in photoms
Exemple #4
0
def test_getCRSPhotometers():
    with mock.patch.dict("sys.modules",{"psychopy.hardware.crs": object()}):
        photoms = list(hw.getAllPhotometers())

        for p in photoms:
            assert p.longName != "CRS ColorCAL"

        assert isinstance(photoms,collections.Iterable)
        # missing crs shouldn't break it
        assert len(photoms) > 0


    # This allows us to test our logic even when pycrsltd is missing
    faked = type("MockColorCAL",(object,),{})
    with mock.patch("psychopy.hardware.crs.ColorCAL", faked, create=True):
        photoms = list(hw.getAllPhotometers())
        assert faked in photoms
Exemple #5
0
def test_getPhotometers():
    photoms = hw.getAllPhotometers()

    # Always iterable
    assert isinstance(photoms, collections.Iterable)

    photoms = list(photoms)

    assert len(photoms) > 0
Exemple #6
0
def test_getPhotometers():
    photoms = hw.getAllPhotometers()

    # Always iterable
    assert isinstance(photoms,collections.Iterable)

    photoms = list(photoms)

    assert len(photoms) > 0
Exemple #7
0
    def makeCalibBox(self, parent):
        boxLabel = wx.StaticBox(parent, -1, _translate('Calibration'))
        boxLabel.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        calibBox = wx.StaticBoxSizer(boxLabel)

        photometerBox = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
        #com port entry number
        self.comPortLabel =  wx.StaticText(parent, -1, " ", size=(150,20))
        #photometer button
        # photom type choices should not need localization:
        self.ctrlPhotomType = wx.Choice(parent, -1, name="Type:",
            choices=list([p.longName for p in hardware.getAllPhotometers()]))

        self._photomChoices = [_translate("Scan all ports")] + list(hardware.getSerialPorts())
        self.ctrlPhotomPort = wx.ComboBox(parent, -1, name="Port:",
                                          value=self._photomChoices[0], # scan all ports
                                          choices=self._photomChoices,
                                          size=self.ctrlPhotomType.GetSize()+[0,5]
                                    )

        #wx.EVT_CHOICE(self, self.ctrlPhotomType.GetId(), self.onChangePhotomType)#not needed?
        self.btnFindPhotometer = wx.Button(parent, -1, _translate("Get Photometer"))
        wx.EVT_BUTTON(self, self.btnFindPhotometer.GetId(), self.onBtnFindPhotometer)

        #gamma controls
        self.btnCalibrateGamma = wx.Button(
            parent, -1, _translate("Gamma Calibration..."))
        wx.EVT_BUTTON(self, self.btnCalibrateGamma.GetId(), self.onCalibGammaBtn)
        self.btnTestGamma = wx.Button(
            parent, -1, _translate("Gamma Test..."))
        self.btnTestGamma.Enable(False)

        #color controls
        wx.EVT_BUTTON(self, self.btnTestGamma.GetId(), self.onCalibTestBtn)
        self.btnCalibrateColor = wx.Button(
            parent, -1, _translate("Chromatic Calibration..."))
        self.btnCalibrateColor.Enable(False)
        wx.EVT_BUTTON(self, self.btnCalibrateColor.GetId(), self.onCalibColorBtn)
        self.btnPlotGamma = wx.Button(
            parent, -1, _translate("Plot gamma"))
        wx.EVT_BUTTON(self, self.btnPlotGamma.GetId(), self.plotGamma)
        self.btnPlotSpectra = wx.Button(
            parent, -1, _translate("Plot spectra"))
        wx.EVT_BUTTON(self, self.btnPlotSpectra.GetId(), self.plotSpectra)

        photometerBox.AddMany([self.ctrlPhotomType,self.btnFindPhotometer,
                               self.ctrlPhotomPort,(0,0),
                                self.comPortLabel,(0,0),
                                self.btnCalibrateGamma, (0,0),
                                self.btnTestGamma, self.btnPlotGamma,
                                self.btnCalibrateColor, self.btnPlotSpectra])

        #-----------------------
        #----GAMMA------------
        #-----------------------
        #calibration grid
        gammaBox = wx.StaticBox(parent,-1,_translate('Linearization'))
        gammaBox.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        gammaBoxSizer = wx.StaticBoxSizer(gammaBox, wx.VERTICAL)

        # don't localize the choices
        self.choiceLinearMethod = wx.Choice(parent, -1, name='formula:',
                    choices=['easy: a+kx^g', 'full: a+(b+kx)^g'])
        if self.currentMon.getLinearizeMethod()==4:
            self.choiceLinearMethod.SetSelection(1)
        else: self.choiceLinearMethod.SetSelection(0)
        wx.EVT_CHOICE(self, self.choiceLinearMethod.GetId(), self.onChangeLinearMethod)
        gammaBoxSizer.Add(self.choiceLinearMethod, 1, wx.ALL, 2)

        self.gammaGrid = SimpleGrid(parent, id=-1,
                                    cols=['Min','Max','Gamma','a','b','k'],
                                    rows=['lum','R','G','B'])
        gammaBoxSizer.Add(self.gammaGrid)
        grid.EVT_GRID_CELL_CHANGE(self.gammaGrid,self.onChangeGammaGrid)
        gammaBoxSizer.Layout()

        #LMS grid
        LMSbox = wx.StaticBox(parent,-1,'LMS->RGB')
        LMSboxSizer = wx.StaticBoxSizer(LMSbox, wx.VERTICAL)
        self.LMSgrid = SimpleGrid(parent, id=-1,
                                  cols=['L','M','S'],
                                  rows=['R','G','B'])
        LMSboxSizer.Add(self.LMSgrid)
        LMSboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.LMSgrid,self.onChangeLMSgrid)

        #DKL grid
        DKLbox = wx.StaticBox(parent,-1,'DKL->RGB')
        DKLboxSizer = wx.StaticBoxSizer(DKLbox, wx.VERTICAL)
        self.DKLgrid = SimpleGrid(parent, id=-1,
                                  cols=['Lum','L-M','L+M-S'],
                                  rows=['R','G','B'])
        DKLboxSizer.Add(self.DKLgrid)
        DKLboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.DKLgrid,self.onChangeDKLgrid)


        calibBoxMainSizer = wx.BoxSizer(wx.VERTICAL)
        calibBoxMainSizer.AddMany([photometerBox,
                                   gammaBoxSizer,
                                   LMSboxSizer,
                                   DKLboxSizer,
                                  ])
        calibBoxMainSizer.Layout()

        if NOTEBOOKSTYLE:
            return calibBoxMainSizer
        else:
            #put the main sizer into a labeled box
            calibBox.Add(calibBoxMainSizer)
            return calibBox
Exemple #8
0
    def makeCalibBox(self, parent):
        boxLabel = wx.StaticBox(parent, -1, _translate('Calibration'))
        boxLabel.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        calibBox = wx.StaticBoxSizer(boxLabel)

        photometerBox = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
        # com port entry number
        self.comPortLabel = wx.StaticText(parent, -1, " ", size=(150, 20))
        # photometer button
        # photom type choices should not need localization:
        _choices = list([p.longName for p in hardware.getAllPhotometers()])
        self.ctrlPhotomType = wx.Choice(parent, -1, name="Type:",
                                        choices=_choices)

        _ports = list(hardware.getSerialPorts())
        self._photomChoices = [_translate("Scan all ports")] + _ports
        _size = self.ctrlPhotomType.GetSize() + [0, 5]
        self.ctrlPhotomPort = wx.ComboBox(parent, -1, name="Port:",
                                          value=self._photomChoices[0],
                                          choices=self._photomChoices,
                                          size=_size)

        # wx.EVT_CHOICE(self, self.ctrlPhotomType.GetId(),
        #               self.onChangePhotomType)  # not needed?
        self.btnFindPhotometer = wx.Button(parent, -1,
                                           _translate("Get Photometer"))
        wx.EVT_BUTTON(self, self.btnFindPhotometer.GetId(),
                      self.onBtnFindPhotometer)

        # gamma controls
        self.btnCalibrateGamma = wx.Button(
            parent, -1, _translate("Gamma Calibration..."))
        wx.EVT_BUTTON(self, self.btnCalibrateGamma.GetId(),
                      self.onCalibGammaBtn)
        self.btnTestGamma = wx.Button(
            parent, -1, _translate("Gamma Test..."))
        self.btnTestGamma.Enable(False)

        # color controls
        wx.EVT_BUTTON(self, self.btnTestGamma.GetId(), self.onCalibTestBtn)
        self.btnCalibrateColor = wx.Button(
            parent, -1, _translate("Chromatic Calibration..."))
        self.btnCalibrateColor.Enable(False)
        wx.EVT_BUTTON(self, self.btnCalibrateColor.GetId(),
                      self.onCalibColorBtn)
        self.btnPlotGamma = wx.Button(
            parent, -1, _translate("Plot gamma"))
        wx.EVT_BUTTON(self, self.btnPlotGamma.GetId(), self.plotGamma)
        self.btnPlotSpectra = wx.Button(
            parent, -1, _translate("Plot spectra"))
        wx.EVT_BUTTON(self, self.btnPlotSpectra.GetId(), self.plotSpectra)

        photometerBox.AddMany([self.ctrlPhotomType, self.btnFindPhotometer,
                               self.ctrlPhotomPort, (0, 0),
                               self.comPortLabel, (0, 0),
                               self.btnCalibrateGamma, (0, 0),
                               self.btnTestGamma, self.btnPlotGamma,
                               self.btnCalibrateColor, self.btnPlotSpectra])

        # ----GAMMA------------
        # calibration grid
        gammaBox = wx.StaticBox(parent, -1, _translate('Linearization'))
        gammaBox.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        gammaBoxSizer = wx.StaticBoxSizer(gammaBox, wx.VERTICAL)

        # don't localize the choices
        _choices = ['easy: a+kx^g', 'full: a+(b+kx)^g']
        self.choiceLinearMethod = wx.Choice(parent, -1, name='formula:',
                                            choices=_choices)
        if self.currentMon.getLinearizeMethod() == 4:
            self.choiceLinearMethod.SetSelection(1)
        else:
            self.choiceLinearMethod.SetSelection(0)
        wx.EVT_CHOICE(self, self.choiceLinearMethod.GetId(),
                      self.onChangeLinearMethod)
        gammaBoxSizer.Add(self.choiceLinearMethod, 1, wx.ALL, 2)

        self.gammaGrid = SimpleGrid(parent, id=-1,
                                    cols=['Min', 'Max', 'Gamma',
                                          'a', 'b', 'k'],
                                    rows=['lum', 'R', 'G', 'B'])
        gammaBoxSizer.Add(self.gammaGrid)
        grid.EVT_GRID_CELL_CHANGE(self.gammaGrid, self.onChangeGammaGrid)
        gammaBoxSizer.Layout()

        # LMS grid
        LMSbox = wx.StaticBox(parent, -1, 'LMS->RGB')
        LMSboxSizer = wx.StaticBoxSizer(LMSbox, wx.VERTICAL)
        self.LMSgrid = SimpleGrid(parent, id=-1,
                                  cols=['L', 'M', 'S'],
                                  rows=['R', 'G', 'B'])
        LMSboxSizer.Add(self.LMSgrid)
        LMSboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.LMSgrid, self.onChangeLMSgrid)

        # DKL grid
        DKLbox = wx.StaticBox(parent, -1, 'DKL->RGB')
        DKLboxSizer = wx.StaticBoxSizer(DKLbox, wx.VERTICAL)
        self.DKLgrid = SimpleGrid(parent, id=-1,
                                  cols=['Lum', 'L-M', 'L+M-S'],
                                  rows=['R', 'G', 'B'])
        DKLboxSizer.Add(self.DKLgrid)
        DKLboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.DKLgrid, self.onChangeDKLgrid)

        calibBoxMainSizer = wx.BoxSizer(wx.VERTICAL)
        calibBoxMainSizer.AddMany([photometerBox,
                                   gammaBoxSizer,
                                   LMSboxSizer,
                                   DKLboxSizer])
        calibBoxMainSizer.Layout()

        if NOTEBOOKSTYLE:
            return calibBoxMainSizer
        else:
            # put the main sizer into a labeled box
            calibBox.Add(calibBoxMainSizer)
            return calibBox
Exemple #9
0
    def makeCalibBox(self, parent):

        boxLabel = wx.StaticBox(parent, -1, "Calibration")
        boxLabel.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        calibBox = wx.StaticBoxSizer(boxLabel)

        photometerBox = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
        # com port entry number
        self.comPortLabel = wx.StaticText(parent, -1, " ", size=(150, 20))
        # photometer button
        self.ctrlPhotomType = wx.Choice(
            parent, -1, name="Type:", choices=list([p.longName for p in hardware.getAllPhotometers()])
        )
        self.ctrlPhotomPort = wx.ComboBox(
            parent,
            -1,
            name="Port:",
            value="Scan all ports",
            choices=["Scan all ports"] + list(hardware.getSerialPorts()),
            size=self.ctrlPhotomType.GetSize(),
        )
        # wx.EVT_CHOICE(self, self.ctrlPhotomType.GetId(), self.onChangePhotomType)#not needed?
        self.btnFindPhotometer = wx.Button(parent, -1, "Get Photometer")
        wx.EVT_BUTTON(self, self.btnFindPhotometer.GetId(), self.onBtnFindPhotometer)

        # gamma controls
        self.btnCalibrateGamma = wx.Button(parent, -1, "Gamma Calibration...")
        wx.EVT_BUTTON(self, self.btnCalibrateGamma.GetId(), self.onCalibGammaBtn)
        self.btnTestGamma = wx.Button(parent, -1, "Gamma Test...")
        self.btnTestGamma.Enable(False)

        # color controls
        wx.EVT_BUTTON(self, self.btnTestGamma.GetId(), self.onCalibTestBtn)
        self.btnCalibrateColor = wx.Button(parent, -1, "Chromatic Calibration...")
        self.btnCalibrateColor.Enable(False)
        wx.EVT_BUTTON(self, self.btnCalibrateColor.GetId(), self.onCalibColorBtn)
        self.btnPlotGamma = wx.Button(parent, -1, "Plot gamma")
        wx.EVT_BUTTON(self, self.btnPlotGamma.GetId(), self.plotGamma)
        self.btnPlotSpectra = wx.Button(parent, -1, "Plot spectra")
        wx.EVT_BUTTON(self, self.btnPlotSpectra.GetId(), self.plotSpectra)

        photometerBox.AddMany(
            [
                self.ctrlPhotomType,
                self.btnFindPhotometer,
                self.ctrlPhotomPort,
                (0, 0),
                self.comPortLabel,
                (0, 0),
                self.btnCalibrateGamma,
                (0, 0),
                self.btnTestGamma,
                self.btnPlotGamma,
                self.btnCalibrateColor,
                self.btnPlotSpectra,
            ]
        )

        # -----------------------
        # ----GAMMA------------
        # -----------------------
        # calibration grid
        gammaBox = wx.StaticBox(parent, -1, "Linearisation")
        gammaBox.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL))
        gammaBoxSizer = wx.StaticBoxSizer(gammaBox, wx.VERTICAL)

        self.choiceLinearMethod = wx.Choice(parent, -1, name="formula:", choices=["easy: a+kx^g", "full: a+(b+kx)^g"])
        if self.currentMon.getLineariseMethod() == 4:
            self.choiceLinearMethod.SetSelection(1)
        else:
            self.choiceLinearMethod.SetSelection(0)
        wx.EVT_CHOICE(self, self.choiceLinearMethod.GetId(), self.onChangeLinearMethod)
        gammaBoxSizer.Add(self.choiceLinearMethod, 1, wx.ALL, 2)

        self.gammaGrid = SimpleGrid(
            parent, id=-1, cols=["Min", "Max", "Gamma", "a", "b", "k"], rows=["lum", "R", "G", "B"]
        )
        gammaBoxSizer.Add(self.gammaGrid)
        grid.EVT_GRID_CELL_CHANGE(self.gammaGrid, self.onChangeGammaGrid)
        gammaBoxSizer.Layout()

        # LMS grid
        LMSbox = wx.StaticBox(parent, -1, "LMS->RGB")
        LMSboxSizer = wx.StaticBoxSizer(LMSbox, wx.VERTICAL)
        self.LMSgrid = SimpleGrid(parent, id=-1, cols=["L", "M", "S"], rows=["R", "G", "B"])
        LMSboxSizer.Add(self.LMSgrid)
        LMSboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.LMSgrid, self.onChangeLMSgrid)

        # DKL grid
        DKLbox = wx.StaticBox(parent, -1, "DKL->RGB")
        DKLboxSizer = wx.StaticBoxSizer(DKLbox, wx.VERTICAL)
        self.DKLgrid = SimpleGrid(parent, id=-1, cols=["Lum", "L-M", "L+M-S"], rows=["R", "G", "B"])
        DKLboxSizer.Add(self.DKLgrid)
        DKLboxSizer.Layout()
        grid.EVT_GRID_CELL_CHANGE(self.DKLgrid, self.onChangeDKLgrid)

        calibBoxMainSizer = wx.BoxSizer(wx.VERTICAL)
        calibBoxMainSizer.AddMany([photometerBox, gammaBoxSizer, LMSboxSizer, DKLboxSizer])
        calibBoxMainSizer.Layout()

        if NOTEBOOKSTYLE:
            return calibBoxMainSizer
        else:
            # put the main sizer into a labeled box
            calibBox.Add(calibBoxMainSizer)
            return calibBox