Beispiel #1
0
 def __init__(self,
              name,
              position,
              showtime,
              params,
              func=None,
              pargs=(),
              kwargs={}):
     lpos = position
     vpos = (position[0] + 5, position[1])
     self.statename = name
     self.showtime = showtime
     self.label = VisualStimuli.Text(position=lpos,
                                     anchor='right',
                                     on=True,
                                     text=name + ':',
                                     **params)
     self.value = VisualStimuli.Text(position=vpos,
                                     anchor='left',
                                     on=True,
                                     text=' ',
                                     **params)
     self.lastval = 0
     self.time = 0
     self.func = func
     self.pargs = pargs
     self.kwargs = kwargs
	def __init__(self, bci, classes=None, styles=('', '%d/%d', '%d%%')):
		if classes==None: classes = range(len(bci.introwavs)+1)

		self.classes = classes
		self.celltxt = []
		self.rowlabeltxt = []
		self.collabeltxt = []
		self.coltotaltxt = []
		self.rowtotaltxt = []
		self.grandtotaltxt = None
		self.styles = styles
		
		font_name = getattr(VisualStimuli.screen, 'monofont', None)
		font_size = 20
		
		labelprops = {'font_name':font_name, 'font_size':int(font_size*0.75), 'color':(0.8, 0.8, 0.8)}
		totalprops = {'font_name':font_name, 'font_size':int(font_size*0.65),  'color':(1.0, 1.0, 1.0), 'anchor':'center'}
		cellprops =  {'font_name':font_name, 'font_size':int(font_size*1.0),  'anchor':'center'}
		
		nc = len(self.classes)
		
		br = scr(1.0, -1.0)
		tl = scr(0.1, -0.1)
		mw = min(br[0]-tl[0], tl[1]-br[1])
		mh = mw
		tl = (br[0]-mw,br[1]+mh)
		
		stim = None
		for ystep in range(0, nc+2):
			y = tl[1] - mh * (float(ystep)+0.5)/(float(nc)+2.0)
			yin = (ystep > 0 and ystep <= nc)
			if yin: self.celltxt.append([])
			for xstep in range(0, nc+2):
				x = tl[0] + mw * (float(xstep)+0.5)/(float(nc)+2.0)
				xin = (xstep > 0 and xstep <= nc)
				if xstep == 0 and yin:
					stim = VisualStimuli.Text(position=(x,y), text=str(self.classes[ystep-1]), anchor='right', **labelprops)
					self.rowlabeltxt.append(stim)
				elif ystep == 0 and xin:
					stim = VisualStimuli.Text(position=(x,y), text=str(self.classes[xstep-1]), anchor='center', **labelprops)
					self.collabeltxt.append(stim)
				elif xstep > 0 and ystep > 0 and (xstep > nc or ystep > nc):
					stim = VisualStimuli.Text(position=(x,y), text='', **totalprops)
					if yin: self.rowtotaltxt.append(stim)
					elif xin: self.coltotaltxt.append(stim)
					else: self.grandtotaltxt = stim
				elif xin and yin:
					if xstep==ystep: color = (0, 0.7, 0)
					else: color = (0.4, 0.2, 0.2)
					stim = VisualStimuli.Text(position=(x,y), text = '', color=color, **cellprops)
					self.celltxt[-1].append(stim)
				if stim != None:
					if callable(getattr(bci, 'stimulus', None)):
						bci.stimulus('confusionmatrix_'+str(xstep)+'_'+str(ystep), stim)
					else:
						bci[len(bci.keys())] = stim
		self.reset()
Beispiel #3
0
    def __init__(self,
                 color=(0, 0, 1),
                 font_size=26,
                 pos=None,
                 thickness=10,
                 fliplr=False,
                 baseline=0.0,
                 fac=200.0 / 10.0,
                 horiz=False,
                 fmt='%+.2f',
                 font_name=None):

        if font_name == None:
            font_name = getattr(VisualStimuli.screen, 'monofont', None)

        opposite = {
            'left': 'right',
            'right': 'left',
            'top': 'bottom',
            'bottom': 'top'
        }
        txtanchor = 'right'
        txtpos = (pos[0] - font_size * 0.6, pos[1])
        barpos = tuple(pos)
        if fliplr:
            txtpos, barpos = barpos, txtpos
            txtanchor = opposite[txtanchor]
        if horiz: baranchor = opposite[txtanchor]
        else: baranchor = 'bottom'
        textobj = VisualStimuli.Text(position=txtpos,
                                     anchor=txtanchor,
                                     on=True,
                                     text=' ??? ',
                                     font_size=font_size,
                                     color=color,
                                     font_name=font_name)
        rectobj = VisualStimuli.Block(position=barpos,
                                      anchor=baranchor,
                                      on=True,
                                      size=(1, 1),
                                      color=color)
        self.__dict__.update({
            'baseline': baseline,
            'fac': fac,
            'horiz': horiz,
            'fmt': fmt,
            'thickness': thickness,
            'length': 0,
            'textobj': textobj,
            'rectobj': rectobj
        })  # fac is pixels/maxval
        self.set(val=0, text=' ??? ')
