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)
python类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_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 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 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 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 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._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 set_vsync(self, vsync):
if pyglet.options['vsync'] is not None:
vsync = pyglet.options['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 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 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 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 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 _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 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