text="All done!", wrapWidth=15, units='deg', height=1, color='White', pos=[0, 0], alignHoriz='center', alignVert='bottom') msg.draw() win.flip() wait(.5) win.close() quit() if keys in ['x' ]: #this allows to screenshot the stimuli. win.getMovieFrame() win.saveMovieFrames('SampleStim' + str(trial) + '.jpg') (humanResp, humanRT) = displayRecordResponse(a[condition], trialStart, autoResp, StimLength) #Feedback (trialACC, feedback) = decideFeedback(a[condition], humanResp, signal) feedback.draw() win.flip() wait(.5) RTor = min(humanRT, autoRT) RTand = max(humanRT, autoRT) message = '{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n'\
class Test_textbox(_TestColorMixin, _TestUnitsMixin): def setup(self): self.win = Window((128, 128), pos=(50, 50), monitor="testMonitor", allowGUI=False, autoLog=False) self.error = _BaseErrorHandler() self.textbox = TextBox2( self.win, "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question.", "Noto Sans", alignment="top left", lineSpacing=1, padding=0.05, pos=(0, 0), size=(1, 1), units='height', letterHeight=0.1, colorSpace="rgb") self.obj = self.textbox # point to textbox for mixin tests # Pixel which is the border color self.borderPoint = (0, 0) self.borderUsed = True # Pixel which is the fill color self.fillPoint = (2, 2) self.fillUsed = True # Textbox foreground is too unreliable due to fonts for pixel analysis self.foreUsed = False def teardown(self): self.win.close() def test_glyph_rendering(self): # Prepare textbox self.textbox.colorSpace = 'rgb' self.textbox.color = 'white' self.textbox.fillColor = (0, 0, 0) self.textbox.borderColor = None self.textbox.opacity = 1 # Add all Noto Sans fonts to cover widest possible base of handles characters for font in [ "Noto Sans", "Noto Sans HK", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", "Noto Sans TC", "Niramit", "Indie Flower" ]: self.textbox.fontMGR.addGoogleFont(font) # Some exemplar text to test basic TextBox rendering exemplars = [ # An English pangram { "text": "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question.", "font": "Noto Sans", "size": 16, "screenshot": "exemplar_1.png" }, # The same pangram in IPA { "text": "ə saɪkəʊpaɪ zɛlət nəʊz ə smidge ɒv wx, bʌt ˈʤɑːvəskrɪpt ɪz ðə ˈkwɛsʧən", "font": "Noto Sans", "size": 16, "screenshot": "exemplar_2.png" }, # The same pangram in Hangul { "text": "아 프시초피 제알롣 크노W스 아 s믿게 오f wx, 붇 자v앗c립t 잇 테 q왯디온", "font": "Noto Sans KR", "size": 16, "screenshot": "exemplar_3.png" }, # A noticeably non-standard font { "text": "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question.", "font": "Indie Flower", "size": 16, "screenshot": "exemplar_4.png", } ] # Some text which is likely to cause problems if something isn't working tykes = [ # Text which doesn't render properly on Mac (Issue #3203) { "text": "कोशिकायें", "font": "Noto Sans", "size": 16, "screenshot": "tyke_1.png" }, # Thai text which old Text component couldn't handle due to Pyglet { "text": "ขาว แดง เขียว เหลือง ชมพู ม่วง เทา", "font": "Niramit", "size": 16, "screenshot": "tyke_2.png" }, # Text which had the top cut off { "text": "โฬิปื้ด็ลู", "font": "Niramit", "size": 36, "screenshot": "cutoff_top.png" }, ] # Test each case and compare against screenshot for case in exemplars + tykes: self.textbox.reset() self.textbox.fontMGR.addGoogleFont(case['font']) self.textbox.letterHeight = layout.Size(case['size'], "pix", self.win) self.textbox.font = case['font'] self.textbox.text = case['text'] self.win.flip() self.textbox.draw() if case['screenshot']: # Uncomment to save current configuration as desired filename = "textbox_{}_{}".format(self.textbox._lineBreaking, case['screenshot']) self.win.getMovieFrame(buffer='back').save( Path(utils.TESTS_DATA_PATH) / filename) #utils.compareScreenshot(Path(utils.TESTS_DATA_PATH) / filename, self.win, crit=20) def test_colors(self): # Do base tests _TestColorMixin.test_colors(self) # Do own custom tests self.textbox.text = "A PsychoPy zealot knows a smidge of wx, but JavaScript is the question." # Some exemplar text to test basic colors exemplars = [ # White on black in rgb { "color": (1, 1, 1), "fillColor": (-1, -1, -1), "borderColor": (-1, -1, -1), "space": "rgb", "screenshot": "colors_WOB.png" }, # White on black in named { "color": "white", "fillColor": "black", "borderColor": "black", "space": "rgb", "screenshot": "colors_WOB.png" }, # White on black in hex { "color": "#ffffff", "fillColor": "#000000", "borderColor": "#000000", "space": "hex", "screenshot": "colors_WOB.png" }, { "color": "red", "fillColor": "yellow", "borderColor": "blue", "space": "rgb", "screenshot": "colors_exemplar1.png" }, { "color": "yellow", "fillColor": "blue", "borderColor": "red", "space": "rgb", "screenshot": "colors_exemplar2.png" }, { "color": "blue", "fillColor": "red", "borderColor": "yellow", "space": "rgb", "screenshot": "colors_exemplar3.png" }, ] # Some colors which are likely to cause problems if something isn't working tykes = [ # Text only { "color": "white", "fillColor": None, "borderColor": None, "space": "rgb", "screenshot": "colors_tyke1.png" }, # Fill only { "color": None, "fillColor": "white", "borderColor": None, "space": "rgb", "screenshot": "colors_tyke2.png" }, # Border only { "color": None, "fillColor": None, "borderColor": "white", "space": "rgb", "screenshot": "colors_tyke3.png" }, ] # Test each case and compare against screenshot for case in exemplars + tykes: # Raise error if case spec does not contain all necessary keys if not all( key in case for key in ["color", "fillColor", "borderColor", "space", "screenshot"]): raise KeyError( f"Case spec for test_colors in class {self.__class__.__name__} ({__file__}) invalid, test cannot be run." ) # Apply params from case spec self.textbox.colorSpace = case['space'] self.textbox.color = case['color'] self.textbox.fillColor = case['fillColor'] self.textbox.borderColor = case['borderColor'] for lineBreaking in ('default', 'uax14'): self.win.flip() self.textbox.draw() if case['screenshot']: # Uncomment to save current configuration as desired filename = "textbox_{}_{}".format(self.textbox._lineBreaking, case['screenshot']) # self.win.getMovieFrame(buffer='back').save(Path(utils.TESTS_DATA_PATH) / filename) utils.compareScreenshot(Path(utils.TESTS_DATA_PATH) / filename, self.win, crit=20)