def pause(self, time_for_feedback=60 * 2, text_saving_time="Please wait..."): """returns true if feedback is OK (that means data are saved) waits for a particular for feedback """ self.udp.send(rc.Command.PAUSE) self.clock.reset_stopwatch() kbd = keyboard(self._exp) if text_saving_time != None: cnv = canvas(self._exp) cnv.text(text_saving_time) cnv.show() while True: rtn = self.udp.poll() kbd.get_key(timeout=1) if rtn == rc.Command.FEEDBACK_PAUSED: break if self.clock.stopwatch_time > time_for_feedback * 1000: return False if text_saving_time != None: canvas(self._exp).show() return True
def run(self): """Runs the item.""" self.experiment.var.offline = self.var.offline if self.var.roles == '': self._roles = None else: self._roles = self.var.roles.replace(',', ' ') self._roles = self._roles.split() if self.var.display_messages == 'yes': from openexp.canvas import canvas message_canvas = canvas(self.experiment) message_canvas.text('Connecting with the session...') message_canvas.show() self.experiment._connection = Connection( server_uri=self.var.server, db_name=self.var.db_name, client_name=self.experiment.subject_nr, design=self.var.design, group_size=self.var.group_size, groupings_needed=self.var.groupings_needed, roles=self._roles, ghosts=self.var.ghosts == 'yes', initial_data={ 'os_status': {}, 'os_variables': {} }, offline=self.var.offline == 'yes') if self.identical_rseed == u'yes': print 'Set random seed depending on psynteract session' import random random.seed(self.experiment._connection.session) if self.var.display_messages == 'yes': self.experiment.clock.sleep(1000) message_canvas = canvas(self.experiment) message_canvas.text('Waiting for the session to start...') message_canvas.show() self.experiment._connection.wait( lambda doc: doc['status'] == 'running', check="session") self.experiment.var.own_id = self.experiment._connection._id self.experiment.var.current_role = self.experiment._connection.current_role self.experiment.var.current_grouping = self.experiment._connection.current_grouping current_partners = self.experiment._connection.current_partners for i, p in enumerate(current_partners): self.experiment.var.set('partner{:02d}_id'.format(i + 1), p) if self.var.display_messages == 'yes': self.experiment.clock.sleep(1000)
def hold_check(self, holding_time=3000, left_pos=-200, right_pos=200, radius=50, col_fine='gray', col_too_low='green', col_too_strong='red'): kbd = keyboard(self._exp) blank = canvas(self._exp) blank.show() self.udp.send("hold:test") self.clock.reset_stopwatch() prev_lv = None while True: self.udp.clear_receive_buffer() lv = [ rc.get_data(rc.Command.GET_THRESHOLD_LEVEL), rc.get_data(rc.Command.GET_THRESHOLD_LEVEL2) ] if prev_lv != lv: # level has changes self.clock.reset_stopwatch() prev_lv = lv cnv = canvas(self._exp) for i, pos in enumerate([left_pos, right_pos]): if lv[i] == WEAK: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_too_low) elif lv[i] == STRONG: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_too_strong) elif lv[i] == FINE: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_fine) cnv.show() key, _ = kbd.get_key(timeout=0) if (lv == [FINE, FINE] and self.clock.stopwatch_time > holding_time) or\ (key is not None): break blank.show()
def run(self): """Runs the item.""" self.experiment.var.offline = self.var.offline if self.var.roles=='': self._roles = None else: self._roles = self.var.roles.replace(',', ' ') self._roles = self._roles.split() if self.var.display_messages == 'yes': from openexp.canvas import canvas message_canvas= canvas(self.experiment) message_canvas.text('Connecting with the session...') message_canvas.show() self.experiment._connection = Connection( server_uri=self.var.server,db_name=self.var.db_name, client_name=self.experiment.subject_nr, design=self.var.design, group_size=self.var.group_size, groupings_needed=self.var.groupings_needed, roles=self._roles, ghosts=self.var.ghosts=='yes', initial_data={'os_status':{},'os_variables':{}}, offline=self.var.offline=='yes') if self.identical_rseed == u'yes': print 'Set random seed depending on psynteract session' import random random.seed(self.experiment._connection.session) if self.var.display_messages == 'yes': self.experiment.clock.sleep(1000) message_canvas= canvas(self.experiment) message_canvas.text('Waiting for the session to start...') message_canvas.show() self.experiment._connection.wait(lambda doc: doc['status'] == 'running', check="session") self.experiment.var.own_id = self.experiment._connection._id self.experiment.var.current_role = self.experiment._connection.current_role self.experiment.var.current_grouping = self.experiment._connection.current_grouping current_partners = self.experiment._connection.current_partners for i,p in enumerate(current_partners): self.experiment.var.set('partner{:02d}_id'.format(i+1),p) if self.var.display_messages == 'yes': self.experiment.clock.sleep(1000)
def offline_canvas(self): """ A convenience function to create a new offline canvas """ return canvas.canvas(self.experiment, self.get("background"), self.get("foreground"))
def prepare(self): """Prepare a canvas with a fixation dot.""" # Call parent functions. item.prepare(self) generic_response.prepare(self) # Create a canvas. self.c = canvas(self.experiment, self.get(u'background'), \ self.get(u'foreground')) # Set the coordinates. self._x = self.get(u'x') + self.c.xcenter() self._y = self.get(u'y') + self.c.ycenter() # Draw the fixation dot. self.c.set_penwidth(self.get(u'penwidth')) if self.style == u'default': self.c.fixdot(self._x, self._y) elif self.style == u'filled': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, True) elif self.style == u'filled-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, True) elif self.style == u'empty': self.c.ellipse(self._x - 10, self._y - 10, 20, 20, False) elif self.style == u'empty-small': self.c.ellipse(self._x - 5, self._y - 5, 10, 10, False) elif self.style == u'cross': self.c.line(self._x - 10, self._y, self._x + 10, self._y) self.c.line(self._x, self._y - 10, self._x, self._y + 10) elif self.style == u'cross-small': self.c.line(self._x - 5, self._y, self._x + 5, self._y) self.c.line(self._x, self._y - 5, self._x, self._y + 5)
def __init__(self, experiment, tracker): """ Constructor Arguments: experiment -- opensesame experiment tracker -- an eyelink instance """ pylink.EyeLinkCustomDisplay.__init__(self) self.experiment = experiment self.my_canvas = canvas(self.experiment) self.my_keyboard = keyboard(self.experiment, timeout=0) self.my_mouse = mouse(self.experiment) self.__target_beep__ = synth(self.experiment, length = 50) self.__target_beep__done__ = synth(self.experiment, freq = 880, length = 200) self.__target_beep__error__ = synth(self.experiment, freq = 220, length = 200) self.state = None self.imagebuffer = array.array('l') self.pal = None self.size = (0,0) self.tmp_file = os.path.join(tempfile.gettempdir(), '__eyelink__.jpg') self.set_tracker(tracker) self.last_mouse_state = -1 self.experiment.eyelink_esc_pressed = False
def prepare(self): # Call parent functions. item.prepare(self) # Prepare your plug-in here. generic_response.prepare(self) path = self.experiment.pool[self.var.media_src] self.c = canvas(self.experiment, background_color=self.var.background, color=self.var.foreground) if not os.path.isfile(path): raise osexception(u"Media file '%s' was not found." % (os.path.basename(path), self.name)) if self.var.HMDtype == u"Oculus DK1 (1280x800px)" and self.var.stereoscopic == u"No (No 3D depth)" and self.var.isVideo == u"No": self.c.image(path, x=-252, y=0.0) self.c.image(path, x=252, y=0.0) elif self.var.HMDtype == u"Oculus DK1 (1280x800px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"Oculus DK2 (1920x1080px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-378, y=0.0) self.c.image(path, x=378, y=0.0) elif self.var.HMDtype == u"Oculus DK2 (1920x1080px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"Oculus Rift 2016 (2160x1200px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-415.8, y=0.0) self.c.image(path, x=415.8, y=0.0) elif self.var.HMDtype == u"Oculus Rift 2016 (2160x1200px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0) elif self.var.HMDtype == u"HTC Vive (2160x1200px)" and self.var.stereoscopic == u"No" and self.var.isVideo == u"No": self.c.image(path, x=-415.8, y=0.0) self.c.image(path, x=415.8, y=0.0) elif self.var.HMDtype == u"HTC Vive (2160x1200px)" and self.var.stereoscopic == u"Yes" and self.var.isVideo == u"No": self.c.image(path, x=0, y=0.0)
def create(self, screen=None): """See _display.pygamescreen.PyGameScreen""" if screen != None: self.canvas = screen.copy() else: self.canvas = canvas(self.experiment)
def run(self): """Runs the item.""" current_wait = self.name if self.name in self.experiment._connection.doc['data']['os_status']: self.experiment._connection.doc['data']['os_status'][current_wait]+=1 else: self.experiment._connection.doc['data']['os_status'][current_wait]=1 current_status = self.experiment._connection.doc['data']['os_status'][current_wait] if self.var.display_message == 'yes': from openexp.canvas import canvas message_canvas= canvas(self.experiment) message_canvas.text(self.var.waiting_message) message_canvas.show() if self.experiment.var.offline == 'no': self.experiment._connection.push() def check_waits(doc): check = False if current_wait in doc['data']['os_status']: check = doc['data']['os_status'][current_wait]>=current_status return check self.experiment._connection.wait(check_waits) if self.experiment.var.offline == 'no': self.experiment._connection.push() self.experiment.clock.sleep(self.var.additional_wait)
def run(self): """Runs the item.""" current_wait = self.name if self.name in self.experiment._connection.doc["data"]["os_status"]: self.experiment._connection.doc["data"]["os_status"][current_wait] += 1 else: self.experiment._connection.doc["data"]["os_status"][current_wait] = 1 current_status = self.experiment._connection.doc["data"]["os_status"][current_wait] if self.var.display_message == "yes": from openexp.canvas import canvas message_canvas = canvas(self.experiment) message_canvas.text(self.var.waiting_message) message_canvas.show() if self.experiment.var.offline == "no": self.experiment._connection.push() def check_waits(doc): check = False if current_wait in doc["data"]["os_status"]: check = doc["data"]["os_status"][current_wait] >= current_status return check self.experiment._connection.wait(check_waits) if self.experiment.var.offline == "no": self.experiment._connection.push() self.experiment.clock.sleep(self.var.additional_wait)
def draw_calibration_canvas(self, x, y): """ desc: A hook to prepare the canvas with the clibration target. arguments: x: desc: The X coordinate. type: int y: desc: The Y coordinate. type: int """ dc_canvas = canvas(self.experiment) # Coordinates are always sent in 0,0=top-left mode, so we need to # correct for this if we're using uniform coordinates. if self.var.uniform_coordinates == u'yes': x -= dc_canvas._xcenter y -= dc_canvas._ycenter dc_canvas.fixdot(x, y, style=u'large-open') if self.var.calbeep == 'yes': self.beep.play() dc_canvas.show()
def confirm_abort_experiment(self): """ Asks for confirmation before aborting the experiment. Displays a # confirmation screen, collects the response, and acts accordingly. Exceptions: Raises a response_error upon confirmation. Returns: False if no confirmation was given. """ # Display the confirmation screen conf_canvas = canvas(self.experiment) conf_kb = keyboard(self.experiment, timeout=None) yc = conf_canvas.ycenter() ld = 40 conf_canvas.clear() conf_canvas.text(u'Really abort experiment?', y=yc-3*ld) conf_canvas.text(u'Press \'Y\' to abort', y=yc-0.5*ld) conf_canvas.text(u'Press any other key or wait 5s to go to setup', \ y = yc+0.5*ld) conf_canvas.show() # process the response: try: key, time = conf_kb.get_key(timeout=5000) except: return False # if confirmation, close experiment if key == u'y': raise exceptions.runtime_error(u'The experiment was aborted') else: return False
def prepare(self): """See item.""" base_response_item.prepare(self) # Create a canvas. self.canvas = canvas(self.experiment, background_color=self.var.background, color=self.var.foreground, penwidth=self.var.penwidth) # Set the coordinates. self._x = self.var.x self._y = self.var.y if self.var.uniform_coordinates != u'yes': self._x += self.canvas.width/2 self._y += self.canvas.height/2 # For backwards compatibility, we support a few special fixdot styles if self.var.style == u'filled': self.canvas.ellipse(self._x - 10, self._y - 10, 20, 20, fill=True) elif self.var.style == u'filled-small': self.canvas.ellipse(self._x - 5, self._y - 5, 10, 10, fill=True) elif self.var.style == u'empty': self.canvas.ellipse(self._x - 10, self._y - 10, 20, 20, fill=False) elif self.var.style == u'empty-small': self.canvas.ellipse(self._x - 5, self._y - 5, 10, 10, fill=False) elif self.var.style == u'cross': self.canvas.line(self._x - 10, self._y, self._x + 10, self._y) self.canvas.line(self._x, self._y - 10, self._x, self._y + 10) elif self.var.style == u'cross-small': self.canvas.line(self._x - 5, self._y, self._x + 5, self._y) self.canvas.line(self._x, self._y - 5, self._x, self._y + 5) # But the new way is to use the style keyword else: self.canvas.fixdot(self._x, self._y, style=self.var.style)
def prepare(self): """The preparation phase of the plug-in goes here.""" # Call the parent constructor. item.prepare(self) # Here simply prepare a canvas with a fixatio dot. self.c = canvas(self.experiment) self.c.fixdot()
def fill(self, screen=None): # See _display.basedisplay.BaseDisplay for documentation if screen != None: self.canvas = screen.canvas else: self.canvas = canvas(self.experiment)
def make_connection(self, ip=FORCE_SERVER_IP): """hand shake and filename, returns forceDAQ version """ kbd = keyboard(self._exp) cnv = canvas(self._exp) cnv.text("Prepare force recording <br> press key if ready") cnv.show() kbd.get_key() canvas(self._exp).show() while not self.udp.connect_peer(ip): cnv = canvas(self._exp) cnv.text("ERROR while connecting to server <br> try again or Q to quit") cnv.show() key = kbd.get_key() if key[0] == u'q': msg = "Experiment quitted by user!" self.udp.send(rc.Command.QUIT) print(msg) self._exp.end() exit() canvas(self._exp).show() self.clock.wait(300) cnv = canvas(self._exp) cnv.text("Connected") cnv.show() self.clock.wait(500) self.udp.send(rc.Command.FILENAME.decode('utf-8', 'replace') + "{0}_{1}.csv".format(self.experiment_name, self.subject_number)) rtn = self.udp.receive(5) # paused if rtn is None: msg = "Force server not responding" cnv = canvas(self._exp) cnv.text(msg) cnv.show() kbd.get_key() self.udp.send(rc.Command.QUIT) print(msg) self._exp.end() exit() version = rc.get_data(rc.Command.GET_VERSION) if version is None: version = "" # FIXME Why is version somethimes None cnv = canvas(self._exp) cnv.text("Connected <br> Version " + version) cnv.show() self.clock.wait(1000) return version
def __init__(self, experiment, cols=2, rows=2, spacing=10, margins=(100, 100, 100, 100), theme=u'gray', item=None): """<DOC> Constructor Arguments: experiment -- An OpenSesame experiment. Keyword arguments: cols -- The number of columns (as int) or a list that specifies the # number and relative size of the columns. For example, '[1,2,1]' # will create 3 columns where the middle one is twice as large as # the outer ones (default=2). rows -- Analogous to 'cols' (default=2). spacing -- The amount of empty space between the widgets (default=10). margins -- The amount of empty space around the form. This is specified # as a list, like so [top-margin, right-margin, bottom-margin, # left-margin] (default=[100, 100, 100, 100]). theme -- The theme for the widgets (default='gray'). item -- The item of which the form is part (default=None). </DOC>""" # Normalize the column and row sizes so that they add up to 1 if type(cols) == int: self.cols = [1./cols]*cols else: cols = type_check.float_list(cols, u'form columns', min_len=1) self.cols = [float(c)/sum(cols) for c in cols] if type(rows) == int: self.rows = [1./rows]*rows else: rows = type_check.float_list(rows, u'form rows', min_len=1) self.rows = [float(r)/sum(rows) for r in rows] self.experiment = experiment if item != None: self.item = item else: self.item = experiment self.width = experiment.get(u'width') self.height = experiment.get(u'height') self.spacing = spacing self.margins = type_check.float_list(margins, u'form margins', \ min_len=4, max_len=4) n_cells = len(self.cols)*len(self.rows) self.widgets = [None]*n_cells self.span = [(1,1)]*n_cells self.canvas = canvas(self.experiment, auto_prepare=False, fgcolor= \ self.item.get(u'foreground'), bgcolor=self.item.get( \ u'background')) if theme == u'gray': from themes.gray import gray self.theme_engine = gray(self) else: from themes.plain import plain self.theme_engine = plain(self)
def make_connection(self): """hand shake and filename, returns forceDAQ version """ kbd = keyboard(self._exp) cnv = canvas(self._exp) cnv.text("Prepare force recording <br> press key if ready") cnv.show() kbd.get_key() canvas(self._exp).show() while not self.udp.connect_peer(FORCE_SERVER_IP): cnv = canvas(self._exp) cnv.text("ERROR while connecting to server <br> try again or Q to quit") cnv.show() key = kbd.get_key() if key[0] == u'q': msg = "Experiment quitted by user!" self.udp.send(rc.Command.QUIT) print(msg) self._exp.end() exit() canvas(self._exp).show() self.clock.wait(300) cnv = canvas(self._exp) cnv.text("Connected") cnv.show() self.clock.wait(500) self.udp.send(rc.Command.FILENAME + "{0}_{1}.csv".format(self.experiment_name, self.subject_number)) rtn = self.udp.receive(5) # paused if rtn is None: msg = "Force server not responding" cnv = canvas(self._exp) cnv.text(msg) cnv.show() kbd.get_key() self.udp.send(rc.Command.QUIT) print(msg) self._exp.end() exit() version = rc.get_data(rc.Command.GET_VERSION) cnv = canvas(self._exp) cnv.text("Connected <br> Version " + version) cnv.show() self.clock.wait(1000) return version
def offline_canvas(self): """<DOC> Create an empty canvas Returns: An openexp canvas </DOC>""" return canvas.canvas(self.experiment, self.get("background"), self.get("foreground"))
def prepare_drift_correction_canvas(self): """A hook to prepare the canvas with the drift-correction target.""" if self.var.draw_target == u'yes': self.dc_canvas = canvas(self.experiment) self.dc_canvas.fixdot(self.var.xpos, self.var.ypos, color=self.var.target_color, style=self.var.target_style) else: self.dc_canvas = None
def prepare_drift_correction_canvas(self): """A hook to prepare the canvas with the drift-correction target.""" if self.var.draw_target == 'yes': self.dc_canvas = canvas(self.experiment) self.dc_canvas.fixdot(self.var.xpos, self.var.ypos, color=self.var.target_color, style=self.var.target_style) else: self.dc_canvas = None
def prepare(self): """The preparation phase of the plug-in goes here.""" # Call the parent constructor. item.prepare(self) # Here simply prepare a canvas with a fixatio dot. self.c = canvas(self.experiment) self.c.text('Hello world') debug.msg('Prepared')
def offline_canvas(self): """<DOC> Create an empty canvas Returns: An openexp canvas </DOC>""" return canvas.canvas(self.experiment, self.get("background"), \ self.get("foreground"))
def __init__(self, experiment, cols=2, rows=2, spacing=10, margins=(100, 100, 100, 100), theme='gray', item=None): """<DOC> Constructor Arguments: experiment -- an OpenSesame experiment Keyword arguments: cols -- The number of columns (as int) or a list that specifies the number and relative size of the columns. For example, '[1,2,1]' will create 3 columns where the middle one is twice as large as the outer ones. (default=2) rows -- Analogous to 'cols' (default=2) spacing -- The amount of empty space between the widgets (default=10) margins -- The amount of empty space around the form. This is specified as a list, like so [top-margin, right-margin, bottom-margin, left-margin]. (default=[100, 100, 100, 100]) theme -- the theme for the widgets (default='gray') item -- the item of which the form is part (default=None) </DOC>""" # Normalize the column and row sizes so that they add up to 1 if type(cols) == int: self.cols = [1. / cols] * cols else: self.cols = [float(c) / sum(cols) for c in cols] if type(rows) == int: self.rows = [1. / rows] * rows else: self.rows = [float(r) / sum(rows) for r in rows] self.experiment = experiment self.item = item self.width = experiment.get('width') self.height = experiment.get('height') self.spacing = spacing self.margins = margins n_cells = len(self.cols) * len(self.rows) self.widgets = [None] * n_cells self.span = [(1, 1)] * n_cells self.canvas = canvas(self.experiment, auto_prepare=False) if theme == 'gray': from themes.gray import gray self.theme_engine = gray(self) else: from themes.plain import plain self.theme_engine = plain(self)
def prepare(self): """See item.""" base_response_item.prepare(self) self.canvas = canvas(self.experiment, color=self.var.foreground, background_color=self.var.background, auto_prepare=False) for element in self.elements: if element.is_shown(): element.draw() self.canvas.prepare()
def prepare(self): """The preparation phase of the plug-in goes here.""" # Call the parent constructor. item.prepare(self) # User input self.responses = [self._yes, self._no] self.rows = [2] + [1]*len(self.responses) self.m = mouse(self.experiment) self.c = canvas(self.experiment)
def feedback_start_experiment(self): """ Provides feedback before the experiment """ c = canvas.canvas(self, self.bg_color) c.set_fgcolor(self.fg_color) c.textline("Druk op een toets om te beginnen", 0) c.show() self.wait()
def draw_calibration_canvas(self, x, y): """A hook to prepare the canvas with the clibration target.""" if self.get(u'eyelink_calbeep'): self.beep.play() dc_canvas = canvas(self.experiment) if u'style' in inspect.getargspec(dc_canvas.fixdot).args: dc_canvas.fixdot(x, y, style=u'large-open') else: dc_canvas.fixdot(x, y) dc_canvas.show()
def offline_canvas(self, auto_prepare=True): """ desc: Deprecated function. """ warnings.warn(u'self.offline_canvas() is deprecated. ' 'Use canvas() instead.', DeprecationWarning) return canvas.canvas(self.experiment, auto_prepare=auto_prepare, background_color=self.var.background, color=self.var.foreground)
def prepare(self): """See item.""" base_response_item.prepare(self) self.canvas = canvas(self.experiment, color=self.var.foreground, background_color=self.var.background) with self.canvas: for element in self._elements(): temp_name = element.draw() if element.element_name is not None: self.canvas.rename_element(temp_name, element.element_name)
def run(self): """Execute the consent form""" while True: super(form_consent, self).run() if self.get("checkbox_status") == self.get("checkbox_text") and self.get("accept_status") == "yes": break c = canvas(self.experiment) c.text(self.get("decline_message")) c.show() self.sleep(5000)
def run(self): """Execute the consent form""" while True: super(form_consent, self).run() if self.get('checkbox_status') == self.get('checkbox_text') and \ self.get('accept_status') == 'yes': break c = canvas(self.experiment) c.text(self.get('decline_message')) c.show() self.sleep(5000)
def feedback_end_experiment(self): """ Provides feedback after the experiment """ c = canvas.canvas(self, self.bg_color) c.set_fgcolor(self.fg_color) c.textline("Het experiment is afgelopen", -1) c.textline("Bedankt voor het meedoen!", 0) c.show() self.wait()
def prepare(self): """ Prepare the item. In this case this means drawing a fixation dot to an offline canvas. """ # create offline canvas self.canvas = canvas(self.experiment, auto_prepare=False) self.canvas.set_bgcolor(self.get("bgc")) self.canvas.clear() # draw the stimulus self.sx = self.get("width")/2 self.sy = self.get("height")/2 self.r = self.get("stims")/2 self.canvas.circle(self.sx,self.sy,self.r,fill=True,color=self.get("fgc")) # create keyboard object if self.allow_keyboard == 'yes': kl = self.get("kl").split(';') self.kb = keyboard(self.experiment, keylist=kl, timeout=None) # calculate vibration time (ms) self.experiment.set("T", (1 / float(self.get("freq"))) * 1000) # determine functions for stepsize if self.get("direct") == 'horizontal': if self.get("mtype") == 'sinusoid': self.fx = self.sinusoid elif self.get("mtype") == 'linear': self.fx = self.linear else: self.fx = self.no_change print("Error in smooth_pursuit.prepare: unknown movement type!") self.fy = self.no_change elif self.get("direct") == 'vertical': if self.mtype == 'sinusoid': self.fy = self.sinusoid elif self.mtype == 'linear': self.fy = self.linear else: self.fy = self.no_change print("Error in smooth_pursuit.prepare: unknown movement type!") self.fx = self.no_change # Pass the word on to the parent item.item.prepare(self) # Report success return True
def hold_check(self, holding_time=3000, left_pos=-200, right_pos=200, radius=50, col_fine='gray', col_too_low='green', col_too_strong='red'): kbd = keyboard(self._exp) blank = canvas(self._exp) blank.show() self.udp.send("hold:test") self.clock.reset_stopwatch() prev_lv = None while True: self.udp.clear_receive_buffer() lv = [rc.get_data(rc.Command.GET_THRESHOLD_LEVEL), rc.get_data(rc.Command.GET_THRESHOLD_LEVEL2)] if prev_lv!=lv: # level has changes self.clock.reset_stopwatch() prev_lv = lv cnv = canvas(self._exp) for i, pos in enumerate([left_pos, right_pos]): if lv[i] == WEAK: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_too_low) elif lv[i] == STRONG: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_too_strong) elif lv[i] == FINE: cnv.circle(x=pos, y=0, r=radius, fill=True, color=col_fine) cnv.show() key, _ = kbd.get_key(timeout=0) if (lv == [FINE, FINE] and self.clock.stopwatch_time > holding_time) or\ (key is not None): break blank.show()
def feedback_end_practice(self): """ Provides feedback after the practice phae """ c = canvas.canvas(self, self.bg_color) c.set_fgcolor(self.fg_color) c.textline("Einde van de oefenphase", -2) c.textline("Het echte experiment begint nu", -1) c.textline("Druk op een toets om verder te gaan", 1) c.show() self.wait()
def run(self): """Run the item""" # Initialize the item self.set_item_onset() self.sri = self.time() self.experiment.set("slider_percent", None) my_canvas = canvas(self.experiment) my_mouse = mouse(self.experiment, timeout=20) # Create the app while True: # Slider dimensions slider_w = self.slider_width slider_h = self.slider_heigth slider_x = self.get("width")/2-slider_w/2 slider_y = self.get("height")/2-slider_h/2 # Determine the slider fill based on the mouse position pos, time = my_mouse.get_pos() x, y = pos slider_fill = min(slider_w, max(0, x-slider_x)) my_canvas.set_bgcolor(self.get("bg_colour")) my_canvas.clear() # Draw the text my_canvas.text(self.get("question"), y=slider_y-100, color=self.get("txt_colour")) my_canvas.text(self.get("accept_text"), y=slider_y+slider_h+50, color=self.get("txt_colour")) # Draw the slider frame my_canvas.set_fgcolor(self.get("fg_colour")) my_canvas.rect(slider_x-1, slider_y-1, slider_w+2, slider_h+2) # Draw the slider fill my_canvas.rect(slider_x, slider_y, slider_fill, slider_h, fill=True, color=self.get("sf_colour")) # Draw the canvas my_canvas.show() # Poll the mouse for buttonclicks button, position, timestamp = my_mouse.get_click(timeout = 20) if button != None: break slider_percent = 100.0*slider_fill/slider_w # Set the response self.experiment.set("response", slider_percent) # Return success return True
def wait_no_button_pressed(self, feedback_stimulus_text=None, polling_intervall=500): """level detection needs to be switch on display feedback_stimulus (optional) if one button pressed """ if rc.get_data(rc.Command.GET_THRESHOLD_LEVEL) > 0 or \ rc.get_data(rc.Command.GET_THRESHOLD_LEVEL) > 0: if feedback_stimulus_text is not None: cnv = canvas(self._exp) cnv.text(feedback_stimulus_text) cnv.show() kbd = keyboard(self._exp) while rc.get_data(rc.Command.GET_THRESHOLD_LEVEL) > 0 or \ rc.get_data(rc.Command.GET_THRESHOLD_LEVEL) > 0: kbd.get_key(timeout=polling_intervall)
def prepare_drift_correction_canvas(self): """A hook to prepare the canvas with the drift-correction target.""" if self.get(u'draw_target') == u'yes': self.dc_canvas = canvas(self.experiment) x = self.get(u'xpos') + self.dc_canvas.xcenter() y = self.get(u'ypos') + self.dc_canvas.ycenter() if u'style' in inspect.getargspec(self.dc_canvas.fixdot).args: self.dc_canvas.fixdot(x, y, color=self.get(u'target_color'), \ style=self.get(u'target_style')) else: self.dc_canvas.fixdot(x, y, color=self.get(u'target_color')) else: self.dc_canvas = None
def feedback_end_block(self, practice, current_block, nr_of_blocks, avg_rt, avg_correct): """ Provides feedback after every block """ c = canvas.canvas(self, self.bg_color) c.set_fgcolor(self.fg_color) c.textline("Einde van blok %d van %d" % (current_block, nr_of_blocks), -2) c.textline("Reactiesnelheid: %dms" % avg_rt, -1) c.textline("Percentage correct: %.0f%%" % avg_correct, 0) c.textline("Druk op een toets om verder te gaan", 2) c.show() self.wait()
def run(self): """Executes the consent form.""" while True: # In this case we cannot call super(form_consent, self), because # modules may have been reloaded. The exact nature of the bug is # unclear, but passing the __class__ property resolves it. See also # <http://thingspython.wordpress.com/2010/09/27/another-super-wrinkle-raising-typeerror/> self.super_form_consent.run() if self.get(u'checkbox_status') == self.get(u'checkbox_text') and \ self.get(u'accept_status') == u'yes': break c = canvas(self.experiment) c.text(self.get(u'decline_message')) c.show() self.sleep(5000)