Пример #1
0
    def __init__(self, note, settings):

        size_box = settings["size_box"]
        pos_y = settings["position"]
        text_size = settings["text_size"]
        self.text = "Type response: " + note.Feedback_text + "\nRT: " + note.str_rt + "\nMean: " + note.str_mean + "\nMisses: " + str(note.misses)
        self.TextBox = stimuli.TextBox(self.text, size_box, pos_y, text_size=text_size)
    def prepare_trial(self, block):
        trial = design.Trial()
        # TODO: practice = e['Practice'] if 'Practice' in e else False
        labels = self.labels[block.get_factor('target_titles')][:block.get_factor('num_targets')]

        positions = TrailMaking.make_random_positions(
            self.exp.screen.window_size,
            self.radius,
            block.get_factor('num_targets'),
            self.exp.config.getfloat('DESIGN', 'min_distance_of_targets') * self.radius,
            self.exp.config.getfloat('DESIGN', 'attempts_before_reducing_min_distance'))

        for lab, pos in zip(labels, positions):
            stim = stimuli.Circle(radius=self.radius, position=pos,
                                  colour=self.colour_target,
                                  anti_aliasing=self.antialiasing)
            label = stimuli.TextBox(lab,
                                    (self.radius*2, self.radius*2),
                                    text_size=int(self.stimulus_relative_text_size * self.radius),
                                    position=[pos[0], pos[1] -
                                              self.stimulus_text_correction_y * self.radius],
                                    text_justification=1,
                                    text_colour=self.colour_target_label,
                                    text_font=self.target_font)
            trial.add_stimulus(stim)
            trial.add_stimulus(label)
        return(trial)
Пример #3
0
 def drawConnector(text, nback, width):
     vtx = stimuli.Shape(line_width=2)
     halfwidth = int(width / 2 * nback)
     height = int(-width / 3)
     vtx.add_vertices([(-halfwidth * 1.4, height),
                       (-halfwidth * 0.6, -height),
                       (halfwidth * 0.6, height)])
     vtx.move((-width / 2 * nback, 0))
     txt = stimuli.TextBox(text, size=(width, width), position=(0, height))
     return (vtx, txt)
Пример #4
0
    def __init__(self, screen_size,  pos_y, clef_name="g", design="bw", text=None):

        self.background_colour = constants.C_WHITE
        self.foreground_colour = constants.C_BLACK
        self.clef_name = clef_name

        # Position of field
        self.pos_x = 0
        self.pos_y = pos_y[self.clef_name]

        self.field_position = [self.pos_x, self.pos_y]

        # Size of field is 1 / factor of whole screen
        factor = 3.5
        field_x = screen_size[0] / 2
        field_y = screen_size[1] / factor
        self.field_size = [field_x, field_y]

        self.Field = stimuli.Canvas(size=self.field_size, position=self.field_position, colour=self.background_colour)

        # Text field for debugging
        if text is not None:
            self.text = text
            text = stimuli.TextBox(self.text, [100,100])
            text.plot(self.Field)

        # Add lines
        self.distance = screen_size[0] / 60
        line_radius = screen_size[0]/10

        for i in range(-2, 3, 1):
            item = {
                'start_point': [-line_radius, self.pos_x - (i * self.distance)],
                'end_point': [line_radius, self.pos_x - (i * self.distance)],
                'line_width': 2,
                'colour': self.foreground_colour
                }
            line = stimuli.Line(item['start_point'], item['end_point'], item['line_width'], colour=item['colour'])
            line.plot(self.Field)

        # Add clef
        clef_pos_x = line_radius * 1.2
        clef = stimuli.Picture('Stimuli/clef_' + design + '_' + clef_name + '.jpg', position=[-clef_pos_x, 0])
        clef.scale(3.9 * screen_size[0] / 100000)
        clef.plot(self.Field)
