예제 #1
0
def test_element_array_colors():
    # Create element array with two elements covering the whole window in two block colours
    obj = visual.ElementArrayStim(win,
                                  units="pix",
                                  fieldPos=(0, 0),
                                  fieldSize=(128, 128),
                                  fieldShape='square',
                                  nElements=2,
                                  sizes=[[64, 128], [64, 128]],
                                  xys=[[-32, 0], [32, 0]],
                                  elementMask=None,
                                  elementTex=None)
    # Iterate through color sets
    for colorSet in exemplars + tykes:
        for space in colorSet:
            # Check that setting color arrays renders correctly
            obj.colorSpace = space
            obj.colors = [
                colorSet[space], 'black'
            ]  # Set first color to current color set, second to black
            obj.opacity = 1  # Fix opacity at full as this is not what we're testing
            win.flip()
            obj.draw()
            utils.comparePixelColor(win,
                                    colors.Color(colorSet[space], space),
                                    coord=(10, 10))
            utils.comparePixelColor(win,
                                    colors.Color('black'),
                                    coord=(10, 100))
예제 #2
0
 def test_element_array_colors(self):
     # Create element array with two elements covering the whole window in two block colours
     obj = visual.ElementArrayStim(self.win,
                                   units="pix",
                                   fieldPos=(0, 0),
                                   fieldSize=(128, 128),
                                   fieldShape='square',
                                   nElements=2,
                                   sizes=[[64, 128], [64, 128]],
                                   xys=[[-32, 0], [32, 0]],
                                   elementMask=None,
                                   elementTex=None)
     # Iterate through color sets
     for colorSet in exemplars + tykes:
         for space in colorSet:
             if space not in colors.strSpaces and not isinstance(
                     colorSet[space], (str, type(None))):
                 # Check that setting color arrays renders correctly
                 obj.colorSpace = space
                 col1 = np.array(colorSet[space]).reshape((1, -1))
                 col2 = getattr(colors.Color('black'), space).reshape(
                     (1, -1))
                 obj.colors = np.append(
                     col1, col2, 0
                 )  # Set first color to current color set, second to black in same color space
                 obj.opacity = 1  # Fix opacity at full as this is not what we're testing
                 self.win.flip()
                 obj.draw()
                 utils.comparePixelColor(self.win,
                                         colors.Color(
                                             colorSet[space], space),
                                         coord=(10, 10))
                 utils.comparePixelColor(self.win,
                                         colors.Color('black'),
                                         coord=(10, 100))
예제 #3
0
def test_window_colors():
    # Iterate through color sets
    for colorSet in exemplars + tykes:
        for space in colorSet:
            # Set window color
            win.colorSpace = space
            win.color = colorSet[space]
            win.flip()
            utils.comparePixelColor(win, colors.Color(colorSet[space], space))
예제 #4
0
def test_shape_colors():
    # Create rectangle with chunky border
    obj = visual.Rect(win,
                      units="pix",
                      pos=(0, 0),
                      size=(128, 128),
                      lineWidth=10)
    # Iterate through color sets
    for colorSet in exemplars + tykes:
        for space in colorSet:
            # Check border color
            obj.colorSpace = space
            obj.borderColor = colorSet[space]
            obj.fillColor = 'white'
            obj.opacity = 1  # Fix opacity at full as this is not what we're testing
            win.flip()
            obj.draw()
            utils.comparePixelColor(win,
                                    colors.Color(colorSet[space], space),
                                    coord=(1, 1))
            utils.comparePixelColor(win, colors.Color('white'), coord=(50, 50))
            # Check fill color
            obj.colorSpace = space
            obj.fillColor = colorSet[space]
            obj.borderColor = 'white'
            obj.opacity = 1  # Fix opacity at full as this is not what we're testing
            win.flip()
            obj.draw()
            utils.comparePixelColor(win, colors.Color('white'), coord=(1, 1))
            utils.comparePixelColor(win,
                                    colors.Color(colorSet[space], space),
                                    coord=(50, 50))
예제 #5
0
 def test_contrast(self):
     # Create rectangle with chunky border
     obj = visual.Rect(self.win, units="pix", pos=(0, 0), size=(128, 128), lineWidth=10)
     # Set its colors to be rgb extremes
     obj.fillColor = 'red'
     obj.borderColor = 'blue'
     obj.opacity = 1  # Fix opacity at full as this is not what we're testing
     # Halve contrast
     obj.contrast = 0.5
     # Refresh
     self.win.flip()
     obj.draw()
     # Check rendered color
     utils.comparePixelColor(self.win, colors.Color(( 0.5, -0.5, -0.5), "rgb"), coord=(50, 50))
     utils.comparePixelColor(self.win, colors.Color((-0.5, -0.5,  0.5), "rgb"), coord=(1, 1))
