我们从Python开源项目中,提取了以下37个代码示例,用于说明如何使用pyglet.options()。
def set_exclusive_keyboard(self, exclusive=True): # http://developer.apple.com/mac/library/technotes/tn2002/tn2062.html # http://developer.apple.com/library/mac/#technotes/KioskMode/ # BUG: System keys like F9 or command-tab are disabled, however # pyglet also does not receive key press events for them. # This flag is queried by window delegate to determine whether # the quit menu item is active. self._is_keyboard_exclusive = exclusive if exclusive: # "Be nice! Don't disable force-quit!" # -- Patrick Swayze, Road House (1989) options = NSApplicationPresentationHideDock | \ NSApplicationPresentationHideMenuBar | \ NSApplicationPresentationDisableProcessSwitching | \ NSApplicationPresentationDisableHideApplication else: options = NSApplicationPresentationDefault NSApp = NSApplication.sharedApplication() NSApp.setPresentationOptions_(options)
def _create_track_region(self): self._remove_track_region() # Create a tracking region for the content part of the window # to receive enter/leave events. track_id = MouseTrackingRegionID() track_id.signature = DEFAULT_CREATOR_CODE track_id.id = 1 self._track_ref = MouseTrackingRef() self._track_region = carbon.NewRgn() if self._fullscreen: carbon.SetRectRgn(self._track_region, self._view_x, self._view_y, self._view_x + self._width, self._view_y + self._height) options = kMouseTrackingOptionsGlobalClip else: carbon.GetWindowRegion(self._window, kWindowContentRgn, self._track_region) options = kMouseTrackingOptionsGlobalClip carbon.CreateMouseTrackingRegion(self._window, self._track_region, None, options, track_id, None, None, byref(self._track_ref))
def _error_handler(display, event): # By default, all errors are silently ignored: this has a better chance # of working than the default behaviour of quitting ;-) # # We've actually never seen an error that was our fault; they're always # driver bugs (and so the reports are useless). Nevertheless, set # environment variable PYGLET_DEBUG_X11 to 1 to get dumps of the error # and a traceback (execution will continue). import pyglet if pyglet.options['debug_x11']: event = event.contents buf = c_buffer(1024) xlib.XGetErrorText(display, event.error_code, buf, len(buf)) print('X11 error:', buf.value) print(' serial:', event.serial) print(' request:', event.request_code) print(' minor:', event.minor_code) print(' resource:', event.resourceid) import traceback print('Python stack trace (innermost last):') traceback.print_stack() return 0
def check_state(self): if self.items[self.select_item] == 'FULLSCREEN': self.fullscreen = not self.fullscreen self.window.set_fullscreen(self.fullscreen,width=self.window.width, height=self.window.height) elif self.items[self.select_item] == 'AUDIO': self.audio = not self.audio if self.audio: pyglet.options['audio'] = ('openal') elif not self.audio: pyglet.options['audio'] = ('silent') elif self.items[self.select_item] == 'SHAKE': self.shake = not self.shake self.pos = self.window.get_location() elif self.items[self.select_item] == 'INITIALISE': self.init = True self.save_init()
def set_vsync(self, vsync): if pyglet.options['vsync'] is not None: vsync = pyglet.options['vsync'] self._vsync = vsync # _recreate depends on this if self.context: self.context.set_vsync(vsync)
def set_vsync(self, vsync): if pyglet.options['vsync'] is not None: vsync = pyglet.options['vsync'] self._vsync = vsync self.context.set_vsync(vsync)
def dump_pyglet(): '''Dump pyglet version and options.''' import pyglet print('pyglet.version:', pyglet.version) print('pyglet.compat_platform:', pyglet.compat_platform) print('pyglet.__file__:', pyglet.__file__) for key, value in pyglet.options.items(): print("pyglet.options['%s'] = %r" % (key, value))
def get_audio_driver(): global _audio_driver if _audio_driver: return _audio_driver _audio_driver = None for driver_name in pyglet.options['audio']: try: if driver_name == 'pulse': from . import pulse _audio_driver = pulse.create_audio_driver() break elif driver_name == 'openal': from . import openal _audio_driver = openal.create_audio_driver() break elif driver_name == 'directsound': from . import directsound _audio_driver = directsound.create_audio_driver() break elif driver_name == 'silent': _audio_driver = get_silent_audio_driver() break except Exception as exp: if _debug: print('Error importing driver %s:' % driver_name) import traceback traceback.print_exc() return _audio_driver
def _thread_run(self): if pyglet.options['debug_trace']: pyglet._install_trace() with self._threads_lock: self._threads.add(self) self.run() with self._threads_lock: self._threads.remove(self)
def _create_shadow_window(): global _shadow_window import pyglet if not pyglet.options['shadow_window'] or _is_epydoc: return from pyglet.window import Window _shadow_window = Window(width=1, height=1, visible=False) _shadow_window.switch_to() from pyglet import app app.windows.remove(_shadow_window)
def set_vsync(self, vsync): if pyglet.options['vsync'] is not None: vsync = pyglet.options['vsync'] self.context.set_vsync(vsync)
def playMusic(song, rhythm): pyglet.options['audio'] = ('openal', 'silent') switcherNotes = { #pyglet.media.load("A.wav").play() 1: "A.wav", #A 2: "A#.wav",#A# 3: "B.wav",#B" 4: "C.wav",#C" 5: "C#.wav",#C#" 6: "D.wav",#D" 7: "D#.wav",#D#" 8: "E.wav",#E" 9: "F.wav",#F" 10: "F#.wav",#F#" 11: "G.wav",#G" 12: "G#.wav" #G#" } switcherRhythms = { 0: 0.75, 1: 0.0625, 2: 0.125, 3: 0.25, 4: 1.5, 5: 0.5, 6: 3, 7: 1 } #player = pyglet.media.Player() for i in range(0, len(song)): totalTime = 0 while(totalTime < switcherRhythms[rhythm[i]]): if song[i] != 0: pyglet.media.load(switcherNotes[song[i]], streaming=False).play() #time.sleep(switcherRhythms[rhythm[i]]*.5) time.sleep(.0625*1.5) totalTime += .0625 #pyglet.media.load("A.wav").play() #notes
def dump_pyglet(): '''Dump pyglet version and options.''' import pyglet print('pyglet.version:', pyglet.version) print('pyglet.compat_platform:', pyglet.compat_platform) print('pyglet.__file__:', pyglet.__file__) for key, value in list(pyglet.options.items()): print("pyglet.options['%s'] = %r" % (key, value))
def get_audio_driver(): global _audio_driver if _audio_driver: return _audio_driver _audio_driver = None for driver_name in pyglet.options['audio']: try: if driver_name == 'pulse': from .drivers import pulse _audio_driver = pulse.create_audio_driver() break elif driver_name == 'openal': from .drivers import openal _audio_driver = openal.create_audio_driver() break elif driver_name == 'directsound': from .drivers import directsound _audio_driver = directsound.create_audio_driver() break elif driver_name == 'silent': _audio_driver = get_silent_audio_driver() break except Exception as exp: if _debug: print('Error importing driver %s:\n%s' % (driver_name, str(exp))) return _audio_driver
def setup(): """Called to setup initial sketch options. The `setup()` function is run once when the program starts and is used to define initial environment options for the sketch. """ pass
def mask(self, value): """The alpha mask (forming the shape of the image) This can be one of various options: + 'circle', 'gauss', 'raisedCos', 'cross', **None** (resets to default) + the name of an image file (most formats supported) + a numpy array (1xN or NxN) ranging -1:1 """ self.__dict__['mask'] = value if self.__class__.__name__ == 'ImageStim': dataType = GL.GL_UNSIGNED_BYTE else: dataType = None self._createTexture(value, id=self._maskID, pixFormat=GL.GL_ALPHA, dataType=dataType, stim=self, res=self.texRes, maskParams=self.maskParams)
def units(self, value): """ None, 'norm', 'cm', 'deg', 'degFlat', 'degFlatPos', or 'pix' If None then the current units of the :class:`~psychopy.visual.Window` will be used. See :ref:`units` for explanation of other options. Note that when you change units, you don't change the stimulus parameters and it is likely to change appearance. Example:: # This stimulus is 20% wide and 50% tall with respect to window stim = visual.PatchStim(win, units='norm', size=(0.2, 0.5) # This stimulus is 0.2 degrees wide and 0.5 degrees tall. stim.units = 'deg' """ if value != None and len(value): self.__dict__['units'] = value else: self.__dict__['units'] = self.win.units # Update size and position if they are defined (tested as numeric). If not, this is probably # during some init and they will be defined later, given the new unit. try: self.size * self.pos # quick and dirty way to check that both are numeric. This avoids the heavier attributeSetter calls. self.size = self.size self.pos = self.pos except: pass
def main(): """Start the game.""" logger.info('Started main program') pyglet.options['debug_gl'] = False CONFIG = load_config() window_config = CONFIG['window'] window = GameWindow(window_config['width'], window_config['height'], fullscreen=window_config['fullscreen'], resizable=window_config['resizable'], style=window_config['style'], vsync=CONFIG['graphics']['vsync']) # Configurate window window.set_mouse_visible(window_config['mouse']) window.set_icon(pyglet.resource.image(CONFIG['resources']['icon'])) screen_background = widgets.FilledBoxWidget( position=(0, 0), dimensions=(window.x_tiles, window.y_tiles), removable=False, tile_color=ThemeColors.MENU, tile_id=219) # Create the screen border screen_border = widgets.BorderWidget(position=(0, 0), dimensions=(window.x_tiles, window.y_tiles), removable=False, tile_color=ThemeColors.BORDER, tiles=(178, 178, 178, 178, 35, 35, 35, 35)) # Create the selection menu selection_menu =\ widgets.SelectionMenuWidget( position=(window.x_tiles / 4 + 1, window.y_tiles / 2), dimensions=(window.x_tiles / 2, window.y_tiles / 4), # (TileColor(Border), TileColor(Menu), Default, Active, Selected) colors=(ThemeColors.BORDER, ThemeColors.MENU, ThemeColors.TEXT_DEFAULT, ThemeColors.TEXT_ACTIVE, ThemeColors.TEXT_SELECT), # Menu options (name, method, args) options=( ('Compile World', compile_world, []), ('Testing Area', pdb.set_trace, []), ('Saves/Worlds', None, []), ('Settings', None, []), ('Credits/About', None, []), ('Exit', pyglet.app.exit, []))) # Prepare widgets for rendering window.push_widget(screen_background) window.push_widget(screen_border) window.push_widget(selection_menu) pyglet.app.run()
def load_sound_library(): """ Special code for Windows so we grab the proper avbin from our directory. Otherwise hope the correct package is installed. """ # lazy loading if not load_sound_library._sound_library_loaded: load_sound_library._sound_library_loaded = True else: return import os appveyor = not os.environ.get('APPVEYOR') is None import platform system = platform.system() if system == 'Windows': import sys is64bit = sys.maxsize > 2**32 import site packages = site.getsitepackages() if appveyor: if is64bit: path = "Win64/avbin" else: path = "Win32/avbin" else: if is64bit: path = packages[0] + "/lib/site-packages/arcade/Win64/avbin" else: path = packages[0] + "/lib/site-packages/arcade/Win32/avbin" elif system == 'Darwin': from distutils.sysconfig import get_python_lib path = get_python_lib() + '/lib/site-packages/arcade/lib/libavbin.10.dylib' pyglet.options['audio'] = ('openal', 'pulse', 'silent') else: path = "avbin" pyglet.options['audio'] = ('openal', 'pulse', 'silent') pyglet.lib.load_library(path) pyglet.have_avbin = True # Initialize static function variable
def contains(self, x, y=None, units=None): """Returns True if a point x,y is inside the stimulus' border. Can accept variety of input options: + two separate args, x and y + one arg (list, tuple or array) containing two vals (x,y) + an object with a getPos() method that returns x,y, such as a :class:`~psychopy.event.Mouse`. Returns `True` if the point is within the area defined either by its `border` attribute (if one defined), or its `vertices` attribute if there is no .border. This method handles complex shapes, including concavities and self-crossings. Note that, if your stimulus uses a mask (such as a Gaussian) then this is not accounted for by the `contains` method; the extent of the stimulus is determined purely by the size, position (pos), and orientation (ori) settings (and by the vertices for shape stimuli). See Coder demos: shapeContains.py """ #get the object in pixels if hasattr(x, 'border'): xy = x._borderPix #access only once - this is a property units = 'pix' #we can forget about the units elif hasattr(x, 'verticesPix'): xy = x.verticesPix #access only once - this is a property (slower to access) units = 'pix' #we can forget about the units elif hasattr(x, 'getPos'): xy = x.getPos() units = x.units elif type(x) in [list, tuple, numpy.ndarray]: xy = numpy.array(x) else: xy = numpy.array((x,y)) #try to work out what units x,y has if units is None: if hasattr(xy, 'units'): units = xy.units else: units = self.units if units != 'pix': xy = convertToPix(xy, pos=(0,0), units=units, win=self.win) # ourself in pixels if hasattr(self, 'border'): poly = self._borderPix # e.g., outline vertices else: poly = self.verticesPix # e.g., tesselated vertices return pointInPolygon(xy[0], xy[1], poly=poly)