def main():

    num_blocks    = 16    # num_blocks * wordsPerBlock should not exceed 512
    wordsPerBlock = 16     # words displayed (both latin and hebrew) per block
    word_lengths = [4, 5, 6]   # character lengths to select from word_list.txt


    #ensure that video mode is at the maxium FPS
    if sys.platform.startswith("linux"):
        from subprocess import call
        call(["xrandr","-r","144"])

    pygame.init()
    pygame.mouse.set_visible(False)

    #get filepath/name for words displayed text file
    if not os.path.isdir("data"):
        os.mkdir("data")
    num = 0
    while True:
        fn = "data/words_displayed_%02d.txt" % num
        if not os.path.isfile(fn):
            break
        num += 1

    #instantiate some objects
    if not SUPRESS_TXT_OUTPUT:
        words_displayed = open(fn, "w")
    FC = FixationCross(color = "black")
    restScreen = Screen(color = "white", fixation_cross = FC)
    blankScreen = Screen(color = "white")
    text = TextDisplay(font_size = 288,
                             font_type = "FreeMono.ttf",
                             screen_bgColor = "white",
                             )

    # get and randomize a list of latin words from the word_list.txt file
    word_list = []
    with neurodot_present.resources.load_wordlist() as list_file:
        for line in list_file.readlines():
            if len(line.rstrip()) in word_lengths:
                word_list.append(line.rstrip().upper())
    random.shuffle(word_list)

    # get list of dictionaries for latin/hebrew words and randomize
    stim_list = []
    for word in word_list[0:num_blocks*wordsPerBlock/2 + 1]:
        vsync_value = len(word) - 3 #words are 4,5,6 letters long
        latin = {'word': word, 'vsync_value': vsync_value}
        hebrew = {'word': code_hebrew(word), 'vsync_value': vsync_value + 3}
        stim_list.append(latin)
        stim_list.append(hebrew)
    random.shuffle(stim_list)

    try:

        #start sequence
        run_start_sequence()
        restScreen.run(duration = 2, vsync_value = 0)

        block = 0
        while block < num_blocks:
            for stim in stim_list[block*wordsPerBlock : block*wordsPerBlock + wordsPerBlock]:

                if not SUPRESS_TXT_OUTPUT:
                    words_displayed.write(stim['word'].encode("utf8") + "\n")

                text.run(text_content = stim['word'],
                         duration = STIMULUS_DURATION,
                         vsync_value = stim['vsync_value']
                         )
                #print text.textSurface.get_width()

                # display blank screen
                blankScreen.run(duration = STIMULUS_DURATION, vsync_value = 0)

            if block < num_blocks-1:

                # add an empty line to text file to signify between trials
                if not SUPRESS_TXT_OUTPUT:
                    words_displayed.write("\n")

                #rest period
                bell()
                restScreen.run(duration = 3, vsync_value = 0)
                bell()
                restScreen.run(duration = random.uniform(1,3), vsync_value = 0)

            block += 1

    except UserEscape as exc:
        print exc
    except:
        print "Unexpected error:"
        raise
    finally:
        if not SUPRESS_TXT_OUTPUT:
            words_displayed.close()

        # stop sequence
        run_stop_sequence()

    pygame.quit()
    sys.exit()
    FLASH_DURATION = 8       #seconds
    PAUSE_DURATION_RANGE = (2.0,5.0)

    FC = FixationCross()

    #CBFs

    try:
        #start sequence
        run_start_sequence()
        #trials
        for b in range(BLOCKS):
            stims = REPITITIONS*zip(FLASH_RATES, VSYNC_VALUES)
            random.shuffle(stims)
            for flash_rate, vsync_value in stims:
                CBF = CheckerBoardFlasher(flash_rate=flash_rate)
                CBF.setup_checkerboard(nrows = CHECKERBOARD_NROWS, show_fixation_dot = True)
                CBF.run(duration = FLASH_DURATION, vsync_value = vsync_value)
                SCR = Screen(color = "black", fixation_cross = FC)
                pause_duration = random.uniform(*PAUSE_DURATION_RANGE)
                SCR.run(duration = pause_duration, vsync_value = 0)
    except UserEscape as exc:
        print exc
    finally:
        #stop sequence
        run_stop_sequence()
    #exit
    print "Exiting the presentation"
    pygame.quit()
    sys.exit()
pygame.init()

TASK_DURATION = 30  #seconds

FC = FixationCross()
try:
    #start sequence
    run_start_sequence()
    #setup task
    CBF = CheckerBoardFlasher(flash_rate=0) #no flashing
    CBF.setup_checkerboard(64)
    black_SCR = Screen(color = "black",fixation_cross = FC)
    #run sequence
    CBF.run(duration = TASK_DURATION, vsync_value = 1)
    black_SCR.run(duration = 1, vsync_value = 0)
    bell()
    black_SCR.run(duration = 5, vsync_value = 0)
    black_SCR.run(duration = TASK_DURATION, vsync_value = 2)
    black_SCR.run(duration = 1, vsync_value = 0)
    bell()
except UserEscape:
    print "User stopped the sequence"
except Exception, err:
    raise err
finally:
    #stop sequence
    run_stop_sequence()

pygame.quit()
sys.exit()
            base_vsync_vals = zip(*stimAttrs)[2]

            for r in range(0, REPITITIONS):
                # choose left or right
                if random.choice([True, False]):
                    SCR = SCR_left
                    aSCR = aSCR_left
                    vsync_vals = base_vsync_vals
                    text_content = "L"
                else:
                    SCR = SCR_right
                    aSCR = aSCR_right
                    vsync_vals = [v + len(base_vsync_vals) for v in base_vsync_vals]  # modify vsync values to show we are looking right
                    text_content = "R"

                SCR_rest.run(duration = 1, vsync_value = 0)

                #text.run(text_content = text_content, duration = 0.5)
                #pause_duration = random.uniform(*PAUSE_DURATION_RANGE)

                t0 = time.time()
                #aSCR_both.run(duration = 3)
                aSCR.run(duration = 3)
                t1 = time.time()
                print "Animation duration:", t1 - t0

                CBF.run(duration = FLASH_DURATION, flash_rate_left = FRs_left[r], flash_rate_right = FRs_right[r], vsync_value = vsync_vals[r])
                print "Stimulus duration:", time.time() - t1

            BLOCKS -= 1
            if not BLOCKS == 0: