def _get_feedback_rect_colors(exp_info): colors_param = exp_info.config.feedback_btn_colours if colors_param is None: if exp_info.config.feedback_place == 'button': return xpy.misc.constants.C_GREEN, xpy.misc.constants.C_GREEN elif exp_info.config.feedback_place == 'middle': return xpy.misc.constants.C_GREEN, xpy.misc.constants.C_RED else: raise ttrk.ValueError( 'Unsupported config.feedback_place ({:})'.format( exp_info.config.feedback_place)) if u.is_rgb(colors_param): return colors_param, colors_param if u.is_collection(colors_param) and u.is_rgb( colors_param[0]) and u.is_rgb(colors_param[1]): return tuple(colors_param) else: raise ttrk.ValueError( 'Invalid config.feedback_btn_colours ({:}) - expecting a color (Red,Green,Blue) or an array.tuple with two colors' .format(colors_param))
def _get_colors_as_ints(self, value, attr_name): if u.is_rgb(value): value = (value, ) _u.validate_attr_is_collection(self, attr_name, value, allow_set=True) colors = set() for c in value: if not u.is_rgb(c): raise trajtracker.ValueError( _u.ErrMsg.attr_invalid_type(type(self), attr_name, "color", value)) colors.add(u.color_rgb_to_num(c)) return colors
def _get_colors_as_ints(self, value, attr_name): if u.is_rgb(value): value = (value, ) _u.validate_attr_type(self, attr_name, value, (list, tuple, set)) colors = set() for c in value: if not u.is_rgb(c): raise ValueError( _u.ErrMsg.attr_invalid_type(type(self), attr_name, "color", value)) colors.add(u.color_rgb_to_num(c)) return colors
def _get_response_buttons_colors(exp_info): color = exp_info.config.resp_btn_colours if u.is_rgb(color): #-- One color given return color, color if not trajtracker.utils.is_collection(color) or len(color) != 2 or \ not u.is_rgb(color[0]) or not u.is_rgb(color[1]): raise ttrk.ValueError( "config.resp_btn_colours should be either a color (R,G,B) " + "or a pair of colors (left_rgb, right_rgb). " + "The value provided is invalid: {:}".format(color)) return color
def last_validated_rgb(self, value): if u.is_rgb(value): self._last_validated_rgb = u.color_rgb_to_num(value) else: if value is not None: _u.validate_attr_numeric(self, "last_validated_rgb", value) _u.validate_attr_not_negative(self, "last_validated_rgb", value) self._last_validated_rgb = value self._log_setter("last_validated_rgb")
def _is_multiple_values(self, value, prop_type): if type(prop_type) == type: return isinstance(value, (tuple, list, np.ndarray)) elif prop_type == ttrk.TYPE_RGB: return isinstance(value, (tuple, list, np.ndarray)) and \ (len(value) == 0 or u.is_rgb(value[0])) elif prop_type == ttrk.TYPE_COORD: return isinstance(value, (tuple, list, np.ndarray)) and \ (len(value) == 0 or isinstance(value[0], (tuple, list, XYPoint, np.ndarray))) else: raise Exception("Trajtracker internal error: {:}._validate_attr_type() does not support type={:}".format( _u.get_type_name(self), prop_type))
def validate_config_param_type(param_name, param_type, param_value, none_allowed=False, type_name=None): """ Validate that a certain configuration parameter is of the specified type """ if none_allowed and param_value is None: return if isinstance(param_type, (type, tuple)): if not isinstance(param_value, param_type): if type_name is None: type_name = _u.get_type_name(param_type) raise ttrk.TypeError("config.{:} was set to a non-{:} value ({:})".format(param_name, type_name, param_value)) elif param_type == ttrk.TYPE_RGB: if not u.is_rgb(param_value): raise ttrk.TypeError("config.{:} was set to an invalid value ({:}) - expecting (red,green,blue)". format(param_name, param_value)) elif param_type == ttrk.TYPE_COORD: if not u.is_coord(param_value, allow_float=True): raise ttrk.TypeError("config.{:} was set to an invalid value ({:}) - expecting (x, y)". format(param_name, param_value)) if isinstance(param_value, geometry.XYPoint): param_value = param_value.x, param_value.y elif param_type == ttrk.TYPE_SIZE: if not u.is_collection(param_value) or \ len(param_value) != 2 or \ not isinstance(param_value[0], numbers.Number) or \ not isinstance(param_value[1], numbers.Number): raise ttrk.TypeError("config.{:} was set to an invalid value '{:}' - expecting size, i.e., (width, height) with two integers". format(param_name, param_value)) elif param_type == ttrk.TYPE_CALLABLE: if "__call__" not in dir(param_value): raise ttrk.TypeError( "config.{:} was set to a non-callable value ({:})".format(param_name, param_value)) else: raise Exception("trajtracker internal error: unsupported type '{:}'".format(param_type)) return param_value