Ejemplo n.º 1
0
    def __init__(self, size, colour=None, line_width=None, position=None):
        """Create a rectangle.

        Parameters
        ----------
        size : (int, int)
            size (width, height) of the rectangle
        line_width : int, optional
            line width in pixels; 0 will result in a filled rectangle,
            as does a value < 0 or >= min(size)
        position : (int, int), optional
            position of the stimulus
        colour : (int, int, int), optional
            colour of the rectangle

        """

        if position is None:
            position = defaults.rectangle_position
        Visual.__init__(self, position=position)
        self._size = size
        if colour is None:
            colour = defaults.rectangle_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.rectangle_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
Ejemplo n.º 2
0
    def __init__(self, size, colour=None, line_width=None, position=None):
        """Create an ellipse.

        Parameters
        ----------
        size : (int, int)
            size of the ellipse (major and minor axis)
        colour : (int, int, int), optional
            colour of the ellipse
        line_width : int, optional
            line width in pixels; 0 will result in a filled ellipse
            (as does a value < 0 or >= min(size))
        position : (int, int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.circle_position
        Visual.__init__(self, position)
        self._size = size
        if colour is None:
            colour = defaults.circle_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.circle_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
Ejemplo n.º 3
0
    def __init__(self, size, colour=None, line_width=None, position=None):
        """Create a rectangle.

        Parameters
        ----------
        size : (int, int)
            size (width, height) of the rectangle
        line_width : int, optional
            line width in pixels; 0 will result in a filled rectangle,
            as does a value < 0 or >= min(size)
        position : (int, int), optional
            position of the stimulus
        colour : (int, int, int), optional
            colour of the rectangle

        """

        if position is None:
            position = defaults.rectangle_position
        Visual.__init__(self, position=position)
        self._size = size
        if colour is None:
            colour = defaults.rectangle_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.rectangle_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
Ejemplo n.º 4
0
    def __init__(self, filename, position=None):
        """Create a picture.

        Parameters
        ----------
        filename : str
            filename (incl. path) of the picture file
        position :(int,int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.picture_position
        Visual.__init__(self, position, log_comment=filename)
        self._filename = filename
        if not(os.path.isfile(self._filename)):
            if isinstance(self._filename, unicode):
                import sys
                ENCODING = sys.getfilesystemencoding()
                if ENCODING is None:
                    ENCODING = u"utf-8"
                filename = self._filename.encode(ENCODING)
            raise IOError("The picture file '{0}' does not exist".format(
                filename))
Ejemplo n.º 5
0
    def __init__(self,
                 size,
                 colour=None,
                 line_width=None,
                 corner_rounding=None,
                 corner_anti_aliasing=None,
                 position=None):
        """Create a rectangle.

        Parameters
        ----------
        size : (int, int)
            size (width, height) of the rectangle
        colour : (int, int, int), optional
            colour of the rectangle
        line_width : int, optional
            line width in pixels; 0 will result in a filled rectangle,
            as does a value < 0 or >= min(size)
        corner_rounding : float or (float, float, float, float), optional
            radius of the corners in percent of 0.5 * min(size);
        corner_anti_aliasing : int, optional
            anti aliasing parameter for rounded corners
            (good anti_aliasing with 10)
        position : (int, int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.rectangle_position
        Visual.__init__(self, position=position)
        self._size = size
        if colour is None:
            colour = defaults.rectangle_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.rectangle_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
        if corner_rounding is None:
            corner_rounding = defaults.rectangle_corner_rounding
        elif corner_rounding < 0 or corner_rounding > 100:
            raise AttributeError("corner_rounding must be >= 0 and < 100!")
        self._corner_rounding = corner_rounding
        if corner_anti_aliasing is not None:
            self._corner_anti_aliasing = corner_anti_aliasing
        else:
            self._corner_anti_aliasing = defaults.rectangle_corner_anti_aliasing
Ejemplo n.º 6
0
    def __init__(self, size, colour=None, line_width=None,
                 corner_rounding=None, corner_anti_aliasing=None,
                 position=None):
        """Create a rectangle.

        Parameters
        ----------
        size : (int, int)
            size (width, height) of the rectangle
        colour : (int, int, int), optional
            colour of the rectangle
        line_width : int, optional
            line width in pixels; 0 will result in a filled rectangle,
            as does a value < 0 or >= min(size)
        corner_rounding : float or (float, float, float, float), optional
            radius of the corners in percent of 0.5 * min(size);
        corner_anti_aliasing : int, optional
            anti aliasing parameter for rounded corners
            (good anti_aliasing with 10)
        position : (int, int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.rectangle_position
        Visual.__init__(self, position=position)
        self._size = size
        if colour is None:
            colour = defaults.rectangle_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.rectangle_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
        if corner_rounding is None:
            corner_rounding = defaults.rectangle_corner_rounding
        elif corner_rounding < 0 or corner_rounding > 100:
            raise AttributeError("corner_rounding must be >= 0 and < 100!")
        else:
            self._corner_rounding = corner_rounding
        if corner_anti_aliasing is not None:
            self._corner_anti_aliasing = corner_anti_aliasing
        else:
            self._corner_anti_aliasing = defaults.rectangle_corner_anti_aliasing
Ejemplo n.º 7
0
    def __init__(self, position=None, colour=None, line_width=None,
                 anti_aliasing=None):
        """Create a shape.

        A shape comprises always (0,0) as origin vertex

        Parameters
        ----------
        position : (int, int), optional
            position of the stimulus
        colour : (int, int, int), optional
            colour of the shape
        line_width : int, optional
            line width in pixels; 0 will result in a filled shape,
            as does a value < 0 or >= min(size) (optional)
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        if position is None:
            position = defaults.shape_position
        Visual.__init__(self, position)
        if colour is None:
            colour = defaults.shape_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is not None:
            self._line_width = line_width
        else:
            self._line_width = defaults.shape_line_width
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.shape_anti_aliasing

        self._vertices = []
        self._xy_points = []
        self._rect = []
        self._native_rotation = 0
        self._native_scaling = [1, 1]
        self._native_rotation_centre = (0, 0)
        self._rotation_centre_display_colour = None
        self._update_points()
Ejemplo n.º 8
0
    def __init__(self,
                 radii,
                 colour=None,
                 line_width=None,
                 position=None,
                 anti_aliasing=None):
        """Create an ellipse.

        Parameters
        ----------
        radii : (int, int)
            major and minor radii of the ellipse
        colour : (int, int, int), optional
            colour of the ellipse
        line_width : int, optional
            line width in pixels; 0 will result in a filled ellipse
            (as does a value < 0 or >= min(size))
        position : (int, int), optional
            position of the stimulus
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        if position is None:
            position = defaults.ellipse_position
        Visual.__init__(self, position)
        self._radii = radii
        self._size = [x * 2 for x in radii]
        if colour is None:
            colour = defaults.ellipse_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.ellipse_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.ellipse_anti_aliasing
Ejemplo n.º 9
0
    def __init__(self, filename, position=None):
        """Create a picture.

        Parameters
        ----------
        filename : str
            filename (incl. path) of the picture file
        position :(int,int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.picture_position
        Visual.__init__(self, position, log_comment=filename)
        self._filename = filename
        if not (os.path.isfile(self._filename)):
            raise IOError("The picture file '{0}' does not exist".format(
                unicode2str(filename)))
Ejemplo n.º 10
0
    def __init__(self, filename, position=None):
        """Create a picture.

        Parameters
        ----------
        filename : str
            filename (incl. path) of the picture file
        position :(int,int), optional
            position of the stimulus

        """

        if position is None:
            position = defaults.picture_position
        Visual.__init__(self, position, log_comment=filename)
        self._filename = filename
        if not(os.path.isfile(self._filename)):
            raise IOError("The picture file '{0}' does not exist".format(
                unicode2str(filename)))
Ejemplo n.º 11
0
    def __init__(self,
                 start_point,
                 end_point,
                 line_width,
                 colour=None,
                 anti_aliasing=None):
        """Create a line between two points.

        Parameters
        ----------
        start_point : (int, int)
            start point of the line (x,y)
        end_point : (int, int)
            end point of the line (x,y)
        line_width : int
            width of the plotted line
        colour : (int, int, int), optional
            line colour (int, int, int)
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        self._start_point = list(start_point)
        self._end_point = list(end_point)
        self._line_width = line_width
        Visual.__init__(self, position=[0, 0]),
        if colour is None:
            colour = defaults.line_colour
            if colour is None:
                colour = expyriment._active_exp.foreground_colour
        self._colour = colour
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.line_anti_aliasing

        s = misc.geometry.XYPoint(start_point)
        e = misc.geometry.XYPoint(end_point)
        d = misc.geometry.XYPoint(e.x - s.x, e.y - s.y)
        self._position[0] = s.x + (d.x / 2)
        self._position[1] = s.y + (d.y / 2)
Ejemplo n.º 12
0
    def __init__(self, radii, colour=None, line_width=None, position=None,
                 anti_aliasing=None):
        """Create an ellipse.

        Parameters
        ----------
        radii : (int, int)
            major and minor radii of the ellipse
        colour : (int, int, int), optional
            colour of the ellipse
        line_width : int, optional
            line width in pixels; 0 will result in a filled ellipse
            (as does a value < 0 or >= min(size))
        position : (int, int), optional
            position of the stimulus
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        if position is None:
            position = defaults.ellipse_position
        Visual.__init__(self, position)
        self._radii = radii
        self._size = [x * 2 for x in radii]
        if colour is None:
            colour = defaults.ellipse_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is None:
            line_width = defaults.ellipse_line_width
        elif line_width < 0 or line_width >= min(self._size):
            line_width = 0
        self._line_width = line_width
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.ellipse_anti_aliasing
Ejemplo n.º 13
0
    def __init__(self, size, position=None, colour=None):
        """Create a canvas.

        Parameters
        ----------
        size : (int, int)
            size of the canvas (int,int)
        position : (int, int), optional
            position of the stimulus
        colour : (int,int,int), optional
            colour of the canvas stimulus

        """

        if position is None:
            position = defaults.canvas_position
        Visual.__init__(self, position)
        self._size = size
        if colour is not None:
            self._colour = colour
        else:
            self._colour = defaults.canvas_colour
Ejemplo n.º 14
0
    def __init__(self, size, position=None, colour=None):
        """Create a canvas.

        Parameters
        ----------
        size : (int, int)
            size of the canvas (int,int)
        position : (int, int), optional
            position of the stimulus
        colour : (int,int,int), optional
            colour of the canvas stimulus

        """

        if position is None:
            position = defaults.canvas_position
        Visual.__init__(self, position)
        self._size = size
        if colour is not None:
            self._colour = colour
        else:
            self._colour = defaults.canvas_colour
Ejemplo n.º 15
0
    def __init__(self, start_point, end_point, line_width, colour=None,
                 anti_aliasing=None):
        """Create a line between two points.

        Parameters
        ----------
        start_point : (int, int)
            start point of the line (x,y)
        end_point : (int, int)
            end point of the line (x,y)
        line_width : int
            width of the plotted line
        colour : (int, int, int), optional
            line colour (int, int, int)
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        self._start_point = list(start_point)
        self._end_point = list(end_point)
        self._line_width = line_width
        Visual.__init__(self, position=[0,0]),
        if colour is None:
            colour = defaults.line_colour
            if colour is None:
                colour = expyriment._active_exp.foreground_colour
        self._colour = colour
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.line_anti_aliasing

        s = misc.geometry.XYPoint(start_point)
        e = misc.geometry.XYPoint(end_point)
        d = misc.geometry.XYPoint(e.x - s.x, e.y - s.y)
        self._position[0] = s.x + (d.x / 2)
        self._position[1] = s.y + (d.y / 2)
Ejemplo n.º 16
0
    def __init__(self, position=None, colour=None, line_width=None,
                 anti_aliasing=None):
        """Create a shape.

        A shape is an object described by vertices. For more details about
        vertex representations see:
        http://en.wikipedia.org/wiki/Vertex_(geometry)

        The vertex representation describes the contour of an object. Think of
        it as if you would draw with a pen. You start somewhere and make
        movements in different directions. A rectangle could be then for
        instance described by a right, a down, a left and an up movement
        (see example below).

        As always in Expyriment, the center of the surface of the shape is its
        position. That means, that with every new vertex, the shape size might
        change and the shape position will be realigned.

        Example
        -------
            r = stimuli.Shape(line_width = 0)
            r.add_vertex((100,0))
            r.add_vertices([(0,-50),(-100,0) ])
            # three vertices are sufficient, because shapes are always closed
            r.present()


        Parameters
        ----------
        position : (int, int), optional
            position of the stimulus
        colour : (int, int, int), optional
            colour of the shape
        line_width : int, optional
            line width in pixels; 0 will result in a filled shape,
            as does a value < 0 or >= min(size) (optional)
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        if position is None:
            position = defaults.shape_position
        Visual.__init__(self, position)
        if colour is None:
            colour = defaults.shape_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is not None:
            self._line_width = line_width
        else:
            self._line_width = defaults.shape_line_width
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.shape_anti_aliasing

        self._vertices = []
        self._xy_points = []
        self._rect = []
        self._native_rotation = 0
        self._native_scaling = [1, 1]
        self._native_rotation_centre = (0, 0)
        self._rotation_centre_display_colour = None
        self._update_points()
Ejemplo n.º 17
0
    def __init__(self, text, size, position=None, text_font=None,
                 text_size=None, text_bold=None, text_italic=None,
                 text_underline=None, text_justification=None,
                 text_colour=None, background_colour=None,
                 do_not_trim_words=None):
        """Create a text box.

        Notes
        -----
        text_font can be both, a name or path to a font file!
        When text_font is a name, Expyriment will try to find a font that
        best matches the given name.
        If no matching font can be found, or if the given font file cannot be
        found, the Pygame system default will be used.
        In any case the value of the attribute text_font will always
        resemble the font that is actually in use!

        Parameters
        ----------
        text : str
            text to wrap
        size : (int, int)
            size of the text box
        position : (int, int), optional
            position of the stimulus
        text_font : str, optional
            text font to use as a name or as a path to a font file
        text_size : int, optional
            size of the text
        text_bold : bool, optional
            font should be bold
        text_italic : bool, optional
            font should be italic
        text_underline : bool, optional
            font should get an underline
        text_justification : int, optional
            text justification, 0 (left), 1 (center), 2 (right)
        text_colour : (int, int, int), optional
            colour of the text
        background_colour : (int, int, int), optional
            background colour
        do_not_trim_words: bool, optional
            if True, words that exceed the width of the text box
            will be not be trimmed and an exception is raise instead.
            default: False

        """

        pygame.font.init()

        if position is None:
            position = defaults.textbox_position
        Visual.__init__(self, position)
        self._text = text
        self._size = size
        if text_size is None:
            text_size = defaults.textbox_text_size
        if text_size is not None:
            self._text_size = text_size
        else:
            self._text_size = expyriment._active_exp.text_size

        if text_font is None:
            text_font = defaults.textbox_text_font
        if text_font is not None:
            self._text_font = find_font(text_font)
        else:
            self._text_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(unicode2str(self._text_font, fse=True),
                                     10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(text_font))
        if text_bold is not None:
            self._text_bold = text_bold
        else:
            self._text_bold = defaults.textbox_text_bold
        if text_italic is not None:
            self._text_italic = text_italic
        else:
            self._text_italic = defaults.textbox_text_italic
        if text_underline is not None:
            self._text_underline = text_underline
        else:
            self._text_underline = defaults.textbox_text_underline
        if text_justification is not None:
            self._text_justification = text_justification
        else:
            self._text_justification = defaults.textbox_text_justification
        if text_colour is not None:
            self._text_colour = text_colour
        else:
            if defaults.textbox_text_colour is not None:
                self._text_colour = defaults.textbox_text_colour
            else:
                self._text_colour = expyriment._active_exp.foreground_colour
        if background_colour is not None:
            self._background_colour = background_colour
        else:
            self._background_colour = \
                defaults.textbox_background_colour
        if do_not_trim_words is not None:
            self._do_not_trim_words = do_not_trim_words
        else:
            self._do_not_trim_words = defaults.textbox_do_not_trim_words
Ejemplo n.º 18
0
    def __init__(self,
                 position=None,
                 colour=None,
                 line_width=None,
                 anti_aliasing=None):
        """Create a shape.

        A shape is an object described by vertices. For more details about
        vertex representations see:
        http://en.wikipedia.org/wiki/Vertex_(geometry)

        The vertex representation describes the contour of an object. Think of
        it as if you would draw with a pen. You start somewhere and make
        movements in different directions. A rectangle could be then for
        instance described by a right, a down, a left and an up movement
        (see example below).

        As always in Expyriment, the center of the surface of the shape is its
        position. That means, that with every new vertex, the shape size might
        change and the shape position will be realigned.

        Example
        -------
            r = stimuli.Shape(line_width = 0)
            r.add_vertex((100,0))
            r.add_vertices([(0,-50),(-100,0) ])
            # three vertices are sufficient, because shapes are always closed
            r.present()


        Parameters
        ----------
        position : (int, int), optional
            position of the stimulus
        colour : (int, int, int), optional
            colour of the shape
        line_width : int, optional
            line width in pixels; 0 will result in a filled shape,
            as does a value < 0 or >= min(size) (optional)
        anti_aliasing : int, optional
            anti aliasing parameter (good anti_aliasing with 10)

        """

        if position is None:
            position = defaults.shape_position
        Visual.__init__(self, position)
        if colour is None:
            colour = defaults.shape_colour
        if colour is not None:
            self._colour = colour
        else:
            self._colour = expyriment._active_exp.foreground_colour
        if line_width is not None:
            self._line_width = line_width
        else:
            self._line_width = defaults.shape_line_width
        if anti_aliasing is not None:
            self._anti_aliasing = anti_aliasing
        else:
            self._anti_aliasing = defaults.shape_anti_aliasing

        self._vertices = []
        self._xy_points = []
        self._rect = []
        self._native_rotation = 0
        self._native_scaling = [1, 1]
        self._native_rotation_centre = (0, 0)
        self._rotation_centre_display_colour = None
        self._update_points()
Ejemplo n.º 19
0
    def __init__(self, text, size, position=None, text_font=None,
                 text_size=None, text_bold=None, text_italic=None,
                 text_underline=None, text_justification=None,
                 text_colour=None, background_colour=None):
        """Create a text box.

        Notes
        -----
        text_font can be both, a name or path to a font file!
        When text_font is a name, Expyriment will try to find a font that
        best matches the given name.
        If no matching font can be found, or if the given font file cannot be
        found, the Pygame system default will be used.
        In any case the value of the attribute text_font will always
        resemble the font that is actually in use!

        Parameters
        ----------
        text : str
            text to wrap
        size : (int, int)
            size of the text box
        position : (int, int), optional
            position of the stimulus
        text_font : str, optional
            text font to use as a name or as a path to a font file
        text_size : int, optional
            size of the text
        text_bold : bool, optional
            font should be bold
        text_italic : bool, optional
            font should be italic
        text_underline : bool, optional
            font should get an underline
        text_justification : int, optional
            text justification, 0 (left), 1 (center), 2 (right)
        text_colour : (int, int, int), optional
            colour of the text
        background_colour : (int, int, int), optional
            background colour

        """

        pygame.font.init()

        if position is None:
            position = defaults.textbox_position
        Visual.__init__(self, position)
        self._text = text
        self._size = size
        if text_size is None:
            text_size = defaults.textbox_text_size
        if text_size is not None:
            self._text_size = text_size
        else:
            self._text_size = expyriment._active_exp.text_size

        if text_font is None:
            text_font = defaults.textbox_text_font
        if text_font is not None:
            self._text_font = find_font(text_font)
        else:
            self._text_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(unicode2str(self._text_font, fse=True),
                                     10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(text_font))
        if text_bold is not None:
            self._text_bold = text_bold
        else:
            self._text_bold = defaults.textbox_text_bold
        if text_italic is not None:
            self._text_italic = text_italic
        else:
            self._text_italic = defaults.textbox_text_italic
        if text_underline is not None:
            self._text_underline = text_underline
        else:
            self._text_underline = defaults.textbox_text_underline
        if text_justification is not None:
            self._text_justification = text_justification
        else:
            self._text_justification = defaults.textbox_text_justification
        if text_colour is not None:
            self._text_colour = text_colour
        else:
            if defaults.textbox_text_colour is not None:
                self._text_colour = defaults.textbox_text_colour
            else:
                self._text_colour = expyriment._active_exp.foreground_colour
        if background_colour is not None:
            self._background_colour = background_colour
        else:
            self._background_colour = \
                defaults.textbox_background_colour
Ejemplo n.º 20
0
    def __init__(self, text, position=None, text_font=None, text_size=None,
                 text_bold=None, text_italic=None, text_underline=None,
                 text_colour=None, background_colour=None, max_width=None):
        """Create a text line stimulus.

        NOTE: text_font can be both, a name or path to a font file!
        When text_font is a name, Expyriment will try to find a font that
        best matches the given name.
        If no matching font can be found, or if the given font file cannot be
        found, the Pygame system default will be used.
        In any case the value of the attribute text_font will always
        resemble the font that is actually in use!

        Parameters
        ----------
        text : str
            text to show (str)
        position : (int, int), optional
            position of the stimulus
        text_font : str, optional
            font to use as name or as path to a font file
        text_size : int, optional
            text size
        text_bold : bool, optional
            font should be bold
        text_italic : bool, optional
            font should be italic
        text_underline : bool, optional
            font should get an underline
        text_colour : (int, int, int), optional
            text colour
        background_colour : (int, int, int), optional
            background colour
        max_width: int, optional
            maximum surface width of the text line stimulus
            if this parameter is defined, text lines that exceed this
            surface width will be trimmed (indicated by a '~' as last letter)

        """

        pygame.font.init()
        if position is None:
            position = defaults.textline_position
        Visual.__init__(self, position, log_comment=text)
        self._text = text
        self._max_width = max_width
        if text_size is None:
            text_size = defaults.textline_text_size
        if text_size is not None:
            self._text_size = text_size
        else:
            self._text_size = expyriment._active_exp.text_size
        if text_font is None:
            text_font = defaults.textline_text_font
        if text_font is not None:
            self._text_font = find_font(text_font)
        else:
            self._text_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(unicode2str(self._text_font, fse=True),
                                     10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(text_font))
        if text_bold is not None:
            self._text_bold = text_bold
        else:
            self._text_bold = defaults.textline_text_bold
        if text_italic is not None:
            self._text_italic = text_italic
        else:
            self._text_italic = defaults.textline_text_italic
        if text_underline is not None:
            self._text_underline = text_underline
        else:
            self._text_underline = defaults.textline_text_underline
        if text_colour is None:
            text_colour = defaults.textline_text_colour
        if text_colour is not None:
            self._text_colour = text_colour
        else:
            self._text_colour = expyriment._active_exp.foreground_colour
        if background_colour is not None:
            self._background_colour = background_colour
        else:
            self._background_colour = \
                defaults.textline_background_colour
Ejemplo n.º 21
0
    def __init__(self, heading, text, position=None, heading_font=None,
                 heading_size=None, heading_bold=None, heading_italic=None,
                 heading_underline=None, heading_colour=None, text_font=None,
                 text_size=None, text_bold=None, text_italic=None,
                 text_underline=None, text_colour=None,
                 text_justification=None, background_colour=None, size=None):
        """Create a text screen.

        Parameters
        ----------
        heading : str
            heading of the text screen
        text : str
            text of the text screen
        position : (int, int), optional
            position of the stimulus
        heading_font : str, optional
            heading font to use
        heading_size : int, optional
            heading font size
        heading_bold : bool, optional
            heading should be bold
        heading_italic : bool, optional
            heading should be italic
        heading_underline : bool, optional
            heading should get an underline
        heading_colour : (int,int,int), optional
            heding colour
        text_font : str, optional
            text font to use
        text_size : int, optional
            text font size
        text_bold : bool, optional
            text should be bold
        text_italic : bool, optional
            text should be italic
        text_underline : bool, optional
            text should get an underline
        text_colour : (int,int,int), optional
            text colour
        text_justification : int, optional
            0 (Left), 1(center), 2(right) (int) (optional)
        background_colour : (int, int, int), optional
            background_colour
        size : (int, int), optional
            size of the text screen

        """

        if position is None:
            position = defaults.textscreen_position
        Visual.__init__(self, position, log_comment="text_screen")
        self._heading = heading
        self._text = text
        if heading_font is None:
            heading_font = defaults.textscreen_heading_font
        if heading_font is not None:
            self._heading_font = find_font(heading_font)
        else:
            self._heading_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(
                unicode2str(self._heading_font, fse=True), 10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(heading_font))
        if heading_size is None:
            heading_size = defaults.textscreen_heading_size
        if heading_size:
            self._heading_size = heading_size
        else:
            self._heading_size = int(expyriment._active_exp.text_size
                                     * 1.2)
        if heading_bold is not None:
            self._heading_bold = heading_bold
        else:
            self._heading_bold = defaults.textscreen_heading_bold
        if heading_italic is not None:
            self._heading_italic = heading_italic
        else:
            self._heading_italic = \
                defaults.textscreen_heading_italic
        if heading_underline is not None:
            self._heading_underline = heading_underline
        else:
            self._heading_underline = \
                defaults.textscreen_heading_underline
        if heading_colour is None:
            heading_colour = defaults.textscreen_heading_colour
        if heading_colour is not None:
            self._heading_colour = heading_colour
        else:
            self._heading_colour = expyriment._active_exp.foreground_colour
        if text_font is None:
            text_font = defaults.textscreen_text_font
        if text_font is not None:
            self._text_font = find_font(text_font)
        else:
            self._text_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(unicode2str(self._text_font, fse=True),
                                     10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(text_font))
        if text_size is None:
            self._text_size = defaults.textscreen_text_size
        if text_size is not None:
            self._text_size = text_size
        else:
            self._text_size = expyriment._active_exp.text_size
        if text_bold is not None:
            self._text_bold = text_bold
        else:
            self._text_bold = defaults.textscreen_text_bold
        if text_italic is not None:
            self._text_italic = text_italic
        else:
            self._text_italic = defaults.textscreen_text_italic
        if text_underline is not None:
            self._text_underline = text_underline
        else:
            self._text_underline = defaults.textscreen_text_underline
        if text_colour is None:
            text_colour = defaults.textscreen_text_colour
        if text_colour is not None:
            self._text_colour = text_colour
        else:
            self._text_colour = expyriment._active_exp.foreground_colour
        if text_justification is not None:
            self._text_justification = text_justification
        else:
            self._text_justification = \
                defaults.textscreen_text_justification
        if size is not None:
            self._size = size
        else:
            size = defaults.textscreen_size
            if size is None:
                try:
                    self._size = (
                        expyriment._active_exp.screen.surface.get_size()[0] -
                        expyriment._active_exp.screen.surface.get_size()[0]
                        / 5,
                        expyriment._active_exp.screen.surface.get_size()[1] -
                        expyriment._active_exp.screen.surface.get_size()[1]
                        / 5)
                except:
                    raise RuntimeError("Cannot get size of screen!")

        if background_colour is not None:
            self._background_colour = background_colour
        else:
            self._background_colour = \
                defaults.textscreen_background_colour
Ejemplo n.º 22
0
    def __init__(self,
                 text,
                 position=None,
                 text_font=None,
                 text_size=None,
                 text_bold=None,
                 text_italic=None,
                 text_underline=None,
                 text_colour=None,
                 background_colour=None,
                 max_width=None):
        """Create a text line stimulus.

        NOTE: text_font can be both, a name or path to a font file!
        When text_font is a name, Expyriment will try to find a font that
        best matches the given name.
        If no matching font can be found, or if the given font file cannot be
        found, the Pygame system default will be used.
        In any case the value of the attribute text_font will always
        resemble the font that is actually in use!

        Parameters
        ----------
        text : str
            text to show (str)
        position : (int, int), optional
            position of the stimulus
        text_font : str, optional
            font to use as name or as path to a font file
        text_size : int, optional
            text size
        text_bold : bool, optional
            font should be bold
        text_italic : bool, optional
            font should be italic
        text_underline : bool, optional
            font should get an underline
        text_colour : (int, int, int), optional
            text colour
        background_colour : (int, int, int), optional
            background colour
        max_width: int, optional
            maximum surface width of the text line stimulus
            if this parameter is defined, text lines that exceed this
            surface width will be trimmed (indicated by a '~' as last letter)

        """

        pygame.font.init()
        if position is None:
            position = defaults.textline_position
        Visual.__init__(self, position, log_comment=text)
        self._text = text
        self._max_width = max_width
        if text_size is None:
            text_size = defaults.textline_text_size
        if text_size is not None:
            self._text_size = text_size
        else:
            self._text_size = expyriment._active_exp.text_size
        if text_font is None:
            text_font = defaults.textline_text_font
        if text_font is not None:
            self._text_font = find_font(text_font)
        else:
            self._text_font = find_font(expyriment._active_exp.text_font)
        try:
            _font = pygame.font.Font(unicode2str(self._text_font, fse=True),
                                     10)
            _font = None
        except:
            raise IOError("Font '{0}' not found!".format(text_font))
        if text_bold is not None:
            self._text_bold = text_bold
        else:
            self._text_bold = defaults.textline_text_bold
        if text_italic is not None:
            self._text_italic = text_italic
        else:
            self._text_italic = defaults.textline_text_italic
        if text_underline is not None:
            self._text_underline = text_underline
        else:
            self._text_underline = defaults.textline_text_underline
        if text_colour is None:
            text_colour = defaults.textline_text_colour
        if text_colour is not None:
            self._text_colour = text_colour
        else:
            self._text_colour = expyriment._active_exp.foreground_colour
        if background_colour is not None:
            self._background_colour = background_colour
        else:
            self._background_colour = \
                defaults.textline_background_colour