Example #1
0
	def set_config(self, **cfg):

		# Remap deprecated names
		if u'bgcolor' in cfg:
			warnings.warn(u'bgcolor is a deprecated style argument. '
				'Use background_color instead.',
				DeprecationWarning)
			cfg[u'background_color'] = cfg[u'bgcolor']
			del cfg['bgcolor']
		if u'fgcolor' in cfg:
			warnings.warn(u'fgcolor is a deprecated style argument. '
				'Use color instead.', DeprecationWarning)
			cfg[u'color'] = cfg[u'fgcolor']
			del cfg['fgcolor']
		if u'font_style' in cfg:
			warnings.warn(u'font_style is a deprecated style argument. '
				'Use font_family instead.',	DeprecationWarning)
			cfg[u'font_family'] = cfg[u'font_style']
			del cfg['font_style']
		# Convert color to backend specific colors
		if u'color' in cfg and not hasattr(cfg[u'color'], u'backend_color'):
			cfg[u'color'] = color(self.experiment, cfg[u'color'])
		if u'background_color' in cfg \
			and not hasattr(cfg[u'background_color'], u'backend_color'):
			cfg[u'background_color'] = color(self.experiment,
				cfg[u'background_color'])
		backend.set_config(self, **cfg)
Example #2
0
	def __init__(self, canvas, **properties):

		"""
		desc:
			Constructor.

		arguments:
			canvas:
				desc:	The canvas of which this element is part.
				type:	Canvas

		keyword-dict:
			properties:
				A dict with style arguments such as color, fill, etc.
		"""

		self._canvas = canvas
		if u'visible' not in properties:
			properties[u'visible'] = True
		if u'color' in properties:
			properties[u'color'] = color(self.experiment, properties[u'color'])
		self._assert_numeric(**{
			prop : val
			for prop, val in properties.items()
			if prop in NUMERIC_PROPERTIES
		})
		self._properties = properties
		for prop in self.property_names:
			self._create_property(prop)
		if canvas.auto_prepare and self.visible:
			self.prepare()
Example #3
0
	def _setter(key, self, val):

		"""
		visible: False

		desc:
			A setter for dynamically created properties.

		arguments:
			key:
				desc:	A property name.
				type:	str
			self:
				desc:	The Element instance. For technical reasons this is
						passed as the second argument.
				type:	Element.
			val:
				desc:	A property value.
				type:	Any
		"""

		if key in NUMERIC_PROPERTIES:
			self._assert_numeric(**{key: val})
		if key == u'color':
			val = color(self.experiment, val)
		self._properties[key] = val
		self._on_attribute_change(**{key: val})
	def prepare_for_playback(self):
		"""
		Setup screen for playback (Just fills the screen with the background color for this backend)
		"""
		# Create back-end-specific color object
		c = color(self.main_player.experiment, self.main_player.experiment.background)
		# Get color.backend_color, which is for example a pygame.Color object
		
		# Fill surface with background color
		self.screen.fill(c.backend_color)
		self.last_drawn_frame_no = 0
Example #5
0
    def prepare_for_playback(self):
        """
		Setup screen for playback (Just fills the screen with the background color for this backend)
		"""
        # Create back-end-specific color object
        c = color(self.main_player.experiment,
                  self.main_player.experiment.background)
        # Get color.backend_color, which is for example a pygame.Color object

        # Fill surface with background color
        self.screen.fill(c.backend_color)
        self.last_drawn_frame_no = 0