elif not (splash_screen is None):
    if op.splitext(splash_screen)[1] == '.csv':
        instructions = csv.reader(io.open(splash_screen, 'r',
                                          encoding='utf-8'),
                                  delimiter='\t')
        for instruction_line in instructions:
            instruction_duration, stype, instruction_line = instruction_line[
                0], instruction_line[1], instruction_line[2]
            if stype == 'box':
                instruction_line = instruction_line.replace('\\n', '\n')
                width_screen, height_screen = exp.screen.size
                y = (-1 * exp.screen.center_y) / 2
                instruction = stimuli.TextBox(
                    instruction_line,
                    position=(0, -230),
                    size=(int(width_screen), int(height_screen)),
                    text_font=TEXT_FONT,
                    text_size=TEXT_SIZE,
                    text_colour=TEXT_COLOR,
                    background_colour=BACKGROUND_COLOR)
                instruction.preload()
                instruction.present()
                #exp.clock.wait(WORD_DURATION*10)
                exp.clock.wait(int(instruction_duration))
                #fs.present()
                #exp.clock.wait(WORD_ISI*6)
            elif stype == 'text':
                #instruction_line = instruction_line.replace('\BL', '\n')
                instruction = stimuli.TextLine(
                    instruction_line,
                    text_font=TEXT_FONT,
                    text_size=TEXT_SIZE,
Пример #6
0
def main_loop(exp, recorder, remote_control=False):
    """udp command:
            "start", "pause", "stop"
            "thresholds = [x,...]" : start level detection for Fz parameter and set threshold
            "thresholds stop" : stop level detection
    """

    indicator_grid = 70  # distance between indicator center
    plotter_width = 900
    plotter_position = (0, -30)

    s = GUIStatus(
        screen_refresh_interval_indicator=config.
        screen_refresh_interval_indicator,
        screen_refresh_interval_plotter=config.
        gui_screen_refresh_interval_plotter,
        recorder=recorder,
        remote_control=remote_control,
        level_detection_parameter=ForceData.forces_names.index(
            config.level_detection_parameter),  # only one dimension
        screen_size=exp.screen.size,
        data_min_max=config.data_min_max,
        plotter_pixel_min_max=config.plotter_pixel_min_max,
        indicator_pixel_min_max=config.indicator_pixel_min_max,
        plot_axis=config.plot_axis)

    # plotter
    plotter_thread = None
    exp.keyboard.clear()

    while not s.quit_recording:  ######## process loop
        if s.pause_recording:
            sleep(0.01)

        ################################ process keyboard
        s.process_key(exp.keyboard.check(check_for_control_keys=False))

        ##############################  process udp
        udp = recorder.process_and_write_udp_events()
        while len(udp) > 0:
            s.process_udp_event(udp.pop(0))

        ########################### process new samples
        for x in s.check_new_samples():
            s.update_history(sensor=x)

            if s.thresholds is not None:
                # level change detection
                level_change, tmp = s.thresholds.get_level_change(
                    s.history[x].moving_average[s.level_detection_parameter],
                    channel=x)
                if level_change:
                    if x == 1:
                        recorder.udp.send_queue.put(RcCmd.CHANGED_LEVEL2 +
                                                    dumps(tmp))
                    else:
                        recorder.udp.send_queue.put(RcCmd.CHANGED_LEVEL +
                                                    dumps(tmp))

                # minmax detection
                tmp = s.thresholds.get_response_minmax(
                    s.history[x].moving_average[s.level_detection_parameter],
                    channel=x)
                if tmp is not None:
                    if x == 1:
                        recorder.udp.send_queue.put(RcCmd.RESPONSE_MINMAX2 +
                                                    dumps(tmp))
                    else:
                        recorder.udp.send_queue.put(RcCmd.RESPONSE_MINMAX +
                                                    dumps(tmp))

        ######################## show pause or recording screen
        if s.check_recording_status_change():
            if s.pause_recording:
                s.background.stimulus("writing data...").present()
                recorder.pause_recording()
                s.background.stimulus("Paused ('b' for baseline)").present()
                if remote_control:
                    recorder.udp.send_queue.put(RcCmd.FEEDBACK_PAUSED)
            else:
                recorder.start_recording()
                s.set_start_recording_time()
                s.background.stimulus().present()
                if remote_control:
                    recorder.udp.send_queue.put(RcCmd.FEEDBACK_STARTED)

        ###########################
        ########################### plotting
        ###########################

        if s.check_refresh_required():  #do not give priority to visual output
            update_rects = []

            if s.check_thresholds_changed():
                draw_plotter_thread_thresholds(plotter_thread, s.thresholds,
                                               s.scaling_plotter)

            if s.plot_indicator:
                ############################################  plot_indicator
                if plotter_thread is not None:
                    plotter_thread.stop()
                    plotter_thread = None

                ## indicator
                force_data_array = map(
                    lambda x: s.sensor_processes[x[0]].get_force(x[1]),
                    s.plot_data_indicator)

                for cnt in range(6):
                    x_pos = (-3 * indicator_grid) + (
                        cnt * indicator_grid) + 0.5 * indicator_grid

                    if cnt == s.level_detection_parameter:
                        thr = s.thresholds
                    else:
                        thr = None
                    li = level_indicator(value=force_data_array[cnt],
                                         text=s.plot_data_indicator_names[cnt],
                                         scaling=s.scaling_indicator,
                                         width=50,
                                         position=(x_pos, 0),
                                         thresholds=thr)
                    li.present(update=False, clear=False)
                    update_rects.append(get_pygame_rect(li, exp.screen.size))

                #line
                zero = s.scaling_indicator.data2pixel(
                    s.scaling_indicator.trim(0))
                rect = stimuli.Line(start_point=(-200, zero),
                                    end_point=(200, zero),
                                    line_width=1,
                                    colour=misc.constants.C_YELLOW)
                rect.present(update=False, clear=False)
                update_rects.append(get_pygame_rect(rect, exp.screen.size))

                # axis labels
                pos = (-220, -145)
                stimuli.Canvas(position=pos,
                               size=(30, 20),
                               colour=misc.constants.C_BLACK).present(
                                   update=False, clear=False)
                txt = stimuli.TextLine(position=pos,
                                       text=str(s.scaling_indicator.min),
                                       text_size=15,
                                       text_colour=misc.constants.C_YELLOW)
                txt.present(update=False, clear=False)
                update_rects.append(get_pygame_rect(txt, exp.screen.size))
                pos = (-220, 145)
                stimuli.Canvas(position=pos,
                               size=(30, 20),
                               colour=misc.constants.C_BLACK).present(
                                   update=False, clear=False)
                txt = stimuli.TextLine(position=pos,
                                       text=str(s.scaling_indicator.max),
                                       text_size=15,
                                       text_colour=misc.constants.C_YELLOW)
                txt.present(update=False, clear=False)
                update_rects.append(get_pygame_rect(txt, exp.screen.size))
                # end indicator

                stimuli.Canvas(position=(-250, 200),
                               size=(200, 50),
                               colour=misc.constants.C_BLACK).present(
                                   update=False, clear=False)
                txt = stimuli.TextBox(
                    text=str(s.sensor_info_str),
                    #background_colour=(30,30,30),
                    size=(200, 50),
                    text_size=15,
                    position=(-250, 200),
                    text_colour=misc.constants.C_YELLOW,
                    text_justification=0)
                txt.present(update=False, clear=False)
                update_rects.append(get_pygame_rect(txt, exp.screen.size))
            else:
                ############################################  plotter
                if plotter_thread is None:
                    plotter_thread = PlotterThread(
                        n_data_rows=len(s.plot_data_plotter),
                        data_row_colours=colours[:len(s.plot_data_plotter)],
                        y_range=[
                            s.scaling_plotter.pixel_min,
                            s.scaling_plotter.pixel_max
                        ],
                        width=plotter_width,
                        position=plotter_position,
                        background_colour=[10, 10, 10],
                        axis_colour=misc.constants.C_YELLOW)
                    plotter_thread.start()

                    if s.plot_axis:
                        plotter_thread.set_horizontal_lines(
                            y_values=[s.scaling_plotter.data2pixel(0)])

                    if s.thresholds is not None:
                        plotter_thread.set_horizontal_lines(
                            y_values=s.scaling_plotter.data2pixel(
                                np.array(s.thresholds.thresholds)))

                if s.clear_screen:
                    plotter_thread.clear_area()
                    s.clear_screen = False

                if s.plot_filtered:
                    tmp = np.array(map(
                        lambda x: s.history[x[0]].moving_average[x[1]],
                        s.plot_data_plotter),
                                   dtype=float)
                else:
                    tmp = np.array(map(
                        lambda x: s.sensor_processes[x[0]].get_force(x[1]),
                        s.plot_data_plotter),
                                   dtype=float)

                if s.thresholds is not None:
                    point_marker = s.thresholds.is_detecting_anything()
                else:
                    point_marker = False

                plotter_thread.add_values(
                    values=s.scaling_plotter.data2pixel(tmp),
                    set_marker=s.set_marker,
                    set_point_marker=point_marker)
                s.set_marker = False

                update_rects.append(
                    plotter_thread.get_plotter_rect(exp.screen.size))

                # axis labels
                axis_labels = (int(s.scaling_plotter.min),
                               int(s.scaling_plotter.max), 0)
                xpos = plotter_position[0] - (plotter_width / 2) - 20
                for cnt, ypos in enumerate(
                    (plotter_position[1] + s.scaling_plotter.pixel_min + 10,
                     plotter_position[1] + s.scaling_plotter.pixel_max - 10,
                     plotter_position[1] + s.scaling_plotter.data2pixel(0))):
                    stimuli.Canvas(position=(xpos, ypos),
                                   size=(50, 30),
                                   colour=misc.constants.C_BLACK).present(
                                       update=False, clear=False)
                    txt = stimuli.TextLine(position=(xpos, ypos),
                                           text=str(axis_labels[cnt]),
                                           text_size=15,
                                           text_colour=misc.constants.C_YELLOW)
                    txt.present(update=False, clear=False)
                    update_rects.append(get_pygame_rect(txt, exp.screen.size))

            # counter
            pos = (-230, 250)
            stimuli.Canvas(position=pos,
                           size=(400, 50),
                           colour=misc.constants.C_BLACK).present(update=False,
                                                                  clear=False)

            txt = stimuli.TextBox(
                position=pos,
                size=(400, 50),
                #background_colour=(30,30,30),
                text_size=15,
                text="n samples (total): {0}\nn samples: {1} ({2} sec.)".
                format(
                    str(map(SensorProcess.get_sample_cnt,
                            s.sensor_processes))[1:-1],
                    str(map(SensorProcess.get_buffer_size,
                            s.sensor_processes))[1:-1],
                    s.recording_duration_in_sec),
                text_colour=misc.constants.C_YELLOW,
                text_justification=0)
            txt.present(update=False, clear=False)
            update_rects.append(get_pygame_rect(txt, exp.screen.size))

            # Infos
            pos = (200, 250)
            tmp = stimuli.Canvas(position=pos,
                                 size=(400, 50),
                                 colour=misc.constants.C_BLACK)
            tmp.present(update=False, clear=False)
            update_rects.append(get_pygame_rect(tmp, exp.screen.size))
            if s.thresholds is not None:
                if s.n_sensors > 1:
                    tmp = [
                        s.thresholds.get_level(
                            s.level_detection_parameter_average(0)),
                        s.thresholds.get_level(
                            s.level_detection_parameter_average(1))
                    ]
                else:
                    tmp = s.thresholds.get_level(
                        s.level_detection_parameter_average(0))
                txt = stimuli.TextBox(position=pos,
                                      size=(400, 50),
                                      text_size=15,
                                      text="T: {0} L: {1}".format(
                                          s.thresholds, tmp),
                                      text_colour=misc.constants.C_YELLOW,
                                      text_justification=0)

                txt.present(update=False, clear=False)

            pos = (400, 250)
            tmp = stimuli.Canvas(position=pos,
                                 size=(400, 50),
                                 colour=misc.constants.C_BLACK)
            tmp.present(update=False, clear=False)
            update_rects.append(get_pygame_rect(tmp, exp.screen.size))
            if s.plot_filtered:
                txt = stimuli.TextBox(position=pos,
                                      size=(400, 50),
                                      text_size=15,
                                      text="Filtered data!",
                                      text_colour=misc.constants.C_YELLOW,
                                      text_justification=0)
                txt.present(update=False, clear=False)

            # last_udp input
            if s.last_udp_data is not None:
                pos = (420, 250)
                stimuli.Canvas(position=pos,
                               size=(200, 30),
                               colour=misc.constants.C_BLACK).present(
                                   update=False, clear=False)
                txt = stimuli.TextBox(
                    position=pos,
                    size=(200, 30),
                    #background_colour=(30,30,30),
                    text_size=15,
                    text="UDP:" + str(s.last_udp_data),
                    text_colour=misc.constants.C_YELLOW,
                    text_justification=0)
                txt.present(update=False, clear=False)
                update_rects.append(get_pygame_rect(txt, exp.screen.size))

            pygame.display.update(update_rects)
            # end plotting screen

        ##### end main  loop

    s.background.stimulus("Quitting").present()
    if plotter_thread is not None:
        plotter_thread.stop()
    recorder.pause_recording(s.background)
Пример #7
0
        stimulus.plot(backBox)

        trial.add_stimulus(backBox)
        trial.preload_stimuli()

        block.add_trial(trial)

    experiment.add_block(block)

# preparing general stimuli

blank = stimuli.BlankScreen()
blank.preload()

# preparing instructions, feedback, subject code entry
subCodeInstr = stimuli.TextBox(text=subCodeText, size=(800, 400))
subCodeInput = io.TextInput(length=6, background_stimulus=subCodeInstr,
                            position=(0, -100))

feedbackCorrect = stimuli.TextLine(text='Točno!',
                                   text_colour=misc.constants.C_GREEN,
                                   text_bold=True)
feedbackCorrect.preload()

feedbackIncorrect = stimuli.TextLine(text='Pogrešno!',
                                     text_colour=misc.constants.C_RED,
                                     text_bold=True)
feedbackIncorrect.preload()

subCode = ''
Пример #8
0
def showInstructions(exp, nback):
    size = (WIDTH, HEIGHT) if not ROTATE_SCREEN else (HEIGHT, WIDTH)
    tut = stimuli.TextScreen(
        INSTRUCTIONS['caption_tutorial'][LANGUAGE].format(nback=nback),
        INSTRUCTIONS['tutorial_text'][LANGUAGE].format(nback=nback),
        size=size,
        position=(size[0] / 3 if ROTATE_SCREEN else 0,
                  -size[1] / 3 if not ROTATE_SCREEN else 0))
    tut.rotate(90) if ROTATE_SCREEN else tut
    tut.present()
    exp.mouse.wait_press()

    s = int(SIZE * 0.1)
    canvas = stimuli.Rectangle((SIZE, SIZE), colour=misc.constants.C_BLACK)
    littlegrid = nback.prepare_grid_stimulus(line_width=15)
    bx = exp.config.getint('DESIGN', 'num_boxes')**(0.5)
    sz = int(canvas_size / bx)
    ctr = int(canvas_size / 2)

    def drawConnector(text, nback, width):
        vtx = stimuli.Shape(line_width=2)
        halfwidth = int(width / 2 * nback)
        height = int(-width / 3)
        vtx.add_vertices([(-halfwidth * 1.4, height),
                          (-halfwidth * 0.6, -height),
                          (halfwidth * 0.6, height)])
        vtx.move((-width / 2 * nback, 0))
        txt = stimuli.TextBox(text, size=(width, width), position=(0, height))
        return (vtx, txt)

    ll = [[5, 0, 5, 6, 6, 5],
          ['magenta', 'green', 'green', 'cyan', 'green', 'cyan']]
    for l in ll:
        pos = not isinstance(l[0], basestring)
        for i, p in enumerate(l):
            if pos:
                g = littlegrid.copy()
                g.decompress()
                stimuli.Rectangle(
                    (sz, sz),
                    position=((p % bx + 0.5) * sz - ctr,
                              (p // bx + 0.5) * sz - ctr)).plot(g)

                g.scale(0.1)
                g.move((int((i - 2.5) * canvas_size / 6), s * 2))
                g.plot(canvas)
            else:
                c = stimuli.Rectangle((int(s / 3), int(s / 3)),
                                      colour=COLOURS[p])
                c.move((int((i - 2.5) * canvas_size / 6), -2 * s))
                c.plot(canvas)
            if i >= nback and l[i - nback] == p:
                vtx, txt = drawConnector(
                    INSTRUCTIONS['tutorial_match'][LANGUAGE].format(
                        nback=nback), nback, canvas_size / 6)
                movey = int(1.0 * s)
                if not pos:
                    movey -= int(4 * s)
                vtx.move((int((i - 2.5) * canvas_size / 6), movey))
                txt.move((int(
                    (i - 2.5) * canvas_size / 6), movey - int(0.5 * s)))
                vtx.plot(canvas)
                txt.plot(canvas)
        if pos:
            txt = stimuli.TextBox(
                INSTRUCTIONS['tutorial_illustration_colour'][LANGUAGE].format(
                    nback=nback),
                size=(canvas_size, 4 * s),
                position=(0, 2 * s))
        else:
            txt = stimuli.TextLine(
                INSTRUCTIONS['tutorial_illustration_position']
                [LANGUAGE].format(nback=nback),
                position=(0, int(-1 * s)))
        txt.plot(canvas)
    canvas.rotate(90) if ROTATE_SCREEN else canvas
    canvas.present()
    exp.mouse.wait_press()
Пример #9
0
    def __init__(self, note, settings):
        size_box = settings["size_box"]
        pos_y = settings["position"]
        text_size = settings["text_size"]

        self.CorrectNote = stimuli.TextBox(note.key, size_box, pos_y, text_size=text_size)
Пример #10
0
def reording_settings_info_screen():

    stimuli.TextBox()