本文整理汇总了Python中pygame.display.get_init函数的典型用法代码示例。如果您正苦于以下问题:Python get_init函数的具体用法?Python get_init怎么用?Python get_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_init函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clearEvents
def clearEvents(eventType=None):
"""Clears all events currently in the event buffer.
Optional argument, eventType, specifies only certain types to be
cleared.
:Parameters:
eventType : **None**, 'mouse', 'joystick', 'keyboard'
If this is not None then only events of the given type are cleared
"""
#pyglet
if not havePygame or not display.get_init():
#for each (pyglet) window, dispatch its events before checking event buffer
wins = pyglet.window.get_platform().get_default_display().get_windows()
for win in wins:
win.dispatch_events()#pump events on pyglet windows
if eventType=='mouse':
return # pump pyglet mouse events but don't flush keyboard buffer
global _keyBuffer
_keyBuffer = []
else:
#for pygame
if eventType=='mouse':
junk = evt.get([locals.MOUSEMOTION, locals.MOUSEBUTTONUP,
locals.MOUSEBUTTONDOWN])
elif eventType=='keyboard':
junk = evt.get([locals.KEYDOWN, locals.KEYUP])
elif eventType=='joystick':
junk = evt.get([locals.JOYAXISMOTION, locals.JOYBALLMOTION,
locals.JOYHATMOTION, locals.JOYBUTTONUP, locals.JOYBUTTONDOWN])
else:
junk = evt.get()
示例2: __init__
def __init__(self, width, height, fullimage, starting_position=(0, 0)):
if not display.get_init():
display.init()
self.width = width
self.height = height
self.image = image.load(fullimage).convert()
self.rect = self.image.get_rect()
示例3: __init__
def __init__(self, width, height, fullimage, starting_position=(0, 0)):
if not display.get_init():
display.init()
self.full_image = image.load(fullimage)
self.width = width
self.height = height
self.x_sprites = self.full_image.get_width() / self.width
self.y_sprites = self.full_image.get_height() / self.height
self.update_current((0, 0, self.width, self.height))
self.rect = self.image.get_rect()
self.rect.topleft = starting_position
示例4: getKeys
def getKeys(keyList=None, modifiers=False, timeStamped=False):
"""Returns a list of keys that were pressed.
:Parameters:
keyList : **None** or []
Allows the user to specify a set of keys to check for.
Only keypresses from this set of keys will be removed from
the keyboard buffer. If the keyList is `None`, all keys will be
checked and the key buffer will be cleared completely.
NB, pygame doesn't return timestamps (they are always 0)
modifiers : **False** or True
If True will return a list of tuples instead of a list of
keynames. Each tuple has (keyname, modifiers). The modifiers
are a dict of keyboard modifier flags keyed by the modifier
name (eg. 'shift', 'ctrl').
timeStamped : **False**, True, or `Clock`
If True will return a list of tuples instead of a list of
keynames. Each tuple has (keyname, time). If a `core.Clock`
is given then the time will be relative to the `Clock`'s last
reset.
:Author:
- 2003 written by Jon Peirce
- 2009 keyList functionality added by Gary Strangman
- 2009 timeStamped code provided by Dave Britton
- 2016 modifiers code provided by 5AM Solutions
"""
keys = []
if havePygame and display.get_init():
# see if pygame has anything instead (if it exists)
for evts in evt.get(locals.KEYDOWN):
# pygame has no keytimes
keys.append((pygame.key.name(evts.key), 0))
elif havePyglet:
# for each (pyglet) window, dispatch its events before checking event
# buffer
defDisplay = pyglet.window.get_platform().get_default_display()
for win in defDisplay.get_windows():
try:
win.dispatch_events() # pump events on pyglet windows
except ValueError as e: # pragma: no cover
# Pressing special keys, such as 'volume-up', results in a
# ValueError. This appears to be a bug in pyglet, and may be
# specific to certain systems and versions of Python.
logging.error(u'Failed to handle keypress')
global _keyBuffer
if len(_keyBuffer) > 0:
# then pyglet is running - just use this
keys = _keyBuffer
# _keyBuffer = [] # DO /NOT/ CLEAR THE KEY BUFFER ENTIRELY
elif haveGLFW:
# 'poll_events' is called when a window is flipped, all the callbacks
# populate the buffer
if len(_keyBuffer) > 0:
keys = _keyBuffer
if keyList is None:
_keyBuffer = [] # clear buffer entirely
targets = keys # equivalent behavior to getKeys()
else:
nontargets = []
targets = []
# split keys into keepers and pass-thrus
for key in keys:
if key[0] in keyList:
targets.append(key)
else:
nontargets.append(key)
_keyBuffer = nontargets # save these
# now we have a list of tuples called targets
# did the user want timestamped tuples or keynames?
if modifiers == False and timeStamped == False:
keyNames = [k[0] for k in targets]
return keyNames
elif timeStamped == False:
keyNames = [(k[0], modifiers_dict(k[1])) for k in targets]
return keyNames
elif hasattr(timeStamped, 'getLastResetTime'):
# keys were originally time-stamped with
# core.monotonicClock._lastResetTime
# we need to shift that by the difference between it and
# our custom clock
_last = timeStamped.getLastResetTime()
_clockLast = psychopy.core.monotonicClock.getLastResetTime()
timeBaseDiff = _last - _clockLast
relTuple = [[_f for _f in (k[0], modifiers and modifiers_dict(k[1]) or None, k[-1] - timeBaseDiff) if _f] for k in targets]
return relTuple
elif timeStamped is True:
return [[_f for _f in (k[0], modifiers and modifiers_dict(k[1]) or None, k[-1]) if _f] for k in targets]
elif isinstance(timeStamped, (float, int, int)):
relTuple = [[_f for _f in (k[0], modifiers and modifiers_dict(k[1]) or None, k[-1] - timeStamped) if _f] for k in targets]
return relTuple
示例5: getKeys
def getKeys(keyList=None, timeStamped=False):
"""Returns a list of keys that were pressed.
:Parameters:
keyList : **None** or []
Allows the user to specify a set of keys to check for.
Only keypresses from this set of keys will be removed from the keyboard buffer.
If the keyList is None all keys will be checked and the key buffer will be cleared
completely. NB, pygame doesn't return timestamps (they are always 0)
timeStamped : **False** or True or `Clock`
If True will return a list of
tuples instead of a list of keynames. Each tuple has (keyname, time).
If a `core.Clock` is given then the time will be relative to the `Clock`'s last reset
:Author:
- 2003 written by Jon Peirce
- 2009 keyList functionality added by Gary Strangman
- 2009 timeStamped code provided by Dave Britton
"""
keys=[]
if havePygame and display.get_init():#see if pygame has anything instead (if it exists)
for evts in evt.get(locals.KEYDOWN):
keys.append( (pygame.key.name(evts.key),0) )#pygame has no keytimes
elif havePyglet:
#for each (pyglet) window, dispatch its events before checking event buffer
wins = pyglet.window.get_platform().get_default_display().get_windows()
for win in wins:
try:
win.dispatch_events()#pump events on pyglet windows
except ValueError as e:
# Pressing special keys, such as 'volume-up', results in a
# ValueError. This appears to be a bug in pyglet, and may be
# specific to certain systems and versions of Python.
logging.error(u'Failed to handle keypress')
global _keyBuffer
if len(_keyBuffer)>0:
#then pyglet is running - just use this
keys = _keyBuffer
# _keyBuffer = [] # DO /NOT/ CLEAR THE KEY BUFFER ENTIRELY
if keyList==None:
_keyBuffer = [] #clear buffer entirely
targets=keys # equivalent behavior to getKeys()
else:
nontargets = []
targets = []
# split keys into keepers and pass-thrus
for key in keys:
if key[0] in keyList:
targets.append(key)
else:
nontargets.append(key)
_keyBuffer = nontargets # save these
#now we have a list of tuples called targets
#did the user want timestamped tuples or keynames?
if timeStamped==False:
keyNames = [k[0] for k in targets]
return keyNames
elif hasattr(timeStamped, 'getLastResetTime'):
relTuple = [(k[0],k[1]-timeStamped.getLastResetTime()) for k in targets]
return relTuple
elif timeStamped==True:
return targets
示例6: screen_size
def screen_size():
''' '''
assert display.get_init()
info = display.Info()
return (info.current_w, info.current_h)