def imagery_trial(self): fill() blit(self.origin_inactive, 5, self.origin_pos, flip_x=P.flip_x) flip() start = self.evm.trial_time if P.demo_mode or P.dm_always_show_cursor: show_mouse_cursor() at_origin = False while not at_origin: x, y, button = mouse_pos(return_button_state=True) left_button_down = button == 1 if self.within_boundary('origin', (x, y)) and left_button_down: at_origin = True self.rt = self.evm.trial_time - start ui_request() fill() blit(self.origin_active, 5, self.origin_pos, flip_x=P.flip_x) flip() while at_origin: x, y, button = mouse_pos(return_button_state=True) left_button_down = button == 1 if not (self.within_boundary('origin', (x, y)) and left_button_down): at_origin = False self.mt = self.evm.trial_time - (self.rt + start) if P.demo_mode: hide_mouse_cursor()
def response_listener(self, queue): self.__render__() num = self.which_boundary(mouse_pos()) if num != None: blit(self.mouseover, 5, self.__num_to_pos(int(num))) for e in queue: if e.type == sdl2.SDL_MOUSEBUTTONDOWN: self.response = int(num)
def get_mouse_state(self): x, y, b = mouse_pos(pump_event_queue=False, return_button_state=True) x = int(x) - (P.screen_c[0] - self.size[0] / 2) y = int(y) - (P.screen_c[1] - self.size[1] / 2) # Restrict mouse coords to within bounds of camera image x = clip(x, minimum=0, maximum=self.size[0]) y = clip(y, minimum=0, maximum=self.size[1]) if b != 1: # Register left clicks only b = 0 return ((x, y), b)
def draw(self): blit(self.line, 5, self.location) if self.ticks: self._draw_ticks() if self.__clicked: mp = mouse_pos() if self.__dragging: new_xpos = clip(mp[0]+self.__drag_offset, self.xmin, self.xmax) blit(self.button, 5, (new_xpos, self.location[1])) else: blit(self.button, 5, self.__abs_pos)
def _render(self): blit(self.q, location=self.origin, registration=8) for ans in self.order: a = self.answers[ans] ax, ay = a['location'] blit(a['text'], location=(ax, ay + int(self.q_pad*0.55)), registration=8) mouseover = self.which_boundary(mouse_pos()) if mouseover != None: a = self.answers[mouseover] hover = kld.Rectangle(self.width, a['height'], fill=TRANSLUCENT_GREY).render() blit(hover, 8, a['location'])
def slide(self): show_mouse_cursor() self.blit() dragging = False while True: if not dragging: m_pos = mouse_pos() for event in pump(True): if event.type == sdl2.SDL_KEYDOWN: ui_request(event.key.keysym) elif event.type in (sdl2.SDL_MOUSEBUTTONDOWN, sdl2.SDL_MOUSEBUTTONUP): within_button = self.within_boundary("button", m_pos) if self.button_active and within_button: return self.response dragging = self.within_boundary("handle", m_pos) if dragging: button_up = False off_handle = False for event in pump(True): if event.type == sdl2.SDL_KEYDOWN: ui_request(event.key.keysym) elif event.type == sdl2.SDL_MOUSEBUTTONUP: button_up = True off_handle = not self.within_boundary("handle", mouse_pos()) if off_handle or button_up: dragging = False self.response = self.handle_value() self.button_active = True flush() return -1 self.handle_pos = mouse_pos()[0] self.blit() return False
def gaze(self, return_integers=True, binocular_mode=EL_RIGHT_EYE): """Fetches the (x,y) coordinates of the participant's current gaze on the screen. In TryLink mode, this fetches the current coordinates of the mouse cursor. Args: return_integers (bool, optional): Whether to return the gaze coordinates as integers or floats. Defaults to True (integers). binocular_mode (int, optional): Tells the function which gaze coordinates to return for binocular samples. Can be any of ``EL_RIGHT_EYE`` (returns right eye gaze), ``EL_LEFT_EYE`` (returns left eye gaze), or ``EL_BOTH_EYES`` (returns average gaze of both eyes). Defaults to ``EL_RIGHT_EYE``. In TryLink mode, this has no effect. Returns: A :obj:`Tuple` containing the (x,y) pixel coordinates of the participant's gaze. """ gaze_pos = mouse_pos() return gaze_pos if return_integers else tuple(float(p) for p in gaze_pos)
def draw(self): blit(self.msg, 5, self.midpoint) mp = mouse_pos() if self.bounds.within(mp): blit(self.hover, 5, self.midpoint)