Example #6
0
    def init_display(experiment):

        global _experiment, _old_gamma
        _experiment = experiment
        # Set the PsychoPy monitor, default to testMonitor
        monitor = experiment.var.get(u'psychopy_monitor', u'testMonitor')
        waitblanking = experiment.var.get(u'psychopy_waitblanking', u'yes', \
         [u'yes', u'no']) == u'yes'
        screen = experiment.var.get(u'psychopy_screen', 0)
        # Print some information to the debug window
        print(u'openexp._canvas.psycho.init_display(): waitblanking = %s' % \
         waitblanking)
        print(u'openexp._canvas.psycho.init_display(): monitor = %s' % monitor)
        print(u'openexp._canvas.psycho.init_display(): screen = %s' % screen)
        # Initialize the PsychoPy window and set various functions

        experiment.window = visual.Window(
            experiment.resolution(),
            screen=screen,
            waitBlanking=waitblanking,
            fullscr=experiment.var.fullscreen == u'yes',
            monitor=monitor,
            units=u'pix',
            rgb=color(experiment, experiment.var.background).backend_color,
            winType=u'pyglet',
            allowStencil=True)
        event.Mouse(visible=False, win=experiment.window)
        experiment.window.winHandle.set_caption(
            u'OpenSesame (PsychoPy backend)')
        # Set Gamma value if specified
        gamma = experiment.var.get(u'psychopy_gamma', u'unchanged')
        if type(gamma) in (int, float) and gamma > 0:
            _old_gamma = experiment.window.gamma
            experiment.window.setGamma(gamma)
        elif gamma != u'unchanged':
            raise osexception( \
             u'Gamma should be a positive numeric value or "unchanged"')
        # Register the built-in OpenSesame fonts.
        for font in [
                u'sans', u'serif', u'mono', u'arabic', u'hebrew', u'hindi',
                u'chinese-japanese-korean'
        ]:
            font_path = experiment.resource(u'%s.ttf' % font)
            register_font(font_path)
        # Override the default quit function, so that the application is not exited
        core.quit = _psychopy_clean_quit
        # Optionally change the logging level to avoid a lot of warnings in the
        # debug window
        if experiment.var.get(u'psychopy_suppress_warnings', u'yes'):
            logging.console.setLevel(logging.CRITICAL)
        # We need to initialize the pygame mixer, because PsychoPy uses that as well
        pygame.mixer.init()
Example #7
0
	def init_display(experiment):

		global _experiment, _old_gamma
		_experiment = experiment
		# Set the PsychoPy monitor, default to testMonitor
		monitor = experiment.var.get(u'psychopy_monitor', u'testMonitor')
		waitblanking = experiment.var.get(u'psychopy_waitblanking', u'yes', \
			[u'yes', u'no']) == u'yes'
		screen = experiment.var.get(u'psychopy_screen', 0)
		# Print some information to the debug window
		print(u'openexp._canvas.psycho.init_display(): waitblanking = %s' % \
			waitblanking)
		print(u'openexp._canvas.psycho.init_display(): monitor = %s' % monitor)
		print(u'openexp._canvas.psycho.init_display(): screen = %s' % screen)
		# Initialize the PsychoPy window and set various functions

		experiment.window = visual.Window(experiment.resolution(),
			screen=screen, waitBlanking=waitblanking,
			fullscr=experiment.var.fullscreen==u'yes', monitor=monitor,
			units=u'pix',
			rgb=color(experiment, experiment.var.background).backend_color,
			winType=u'pyglet', allowStencil=True)
		event.Mouse(visible=False, win=experiment.window)
		experiment.window.winHandle.set_caption(u'OpenSesame (PsychoPy backend)')
		# Set Gamma value if specified
		gamma = experiment.var.get(u'psychopy_gamma', u'unchanged')
		if type(gamma) in (int, float) and gamma > 0:
			_old_gamma = experiment.window.gamma
			experiment.window.setGamma(gamma)
		elif gamma != u'unchanged':
			raise osexception( \
				u'Gamma should be a positive numeric value or "unchanged"')
		# Register the built-in OpenSesame fonts.
		for font in [u'sans', u'serif', u'mono', u'arabic', u'hebrew', u'hindi',
			u'chinese-japanese-korean']:
			font_path = experiment.resource(u'%s.ttf' % font)
			register_font(font_path)
		# Override the default quit function, so that the application is not exited
		core.quit = _psychopy_clean_quit
		# Optionally change the logging level to avoid a lot of warnings in the
		# debug window
		if experiment.var.get(u'psychopy_suppress_warnings', u'yes'):
			logging.console.setLevel(logging.CRITICAL)
		# We need to initialize the pygame mixer, because PsychoPy uses that as well
		pygame.mixer.init()