Beispiel #4
0
def PolygonTexture(frame=None,
                   vertices=((0.0, 1.0), (1.0, 1.0), (0.5, 0.0)),
                   color=(0, 0, 0),
                   anchor=None,
                   position=None,
                   size=None,
                   **kwargs):
    if frame == None:
        if size == None: size = (100, 100)
        if position == None: position = (50, 50)
        if anchor == None: anchor = 'center'
        frame = Boxes.box(size=size, position=position, anchor=anchor)
    else:
        if isinstance(frame, (list, tuple)):
            if len(frame) == 2: frame = [0, 0] + list(frame)
            frame = Boxes.box(rect=frame, sticky=True)
            if anchor != None: frame.anchor = anchor
        if size == None: size = frame.size
        if anchor == None: anchor = frame.anchor
        if position == None: position = frame.position
        frame = frame.copy()

    if len(color) >= 4: alpha = color[3]
    else: alpha = 1.0
    mask = (255, 255, 255, int(round(255.0 * alpha)))
    csize = (int(round(size[0])), int(round(size[1])))

    if isinstance(vertices, (float, int)):
        vertices = [i / float(vertices) for i in range(int(vertices) + 1)[:-1]]
    if False not in [isinstance(i, (float, int)) for i in vertices]:
        from math import cos, sin, pi
        vertices = [(0.5 + 0.5 * cos(2 * pi * a), 0.5 + 0.5 * sin(2 * pi * a))
                    for a in vertices]

    # map from source coordinates (default to lowerleft-upward normalized)
    # to upperleft-downward pixel coordinates
    if frame.internal == None:
        frame.internal = Boxes.box(left=0.0, right=1.0, bottom=0.0, top=1.0)
    frame.internal.bottom, frame.internal.top = frame.internal.top, frame.internal.bottom
    frame.anchor, frame.position, frame.size = 'lowerleft', (0, 0), csize
    vertices = [tuple(frame.map(v)) for v in vertices]

    canvas = Image.new("RGBA", csize, (0, 0, 0, 0))
    draw = ImageDraw.Draw(canvas)
    draw.polygon(vertices, fill=mask, outline=None)
    from CurrentRenderer import VisualStimuli
    return VisualStimuli.ImageStimulus(texture=canvas,
                                       size=size,
                                       anchor=anchor,
                                       position=position,
                                       color=color[:3],
                                       **kwargs)
Beispiel #5
0
def Block(position=(10, 10),
          size=(10, 10),
          color=(0, 0, 1),
          anchor='center',
          **kwargs):

    if len(color) >= 4: alpha = color[3]
    else: alpha = 1.0
    mask = (255, 255, 255, int(round(255.0 * alpha)))
    csize = (1, 1)
    canvas = Image.new("RGBA", csize, mask)
    from CurrentRenderer import VisualStimuli
    return VisualStimuli.ImageStimulus(texture=canvas,
                                       size=size,
                                       anchor=anchor,
                                       position=position,
                                       color=color[:3],
                                       **kwargs)
Beispiel #6
0
def Disc(position=(10, 10),
         size=(1, 1),
         radius=1,
         color=(0, 0, 1),
         anchor='center',
         **kwargs):

    size = tuple([x * radius * 2 for x in size])
    if len(color) >= 4: alpha = color[3]
    else: alpha = 1.0
    mask = (255, 255, 255, int(round(255.0 * alpha)))
    csize = (max(int(round(size[0])), 100), max(int(round(size[1])), 100))

    canvas = Image.new("RGBA", csize, (0, 0, 0, 0))
    draw = ImageDraw.Draw(canvas)
    draw.ellipse(((0.0, 0.0), csize), fill=mask, outline=None)
    from CurrentRenderer import VisualStimuli
    return VisualStimuli.ImageStimulus(texture=canvas,
                                       size=size,
                                       anchor=anchor,
                                       position=position,
                                       color=color[:3],
                                       **kwargs)