예제 #6
0
 def test_colors(self):
     # If this test object has no obj, skip
     if not self.obj:
         return
     # Test each case
     for case in self.colorTykes + self.colorExemplars:
         for space, color in case.items():
             # Make color to compare against
             target = colors.Color(color, space)
             # Prepare object
             self.obj.colorSpace = space
             self.obj.fillColor = 'white'
             self.obj.foreColor = 'white'
             self.obj.borderColor = 'white'
             self.obj.opacity = 1
             if hasattr(self.obj, "text"):
                 self.obj.text = "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question."
             # Prepare window
             self.win.flip()
             # Test fill color
             if self.fillUsed:
                 # Set fill
                 self.obj.fillColor = color
                 self.obj.opacity = 1
                 self.obj.draw()
                 if color is not None:
                     # Make sure fill is set
                     utils.comparePixelColor(self.win, target, coord=self.fillPoint, context=f"{self.__class__.__name__}_fill")
                     # Make sure border is not
                     if self.borderUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.borderPoint, context=f"{self.__class__.__name__}_fill")
                     # Make sure fore is not
                     if self.foreUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.forePoint, context=f"{self.__class__.__name__}_fill")
                 # Reset fill
                 self.obj.fillColor = 'white'
                 self.obj.opacity = 1
             # Test border color
             if self.borderUsed:
                 # Set border
                 self.obj.borderColor = color
                 self.obj.opacity = 1
                 self.obj.draw()
                 if color is not None:
                     # Make sure border is set
                     utils.comparePixelColor(self.win, target, coord=self.borderPoint, context=f"{self.__class__.__name__}_border")
                     # Make sure fill is not
                     if self.fillUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.fillPoint, context=f"{self.__class__.__name__}_border")
                     # Make sure fore is not
                     if self.foreUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.forePoint, context=f"{self.__class__.__name__}_border")
                 # Reset border
                 self.obj.borderColor = 'white'
                 self.obj.opacity = 1
             # Test fore color
             if self.foreUsed:
                 # Set fore
                 self.obj.foreColor = color
                 self.obj.opacity = 1
                 self.obj.draw()
                 if color is not None:
                     # Make sure fore is set
                     utils.comparePixelColor(self.win, target, coord=self.forePoint, context=f"{self.__class__.__name__}_fore")
                     # Make sure fill is not
                     if self.fillUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.fillPoint, context=f"{self.__class__.__name__}_fore")
                     # Make sure border is not
                     if self.borderUsed:
                         utils.comparePixelColor(self.win, colors.Color('white'), coord=self.borderPoint, context=f"{self.__class__.__name__}_fore")
                 # Reset fore
                 self.obj.foreColor = 'white'
                 self.obj.opacity = 1
예제 #7
0
    def test_visual_helper(self):
        # Create rectangle with chunky border
        obj = visual.Rect(self.win, units="pix", pos=(0, 0), size=(128, 128), lineWidth=10)
        # Iterate through color sets
        for colorSet in exemplars + tykes:
            for space in colorSet:
                # Check border color
                visual.helpers.setColor(obj,
                                        color=colorSet[space], colorSpace=space,
                                        colorAttrib="borderColor")
                obj.fillColor = 'white'
                obj.opacity = 1  # Fix opacity at full as this is not what we're testing
                self.win.flip()
                obj.draw()
                if colorSet[space]:  # skip this comparison if color is None
                    utils.comparePixelColor(self.win, colors.Color(colorSet[space], space), coord=(1, 1))
                utils.comparePixelColor(self.win, colors.Color('white'), coord=(50, 50))
                # Check fill color
                visual.helpers.setColor(obj,
                                        color=colorSet[space], colorSpace=space,
                                        colorAttrib="fillColor")
                obj.borderColor = 'white'
                obj.opacity = 1  # Fix opacity at full as this is not what we're testing
                self.win.flip()
                obj.draw()
                if colorSet[space]:  # skip this comparison if color is None
                    utils.comparePixelColor(self.win, colors.Color(colorSet[space], space), coord=(50, 50))
                utils.comparePixelColor(self.win, colors.Color('white'), coord=(1, 1))
        # Check color addition
        obj.fillColor = 'white'
        visual.helpers.setColor(obj,
                                color='black',
                                colorAttrib='fillColor',
                                operation='+')
        self.win.flip()
        obj.draw()
        utils.comparePixelColor(self.win, colors.Color('white') + colors.Color('black'), coord=(50, 50))
        # Check color subtraction
        obj.fillColor = 'grey'
        visual.helpers.setColor(obj,
                                color='black',
                                colorAttrib='fillColor',
                                operation='-')
        self.win.flip()
        obj.draw()
        utils.comparePixelColor(self.win, colors.Color('grey') - colors.Color('black'), coord=(50, 50))

        # Check alerts
        visual.helpers.setColor(obj, color="white", colorSpaceAttrib="fillColorSpace", rgbAttrib="fillRGB")
        assert any(err.code == 8105 for err in self.error.alerts), "Alert 8105 not triggered"
        assert any(err.code == 8110 for err in self.error.alerts), "Alert 8110 not triggered"