def resetWindowProperties(self, pipe, properties): if base.win: currentProperties = WindowProperties(base.win.getProperties()) gsg = base.win.getGsg() else: currentProperties = WindowProperties.getDefault() gsg = None newProperties = WindowProperties(currentProperties) newProperties.addProperties(properties) if base.pipe != pipe: gsg = None if gsg == None or currentProperties.getFullscreen() != newProperties.getFullscreen() or currentProperties.getParentWindow() != newProperties.getParentWindow(): self.notify.debug('window properties: %s' % properties) self.notify.debug('gsg: %s' % gsg) base.pipe = pipe if not base.openMainWindow(props=properties, gsg=gsg, keepCamera=True): self.notify.warning('OPEN MAIN WINDOW FAILED') return 0 self.notify.info('OPEN MAIN WINDOW PASSED') base.graphicsEngine.openWindows() if base.win.isClosed(): self.notify.warning('Window did not open, removing.') base.closeWindow(base.win) return 0 base.disableShowbaseMouse() if 'libotp' in sys.modules: from libotp import NametagGlobals NametagGlobals.setCamera(base.cam) NametagGlobals.setMouseWatcher(base.mouseWatcherNode) else: self.notify.debug('Adjusting properties') base.win.requestProperties(properties) base.graphicsEngine.renderFrame() return 1
def set(self, pipe, width, height, fullscreen, embedded): self.notify.debugStateCall(self) state = False self.notify.info('SET') if self.restrict_to_embedded: fullscreen = 0 embedded = 1 if embedded: if base.appRunner.windowProperties: width = base.appRunner.windowProperties.getXSize() height = base.appRunner.windowProperties.getYSize() self.current_pipe = base.pipe self.current_properties = WindowProperties(base.win.getProperties()) properties = self.current_properties self.notify.debug('DISPLAY PREVIOUS:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) self.notify.debug('DISPLAY REQUESTED:') self.notify.debug(' EMBEDDED: %s' % bool(embedded)) self.notify.debug(' FULLSCREEN: %s' % bool(fullscreen)) self.notify.debug(' X SIZE: %s' % width) self.notify.debug(' Y SIZE: %s' % height) if self.current_pipe == pipe and bool(self.current_properties.getParentWindow()) == bool(embedded) and self.current_properties.getFullscreen() == fullscreen and self.current_properties.getXSize() == width and self.current_properties.getYSize() == height: self.notify.info('DISPLAY NO CHANGE REQUIRED') state = True else: properties = WindowProperties() properties.setSize(width, height) properties.setFullscreen(fullscreen) properties.setParentWindow(0) if embedded: if base.appRunner.windowProperties: properties = base.appRunner.windowProperties original_sort = base.win.getSort() if self.resetWindowProperties(pipe, properties): self.notify.debug('DISPLAY CHANGE SET') properties = base.win.getProperties() self.notify.debug('DISPLAY ACHIEVED:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) if bool(properties.getParentWindow()) == bool(embedded) and properties.getFullscreen() == fullscreen and properties.getXSize() == width and properties.getYSize() == height: self.notify.info('DISPLAY CHANGE VERIFIED') state = True else: self.notify.warning('DISPLAY CHANGE FAILED, RESTORING PREVIOUS DISPLAY') self.restoreWindowProperties() else: self.notify.warning('DISPLAY CHANGE FAILED') self.notify.warning('DISPLAY SET - BEFORE RESTORE') self.restoreWindowProperties() self.notify.warning('DISPLAY SET - AFTER RESTORE') base.win.setSort(original_sort) base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() return state
def toggle_fullscreen(self): """ Toggles fullscreen mode.""" props = WindowProperties(self.win.getProperties()) if props.getFullscreen(): props.setSize(*self.size) props.setFullscreen(False) else: w = self.pipe.getDisplayWidth() h = self.pipe.getDisplayHeight() props.setSize(w, h) props.setFullscreen(True) self.win.requestProperties(props)
def toggleFullScreen(self): props = WindowProperties( self.win.getProperties() ) if not props.getFullscreen(): props.setSize(int(game_settings['screen_resolution'][0]),int(game_settings['screen_resolution'][1])) props.setFullscreen(True) else: props.setFullscreen(False) self.win.requestProperties(props) game_settings['full_screen'] = not game_settings['full_screen'] if self.configForm: self.configForm.refreshSettings() messenger.send('window-event', [self])
def toggleFullScreen(self): props = WindowProperties(self.win.getProperties()) if not props.getFullscreen(): props.setSize(int(game_settings['screen_resolution'][0]), int(game_settings['screen_resolution'][1])) props.setFullscreen(True) else: props.setFullscreen(False) self.win.requestProperties(props) game_settings['full_screen'] = not game_settings['full_screen'] if self.configForm: self.configForm.refreshSettings() messenger.send('window-event', [self])
class DisplayOptions: notify = DirectNotifyGlobal.directNotify.newCategory('DisplayOptions') def __init__(self): self.restore_failed = False self.loadFromSettings() def loadFromSettings(self): Settings.readSettings() mode = not Settings.getWindowedMode() music = Settings.getMusic() sfx = Settings.getSfx() toonChatSounds = Settings.getToonChatSounds() musicVol = Settings.getMusicVolume() sfxVol = Settings.getSfxVolume() resList = [(640, 480), (800, 600), (1024, 768), (1280, 1024), (1600, 1200)] res = resList[Settings.getResolution()] embed = Settings.getEmbeddedMode() self.notify.debug('before prc settings embedded mode=%s' % str(embed)) self.notify.debug('before prc settings full screen mode=%s' % str(mode)) if mode == None: mode = 1 if res == None: res = (800, 600) if not Settings.doSavedSettingsExist(): self.notify.info( 'loadFromSettings: No settings; isDefaultEmbedded=%s' % self.isDefaultEmbedded()) embed = self.isDefaultEmbedded() if embed and not self.isEmbeddedPossible(): self.notify.warning('Embedded mode is not possible.') embed = False if not mode and not self.isWindowedPossible(): self.notify.warning('Windowed mode is not possible.') mode = True loadPrcFileData('toonBase Settings Window Res', 'win-size %s %s' % (res[0], res[1])) self.notify.debug('settings resolution = %s' % str(res)) loadPrcFileData('toonBase Settings Window FullScreen', 'fullscreen %s' % mode) self.notify.debug('settings full screen mode=%s' % str(mode)) loadPrcFileData('toonBase Settings Music Active', 'audio-music-active %s' % music) loadPrcFileData('toonBase Settings Sound Active', 'audio-sfx-active %s' % sfx) loadPrcFileData('toonBase Settings Music Volume', 'audio-master-music-volume %s' % musicVol) loadPrcFileData('toonBase Settings Sfx Volume', 'audio-master-sfx-volume %s' % sfxVol) loadPrcFileData('toonBase Settings Toon Chat Sounds', 'toon-chat-sounds %s' % toonChatSounds) self.settingsFullScreen = mode self.settingsWidth = res[0] self.settingsHeight = res[1] self.settingsEmbedded = embed self.notify.debug('settings embedded mode=%s' % str(self.settingsEmbedded)) self.notify.info( 'settingsFullScreen = %s, embedded = %s width=%d height=%d' % (self.settingsFullScreen, self.settingsEmbedded, self.settingsWidth, self.settingsHeight)) return def restrictToEmbedded(self, restrict, change_display=True): if base.appRunner is None or base.appRunner.windowProperties is None: restrict = 0 self.restrict_to_embedded = choice(restrict, 1, 0) self.notify.debug('restrict_to_embedded: %s' % self.restrict_to_embedded) if change_display: self.set(base.pipe, self.settingsWidth, self.settingsHeight, self.settingsFullScreen, self.settingsEmbedded) return def set(self, pipe, width, height, fullscreen, embedded): self.notify.debugStateCall(self) state = False self.notify.info('SET') if self.restrict_to_embedded: fullscreen = 0 embedded = 1 if embedded: if base.appRunner.windowProperties: width = base.appRunner.windowProperties.getXSize() height = base.appRunner.windowProperties.getYSize() self.current_pipe = base.pipe self.current_properties = WindowProperties(base.win.getProperties()) properties = self.current_properties self.notify.debug('DISPLAY PREVIOUS:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) self.notify.debug('DISPLAY REQUESTED:') self.notify.debug(' EMBEDDED: %s' % bool(embedded)) self.notify.debug(' FULLSCREEN: %s' % bool(fullscreen)) self.notify.debug(' X SIZE: %s' % width) self.notify.debug(' Y SIZE: %s' % height) if self.current_pipe == pipe and bool( self.current_properties.getParentWindow( )) == bool(embedded) and self.current_properties.getFullscreen( ) == fullscreen and self.current_properties.getXSize( ) == width and self.current_properties.getYSize() == height: self.notify.info('DISPLAY NO CHANGE REQUIRED') state = True else: properties = WindowProperties() properties.setSize(width, height) properties.setFullscreen(fullscreen) properties.setParentWindow(0) if embedded: if base.appRunner.windowProperties: properties = base.appRunner.windowProperties original_sort = base.win.getSort() if self.resetWindowProperties(pipe, properties): self.notify.debug('DISPLAY CHANGE SET') properties = base.win.getProperties() self.notify.debug('DISPLAY ACHIEVED:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) if bool(properties.getParentWindow()) == bool( embedded) and properties.getFullscreen( ) == fullscreen and properties.getXSize( ) == width and properties.getYSize() == height: self.notify.info('DISPLAY CHANGE VERIFIED') state = True else: self.notify.warning( 'DISPLAY CHANGE FAILED, RESTORING PREVIOUS DISPLAY') self.restoreWindowProperties() else: self.notify.warning('DISPLAY CHANGE FAILED') self.notify.warning('DISPLAY SET - BEFORE RESTORE') self.restoreWindowProperties() self.notify.warning('DISPLAY SET - AFTER RESTORE') base.win.setSort(original_sort) base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() return state def resetWindowProperties(self, pipe, properties): if base.win: currentProperties = WindowProperties(base.win.getProperties()) gsg = base.win.getGsg() else: currentProperties = WindowProperties.getDefault() gsg = None newProperties = WindowProperties(currentProperties) newProperties.addProperties(properties) if base.pipe != pipe: gsg = None if gsg == None or currentProperties.getFullscreen( ) != newProperties.getFullscreen( ) or currentProperties.getParentWindow( ) != newProperties.getParentWindow(): self.notify.debug('window properties: %s' % properties) self.notify.debug('gsg: %s' % gsg) base.pipe = pipe if not base.openMainWindow( props=properties, gsg=gsg, keepCamera=True): self.notify.warning('OPEN MAIN WINDOW FAILED') return 0 self.notify.info('OPEN MAIN WINDOW PASSED') base.graphicsEngine.openWindows() if base.win.isClosed(): self.notify.warning('Window did not open, removing.') base.closeWindow(base.win) return 0 base.disableShowbaseMouse() if 'libotp' in sys.modules: from libotp import NametagGlobals NametagGlobals.setCamera(base.cam) NametagGlobals.setMouseWatcher(base.mouseWatcherNode) else: self.notify.debug('Adjusting properties') base.win.requestProperties(properties) base.graphicsEngine.renderFrame() return 1 def restoreWindowProperties(self): if self.resetWindowProperties(self.current_pipe, self.current_properties): self.restore_failed = False else: self.notify.warning("Couldn't restore original display settings!") if base.appRunner and base.appRunner.windowProperties: fullscreen = 0 embedded = 1 tryProps = base.appRunner.windowProperties if self.resetWindowProperties(self.current_pipe, tryProps): self.current_properties = copy.copy(tryProps) self.restore_failed = False return if self.current_properties.getFullscreen(): fullscreen = 0 embedded = 0 tryProps = self.current_properties tryProps.setFullscreen(0) if self.resetWindowProperties(self.current_pipe, tryProps): self.current_properties = copy.copy(tryProps) self.restore_failed = False return self.notify.error('Failed opening regular window!') base.panda3dRenderError() self.restore_failed = True @staticmethod def isDefaultEmbedded(): result = False try: embedOption = int( base.launcher.getValue('GAME_DEFAULT_TO_EMBEDDED', None)) if embedOption != None: result = bool(int(embedOption)) except: pass return result @staticmethod def isEmbeddedPossible(): result = False try: showOption = base.launcher.getValue('GAME_SHOW_EMBEDDED_OPTION', None) if showOption != None: result = bool(int(showOption)) except: pass return result @staticmethod def isWindowedPossible(): result = True try: showOption = base.launcher.getValue('GAME_SHOW_WINDOWED_OPTION', None) if showOption != None: result = bool(int(showOption)) except: pass return result
def __init__(self): "初始化" dir = os.path.dirname(game_settings['save_folder']) if not os.path.exists(dir): os.makedirs(dir) self.initGameSettings() #读取设置文件 loadPrcFile("config/PandaConfig.prc") loadPrcFileData( '', 'win-size ' + str(game_settings['screen_resolution'][0]) + ' ' + str(game_settings['screen_resolution'][1])) #构造Panda3D的ShowBase ShowBase.__init__(self) #Retrieving available resolutions #self.makeDefaultPipe() di = self.pipe.getDisplayInformation() self.supportedResolutions = [] for index in range(di.getTotalDisplayModes()): self.supportedResolutions.append((di.getDisplayModeWidth(index), di.getDisplayModeHeight(index))) color_themes.initStyles() props = WindowProperties(self.win.getProperties()) props.setSize(int(game_settings['screen_resolution'][0]), int(game_settings['screen_resolution'][1])) if game_settings['full_screen'] and not props.getFullscreen(): props.setFullscreen(True) props.setTitle(game_settings['window_title']) self.win.requestProperties(props) self.cam2dp.node().getDisplayRegion(0).setSort( -20) #Set render2dp to background self.disableMouse() #Disable panda3d's default mouse control self.cam.node().getDisplayRegion(0).setActive( 0) #disable default camera self.audioPlayer = AudioPlayer() self.focusStack = [] #a stack that shows windowstop window gets focus self._loadReadText() self._loadGlobalData() #add event handlers self.accept('alt-enter', self.toggleFullScreen) self.accept('save_data', self.save) self.accept('load_data', self.load) self.accept('load_memory', self.loadMemory) self.accept('request_focus', self.grantFocus) self.accept('remove_focus', self.cancelFocus) self.accept('return_to_title', self.returnToTitle) self.accept('start_game', self.startGame) self.accept('load_game', self.loadGame) self.accept('config_form', self.showConfig) self.accept('exit_game', self.exit) self.accept('quick_save', self.quickSave) self.accept('quick_load', self.quickLoad) self.accept('auto_save', self.autoSave) self.accept('print_screen', self.takeScrnShot) self.accept('f10', self.takeScrnShot) #Font setting self.textFont = color_themes.default_font #背景设置 self.setBackgroundColor(0, 0, 0, 1) self.backgroundImage = None self.initGameWindows() self.mainMenu = None self.storyManager = None
def __init__(self): "初始化" dir = os.path.dirname(game_settings['save_folder']) if not os.path.exists(dir): os.makedirs(dir) self.initGameSettings() #读取设置文件 loadPrcFile("config/PandaConfig.prc") loadPrcFileData('', 'win-size ' + str(game_settings['screen_resolution'][0]) + ' ' + str(game_settings['screen_resolution'][1]) ) #构造Panda3D的ShowBase ShowBase.__init__(self) #Retrieving available resolutions #self.makeDefaultPipe() di = self.pipe.getDisplayInformation() self.supportedResolutions = [] for index in range(di.getTotalDisplayModes()): self.supportedResolutions.append((di.getDisplayModeWidth(index), di.getDisplayModeHeight(index))) color_themes.initStyles() props = WindowProperties( self.win.getProperties() ) props.setSize(int(game_settings['screen_resolution'][0]),int(game_settings['screen_resolution'][1])) if game_settings['full_screen'] and not props.getFullscreen(): props.setFullscreen(True) props.setTitle(game_settings['window_title']) self.win.requestProperties(props) self.cam2dp.node().getDisplayRegion(0).setSort(-20) #Set render2dp to background self.disableMouse() #Disable panda3d's default mouse control self.cam.node().getDisplayRegion(0).setActive(0) #disable default camera self.audioPlayer = AudioPlayer() self.focusStack = [] #a stack that shows windowstop window gets focus self._loadReadText() self._loadGlobalData() #add event handlers self.accept('alt-enter', self.toggleFullScreen) self.accept('save_data', self.save) self.accept('load_data', self.load) self.accept('load_memory', self.loadMemory) self.accept('request_focus', self.grantFocus) self.accept('remove_focus', self.cancelFocus) self.accept('return_to_title', self.returnToTitle) self.accept('start_game', self.startGame) self.accept('load_game', self.loadGame) self.accept('config_form', self.showConfig) self.accept('exit_game', self.exit) self.accept('quick_save', self.quickSave) self.accept('quick_load', self.quickLoad) self.accept('auto_save', self.autoSave) self.accept('print_screen', self.takeScrnShot) self.accept('f10', self.takeScrnShot) #Font setting self.textFont = color_themes.default_font #背景设置 self.setBackgroundColor(0,0,0,1); self.backgroundImage = None self.initGameWindows() self.mainMenu = None self.storyManager = None
def __init__(self): # Initialize the ShowBase class from which we inherit, which will # create a window and set up everything we need for rendering into it. ShowBase.__init__(self) self.stimtype = 'random image' # session_start self.session_start_time = datetime.datetime.now() # self.accept("escape", sys.exit, [0])#don't let the user do this, because then the data isn't saved. self.accept('q', self.close) self.accept('Q', self.close) self.upArrowIsPressed = base.mouseWatcherNode.isButtonDown(KeyboardButton.up()) self.downArrowIsPressed = base.mouseWatcherNode.isButtonDown(KeyboardButton.down()) self.rightArrowIsPressed = base.mouseWatcherNode.isButtonDown(KeyboardButton.right()) self.leftArrowIsPressed = base.mouseWatcherNode.isButtonDown(KeyboardButton.left()) self.AUTO_REWARD = AUTO_REWARD # disable mouse control so that we can place the camera base.disableMouse() camera.setPosHpr(0, 0, 10, 0, -90, 0) mat = Mat4(camera.getMat()) mat.invertInPlace() base.mouseInterfaceNode.setMat(mat) # base.enableMouse() props = WindowProperties() # props.setOrigin(0, 0) props.setFullscreen(True) props.setCursorHidden(True) props.setMouseMode(WindowProperties.M_relative) base.win.requestProperties(props) base.setBackgroundColor(0, 0, 0) # set the background color to black print('FULSCREEN:') print(props.getFullscreen()) print('=============') # set up the textures # we now get buffer thats going to hold the texture of our new scene altBuffer = self.win.makeTextureBuffer("hello", 1524, 1024) # altBuffer.getDisplayRegion(0).setDimensions(0.5,0.9,0.5,0.8) # altBuffer = base.win.makeDisplayRegion() # altBuffer.makeDisplayRegion(0,1,0,1) # now we have to setup a new scene graph to make this scene self.dr2 = base.win.makeDisplayRegion(0, 0.001, 0, 0.001)#make this really,really small so it's not seeable by the subject altRender = NodePath("new render") # this takes care of setting up ther camera properly self.altCam = self.makeCamera(altBuffer) self.dr2.setCamera(self.altCam) self.altCam.reparentTo(altRender) self.altCam.setPos(0, -10, 0) self.bufferViewer.setPosition("lrcorner") # self.bufferViewer.position = (-.1,-.4,-.1,-.4) self.bufferViewer.setCardSize(1.0, 0.0) print(self.bufferViewer.position) self.imagesTexture = MovieTexture("image_sequence") # success = self.imagesTexture.read("models/natural_images.avi") # success = self.imagesTexture.read("models/movie_5hz.mpg") self.imagesTexture.setPlayRate(1.0) self.imagesTexture.setLoopCount(10) # self.imageTexture =loader.loadTexture("models/NaturalImages/BSDs_8143.tiff") # self.imagesTexture.reparentTo(altRender) self.fixationPoint = OnscreenImage(image='models/fixationpoint.jpg', pos=(0, 0,0),scale=0.01) cm = CardMaker("stimwindow") cm.setFrame(-4, 4, -3, 3) # cm.setUvRange(self.imagesTexture) self.card = NodePath(cm.generate()) self.card.reparentTo(altRender) if self.stimtype == 'image_sequence': self.card.setTexture(self.imagesTexture, 1) # add the score display self.scoreLabel = OnscreenText(text='Current Score:', pos=(-1, 0.9), scale=0.1, fg=(0.8, 0.8, 0.8, 1)) self.scoreText = OnscreenText(text=str(0), pos=(-1, 0.76), scale=0.18, fg=(0, 1, 0, 1), shadow=(0.1, 1, 0.1, 0.5)) self.feebackScoreText = OnscreenText(text='+ ' + str(0), pos=(-0.5, 0.5), scale=0.3, fg=(0, 1, 0, 1), shadow=(0.1, 1, 0.1, 0.5)) self.feebackScoreText.setX(3.) # self.imagesTexture.play() # self.bufferViewer.setPosition("lrcorner") # self.bufferViewer.setCardSize(1.0, 0.0) self.accept("v", self.bufferViewer.toggleEnable) self.accept("V", self.bufferViewer.toggleEnable) # Load the tunnel self.initTunnel() # initialize some things # for the tunnel construction: self.boundary_to_add_next_segment = -1 * TUNNEL_SEGMENT_LENGTH self.current_number_of_segments = 8 # task flow booleans self.in_waiting_period = False self.stim_started = False self.looking_for_a_cue_zone = True self.in_reward_window = False self.show_stimulus = False # for task control self.interval = 0 self.time_waiting_in_cue_zone = 0 self.wait_time = 1.83 self.stim_duration = 0 # in seconds # self.distribution_type = np.random.uniform# # self.distribution_type_inputs = [0.016,0.4] #change the min & max stim duration times #New lines EAS: set weights higher for faster image durations self.durWeights = list() a = np.linspace(0.016,0.4,10) for i,j in enumerate(a): if j<0.1: p1 = 0.25 self.durWeights.append(p1) elif j > 0.1 and j < 0.21: p1 = 0.1 self.durWeights.append(p1) elif j> 0.21: p1 = 0.04 self.durWeights.append(p1) self.rng = np.random.default_rng() a = np.asarray(a) self.distribution_type_inputs = a #subset_size = len(p) #End new lines # self.distribution_type_inputs = [0.05,1.5] #can be anytong should match # self.distribution_type_inputs = [0.016,0.4] #change the min & max stim duration times # self.distribution_type_inputs = [0.016,0.4, 10] #change the min & max stim duration times self.max_stim_duration = 1.0 # in seconds self.stim_elapsed = 0.0 # in seconds self.last_position = base.camera.getZ() self.position_on_track = base.camera.getZ() # for reward control self.reward_window = REWARD_WINDOW # in seconds self.reward_elapsed = 0.0 # self.new_dt = list() # self.reward_volume = 0.008 # in mL. this is for the hardcoded 0.1 seconds of reward time self.reward_volume = int(REWARD_VOLUME) # in uL, for the stepper motor self.reward_time = 0.1 # in sec, based on volume. hard coded right now but should be modified by the (1) calibration and (2) optionally by the main loop for dynamic reward scheduling # self.lick_buffer = [] self.current_score = 0 self.score = 0 self.feedback_score_startime = -2 # INITIALIZE NIDAQ self.nidevice = 'Dev2' self.encodervinchannel = 1 self.encodervsigchannel = 0 self.invertdo = False self.diport = 1 self.lickline = 1 self.doport = 0 self.rewardline = 0 self.rewardlines = [0] self.encoder_position_diff = 0 if have_nidaq: self._setupDAQ() self.do.WriteBit(1, 1) self.do.WriteBit(3, 1) # set reward high, because the logic is flipped somehow. possibly by haphazard wiring of the circuit (12/24/2018 djd) self.previous_encoder_position = self.ai.data[0][self.encodervsigchannel] else: self.previous_encoder_position = 0 self.encoder_gain = 3 # INITIALIZE LICK SENSOR self._lickSensorSetup() # INITIALIZE output data self.lickData = [] self.x = [] self.t = [] self.trialData = [] self.reactionTimeData = [] self.rewardData = [] self.rightKeyData = [] self.leftKeyData = [] self.imageData = [] self.imageTimeData = [] self.scoreData = [] self.trialDurationData = [] self.new_dt = [] # INITIALIZE KEY SENSOR, for backup inputs and other user controls self.keys = key.KeyStateHandler() self.accept('r', self._give_reward, [self.reward_volume]) self.accept('l', self._toggle_reward) # initialize the image list and populate what images you want included # self.img_list = glob.glob('models/2AFC_IMAGES_HUMAN/*.tif') # self.img_list = glob.glob('models/2AFC_IMAGES_HUMAN2/*.tif') # self.img_list = glob.glob('/Users/elizabethstubblefield/Desktop/cheetah_or_elephant/composite_images/masks/all_same_num_ea/*.tif') #Newest images self.img_list = glob.glob('models/all_same_ea/*.tif') #Newest images #No longer hard-coded: self.original_indices = [0,0] #this was manually counted... first number must was the index of the first easy img; was [43, -18] for ndx, name in enumerate(self.img_list): if 'Cheetah255' in name: self.original_indices[0] = ndx elif 'Elephant0' in name: self.original_indices[1] = ndx # print(self.img_list) # self.original_indices = [43,-18] #manually counted, grump #Problematic w/out at least 43 images in the folder self.imageTextures =[loader.loadTexture(img) for img in self.img_list] self.img_id = None #this variable is used so we know which stimulus is being presented self.img_mask = None #this tells us what the image mask being presented is # self._setupEyetracking() # self._startEyetracking() if AUTO_MODE: self.gameTask = taskMgr.add(self.autoLoop2, "autoLoop2") self.rewardTask = taskMgr.add(self.rewardControl, "reward") self.cue_zone = concatenate((self.cue_zone, arange( \ self.current_number_of_segments * -TUNNEL_SEGMENT_LENGTH-50, \ self.current_number_of_segments * -TUNNEL_SEGMENT_LENGTH - TUNNEL_SEGMENT_LENGTH - 100, \ -1))) self.auto_position_on_track = 0 self.auto_restart = False self.auto_running = True self.contTunnel() else: # Now we create the task. taskMgr is the task manager that actually # calls the function each frame. The add method creates a new task. # The first argument is the function to be called, and the second # argument is the name for the task. It returns a task object which # is passed to the function each frame. self.gameTask = taskMgr.add(self.gameLoop, "gameLoop") # self.stimulusTask = taskMgr.add(self.stimulusControl, "stimulus") self.lickTask = taskMgr.add(self.lickControl, "lick") self.rewardTask = taskMgr.add(self.rewardControl, "reward") self.keyTask = taskMgr.add(self.keyControl, "Key press")
class DisplayOptions: notify = DirectNotifyGlobal.directNotify.newCategory('DisplayOptions') def __init__(self): self.restore_failed = False self.loadFromSettings() def loadFromSettings(self): fullscreen = base.settings.getBool('game', 'fullscreen', False) music = base.settings.getBool('game', 'music', True) sfx = base.settings.getBool('game', 'sfx', True) toonChatSounds = base.settings.getBool('game', 'toon-chat-sounds', True) textToSpeech = base.settings.getBool('game', 'text-to-speech', False) textToSpeechPath = base.settings.getString('game', 'text-to-speech-path', base.defaultTextToSpeechPath) globalChatWhispers = base.settings.getBool('game', 'global-chat-whispers', True) chatLogOpen = base.settings.getBool('game', 'chat-log-open', False) chatLogPos = base.settings.getList('game', 'chat-log-pos', [0.05, 0, 0.25]) chatLogScale = base.settings.getFloat('game', 'chat-log-scale', 1.0) musicVol = base.settings.getFloat('game', 'music-volume', 1.0) sfxVol = base.settings.getFloat('game', 'sfx-volume', 1.0) res = base.settings.getList('game', 'resolution', [800, 600]) embed = base.settings.getBool('game', 'embedded-mode', False) antialias = base.settings.getInt('game', 'antialiasing', 0) if antialias: loadPrcFileData('toonBase Settings Framebuffer MSAA', 'framebuffer-multisample 1') loadPrcFileData('toonBase Settings MSAA Level', 'multisamples %i' % antialias) else: base.settings.updateSetting('game', 'antialiasing', antialias) loadPrcFileData('toonBase Settings Framebuffer MSAA', 'framebuffer-multisample 0') self.notify.debug('before prc settings embedded mode=%s' % str(embed)) self.notify.debug('before prc settings full screen mode=%s' % str(fullscreen)) if not base.settings.doSavedSettingsExist(): self.notify.info('loadFromSettings: No settings; isDefaultEmbedded=%s' % self.isDefaultEmbedded()) embed = self.isDefaultEmbedded() if embed and not self.isEmbeddedPossible(): self.notify.warning('Embedded mode is not possible.') embed = False if not fullscreen and not self.isWindowedPossible(): self.notify.warning('Windowed mode is not possible.') fullscreen = True loadPrcFileData('toonBase Settings Window Res', 'win-size %s %s' % (res[0], res[1])) self.notify.debug('settings resolution = %s' % str(res)) loadPrcFileData('toonBase Settings Window FullScreen', 'fullscreen %s' % fullscreen) self.notify.debug('settings full screen mode=%s' % str(fullscreen)) loadPrcFileData('toonBase Settings Music Active', 'audio-music-active %s' % music) loadPrcFileData('toonBase Settings Sound Active', 'audio-sfx-active %s' % sfx) loadPrcFileData('toonBase Settings Music Volume', 'audio-master-music-volume %s' % musicVol) loadPrcFileData('toonBase Settings Sfx Volume', 'audio-master-sfx-volume %s' % sfxVol) loadPrcFileData('toonBase Settings Toon Chat Sounds', 'toon-chat-sounds %s' % toonChatSounds) loadPrcFileData('toonBase Settings Text to Speech', 'text-to-speech %s' % textToSpeech) loadPrcFileData('toonBase Settings Text to Speech Path', 'text-to-speech-path %s' % textToSpeechPath) loadPrcFileData('toonBase Settings Global Chat Whispers', 'global-chat-whispers %s' % globalChatWhispers) loadPrcFileData('toonBase Settings Chat Log Open', 'chat-log-open %s' % chatLogOpen) loadPrcFileData('toonBase Settings Chat Log Pos', 'chat-log-pos %s, %s, %s' % (str(chatLogPos[0]), str(chatLogPos[1]), str(chatLogPos[2]))) loadPrcFileData('toonBase Settings Chat Log Scale', 'chat-log-scale %s' % chatLogScale) self.settingsFullScreen = fullscreen self.settingsWidth = res[0] self.settingsHeight = res[1] self.settingsEmbedded = embed self.settingsAntialiasing = antialias self.notify.debug('settings embedded mode=%s' % str(self.settingsEmbedded)) self.notify.info('settingsFullScreen = %s, embedded = %s width=%d height=%d' % (self.settingsFullScreen, self.settingsEmbedded, self.settingsWidth, self.settingsHeight)) def restrictToEmbedded(self, restrict, change_display=True): if base.appRunner is None or base.appRunner.windowProperties is None: restrict = 0 self.restrict_to_embedded = choice(restrict, 1, 0) self.notify.debug('restrict_to_embedded: %s' % self.restrict_to_embedded) if change_display: self.set(base.pipe, self.settingsWidth, self.settingsHeight, self.settingsFullScreen, self.settingsEmbedded) return def set(self, pipe, width, height, fullscreen, embedded): self.notify.debugStateCall(self) state = False self.notify.info('SET') if self.restrict_to_embedded: fullscreen = 0 embedded = 1 if embedded: if base.appRunner.windowProperties: width = base.appRunner.windowProperties.getXSize() height = base.appRunner.windowProperties.getYSize() self.current_pipe = base.pipe self.current_properties = WindowProperties(base.win.getProperties()) properties = self.current_properties self.notify.debug('DISPLAY PREVIOUS:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) self.notify.debug('DISPLAY REQUESTED:') self.notify.debug(' EMBEDDED: %s' % bool(embedded)) self.notify.debug(' FULLSCREEN: %s' % bool(fullscreen)) self.notify.debug(' X SIZE: %s' % width) self.notify.debug(' Y SIZE: %s' % height) if self.current_pipe == pipe and bool(self.current_properties.getParentWindow()) == bool(embedded) and self.current_properties.getFullscreen() == fullscreen and self.current_properties.getXSize() == width and self.current_properties.getYSize() == height: self.notify.info('DISPLAY NO CHANGE REQUIRED') state = True else: properties = WindowProperties() properties.setSize(width, height) properties.setFullscreen(fullscreen) properties.setParentWindow(0) if embedded: if base.appRunner.windowProperties: properties = base.appRunner.windowProperties original_sort = base.win.getSort() if self.resetWindowProperties(pipe, properties): self.notify.debug('DISPLAY CHANGE SET') properties = base.win.getProperties() self.notify.debug('DISPLAY ACHIEVED:') self.notify.debug(' EMBEDDED: %s' % bool(properties.getParentWindow())) self.notify.debug(' FULLSCREEN: %s' % bool(properties.getFullscreen())) self.notify.debug(' X SIZE: %s' % properties.getXSize()) self.notify.debug(' Y SIZE: %s' % properties.getYSize()) if bool(properties.getParentWindow()) == bool(embedded) and properties.getFullscreen() == fullscreen and properties.getXSize() == width and properties.getYSize() == height: self.notify.info('DISPLAY CHANGE VERIFIED') state = True else: self.notify.warning('DISPLAY CHANGE FAILED, RESTORING PREVIOUS DISPLAY') self.restoreWindowProperties() else: self.notify.warning('DISPLAY CHANGE FAILED') self.notify.warning('DISPLAY SET - BEFORE RESTORE') self.restoreWindowProperties() self.notify.warning('DISPLAY SET - AFTER RESTORE') base.win.setSort(original_sort) base.graphicsEngine.renderFrame() base.graphicsEngine.renderFrame() return state def resetWindowProperties(self, pipe, properties): if base.win: currentProperties = WindowProperties(base.win.getProperties()) gsg = base.win.getGsg() else: currentProperties = WindowProperties.getDefault() gsg = None newProperties = WindowProperties(currentProperties) newProperties.addProperties(properties) if base.pipe != pipe: gsg = None if gsg == None or currentProperties.getFullscreen() != newProperties.getFullscreen() or currentProperties.getParentWindow() != newProperties.getParentWindow(): self.notify.debug('window properties: %s' % properties) self.notify.debug('gsg: %s' % gsg) base.pipe = pipe if not base.openMainWindow(props=properties, gsg=gsg, keepCamera=True): self.notify.warning('OPEN MAIN WINDOW FAILED') return 0 self.notify.info('OPEN MAIN WINDOW PASSED') base.graphicsEngine.openWindows() if base.win.isClosed(): self.notify.warning('Window did not open, removing.') base.closeWindow(base.win) return 0 base.disableShowbaseMouse() if 'libotp' in sys.modules: from libotp import NametagGlobals NametagGlobals.setCamera(base.cam) NametagGlobals.setMouseWatcher(base.mouseWatcherNode) else: self.notify.debug('Adjusting properties') base.win.requestProperties(properties) base.graphicsEngine.renderFrame() return 1 def restoreWindowProperties(self): if self.resetWindowProperties(self.current_pipe, self.current_properties): self.restore_failed = False else: self.notify.warning("Couldn't restore original display settings!") if base.appRunner and base.appRunner.windowProperties: fullscreen = 0 embedded = 1 tryProps = base.appRunner.windowProperties if self.resetWindowProperties(self.current_pipe, tryProps): self.current_properties = copy.copy(tryProps) self.restore_failed = False return if self.current_properties.getFullscreen(): fullscreen = 0 embedded = 0 tryProps = self.current_properties tryProps.setFullscreen(0) if self.resetWindowProperties(self.current_pipe, tryProps): self.current_properties = copy.copy(tryProps) self.restore_failed = False return self.notify.error('Failed opening regular window!') base.panda3dRenderError() self.restore_failed = True @staticmethod def isDefaultEmbedded(): result = False try: embedOption = int(base.launcher.getValue('GAME_DEFAULT_TO_EMBEDDED', None)) if embedOption != None: result = bool(int(embedOption)) except: pass return result @staticmethod def isEmbeddedPossible(): result = False try: showOption = base.launcher.getValue('GAME_SHOW_EMBEDDED_OPTION', None) if showOption != None: result = bool(int(showOption)) except: pass return result @staticmethod def isWindowedPossible(): result = True try: showOption = base.launcher.getValue('GAME_SHOW_WINDOWED_OPTION', None) if showOption != None: result = bool(int(showOption)) except: pass return result