def loadManbar(self, n): """Load Manbar n setting in dimstim config file and assign it to the current manual bar""" mbn = "Manbar" + str(n) self.x = intround( deg2pix(dc.get(mbn, "xorigDeg")) + I.SCREENWIDTH / 2 ) # int pix, since pygame.mouse pos works with ints self.y = intround(deg2pix(dc.get(mbn, "yorigDeg")) + I.SCREENHEIGHT / 2) self.widthDeg = dc.get(mbn, "widthDeg") self.heightDeg = dc.get(mbn, "heightDeg") self.ori = dc.get(mbn, "orioff") self.fp.position = self.x, self.y
def saveManbar(self, n): """Save the state of the current manual bar as Manbar n in dimstim config file""" mbn = 'Manbar' + str(n) dc.set(mbn, 'xorigDeg', roundec(pix2deg(self.x - I.SCREENWIDTH / 2), ndec=6)) dc.set(mbn, 'yorigDeg', roundec(pix2deg(self.y - I.SCREENHEIGHT / 2), ndec=6)) dc.set(mbn, 'widthDeg', roundec(self.widthDeg, ndec=6)) dc.set(mbn, 'heightDeg', roundec(self.heightDeg, ndec=6)) dc.set(mbn, 'orioff', intround(self.ori)) dc.update() self.fp.position = self.x, self.y self.brightenText = mbn # brighten the text for feedback
def loadManbar(self, n): """Load Manbar n setting in dimstim config file and assign it to the current manual bar""" mbn = 'Manbar' + str(n) self.x = intround(I.SCREENWIDTH / 2) # initial horizontal position self.y = self.ypos #allow user to set vertical position self.widthDeg = self.terrain.objectwidthDeg #provided by user in script self.heightDeg = self.terrain.objectwidthDeg #same DW self.offscreen = self.off_screen_distance(self.terrain.orientation) self.ori = self.terrain.orientation self.fp.position = self.x, self.y # to use later for eye-tracking # for grating self.gratingori = 0 self.tfreqCycSec = 1 self.sfreqCycDeg = 1 self.phase0 = 0 self.contrast = 1 self.sfreqmultiplier = 1.01 self.tfreqmultiplier = 1.01 self.contrastmultiplier = 1.01
def get_brightness(self): """Get target brightness""" if self.PLUS: self.brightness += self.brightnessstep elif self.MINUS: self.brightness -= self.brightnessstep self.brightness = max(self.brightness, 0) # keep it >= 0 self.brightness = min(self.brightness, 1) # keep it <= 1 """Set flash speed""" # DW AIBS if self.BRRIGHT: self.flashSec += self.flashSecStep elif self.BRLEFT: self.flashSec -= self.flashSecStep self.flashSec = max(self.flashSec, 0) if self.flashSec == 0: self.flash = False self.tp.on = True # toggle it self.tipp.on = True else: self.flash = True self.flashvsyncs = sec2intvsync(self.flashSec) self.flashvsyncs = intround( self.flashvsyncs / self.nscreens ) # normalize by number of screens to flip in each loop in main()
def run(self, caption='Manual bar'): """Run the experiment""" info('Running Experiment script: %s' % self.script) # Init OpenGL graphics windows, one window per requested screen platform = pyglet.window.get_platform() display = platform.get_default_display() self.screens = display.get_screens() self.screens = self.screens[:self.nscreens] # keep the first nscreens requested self.nscreens = len(self.screens) # update self.flashvsyncs = intround(self.flashvsyncs / self.nscreens) # normalize by number of screens to flip in each loop in main() self.wins = [] for screeni, screen in enumerate(self.screens): # make all screens fullscreen, except for the first (user) screen if screeni == 0: win = Window(screen=screen, fullscreen=False, frameless=False) win.win.set_location((screen.width - win.win.width)//2, (screen.height - win.win.height)//2) win.win.set_caption(caption) else: win = Window(screen=screen, fullscreen=True) win.win.set_exclusive_mouse(False) self.wins.append(win) self.setgamma(self.params.gamma) # Create VisionEgg stimuli objects, defined by each specific subclass of Experiment self.createstimuli() # Create viewport(s) with varying stimuli self.viewports = [] for wini, win in enumerate(self.wins): if wini == 0: self.viewports.append(ve.Core.pyglet_Viewport(window=win, stimuli=self.all_stimuli)) else: self.viewports.append(ve.Core.pyglet_Viewport(window=win, stimuli=self.basic_stimuli)) self.loadManbar(0) # load settings from Manbar0 self.bgp.color = self.bgbrightness, self.bgbrightness, self.bgbrightness, 1.0 # Create the VsyncTimer self.vsynctimer = Core.VsyncTimer() ''' # Hack to fix pygame jumping mouse bug in fullscreen mode # mousemotion event happens on startup, and then once more due to bug for i in range(2): pygame.event.peek(pl.MOUSEMOTION) pygame.mouse.set_pos(self.x, I.SCREENHEIGHT - 1 - self.y) # set that sucker ''' self.attach_handlers() self.nvsyncsdisplayed = 0 # nvsyncs seen by Surf self.startdatetime = datetime.datetime.now() self.starttime = time.clock() # precision timestamp # Run the main stimulus loop, defined by each specific subclass of Experiment self.main() self.stoptime = time.clock() # precision timestamp self.stopdatetime = datetime.datetime.now() # Close OpenGL graphics windows (necessary when running from Python interpreter) self.wins[0].restore_gamma_ramps() # only needs to be done once for win in self.wins: win.close() #Turn off rotary encoder self.encoder.clear() #Turn off reward self.reward.stop() self.reward.clear() # Print messages to VisionEgg log and to screen info(self.vsynctimer.pprint(), toscreen=self.printhistogram, tolog=self.printhistogram) info('%d vsyncs displayed' % self.nvsyncsdisplayed) info('Experiment duration: %s' % isotime(self.stoptime-self.starttime, 6)) printf2log('\n' + '-'*80 + '\n') # add minuses to end of log to space it out between sessions self.logmeta()