本文整理汇总了Python中pyglet.window方法的典型用法代码示例。如果您正苦于以下问题:Python pyglet.window方法的具体用法?Python pyglet.window怎么用?Python pyglet.window使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet
的用法示例。
在下文中一共展示了pyglet.window方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pyglet_key_down
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def pyglet_key_down(self, symbol, modifier, repeat_in=0.3):
from pyglet.window import key
self.last_key_down = symbol
self.last_key_modifier = modifier
self.next_key_repeat = time.time() + repeat_in
is_ascii = 27 <= symbol < 255
char = {
key.LEFT: KEYS.LEFT_ARROW,
key.RIGHT: KEYS.RIGHT_ARROW,
key.UP: KEYS.UP_ARROW,
key.DOWN: KEYS.DOWN_ARROW,
key.ENTER: '\r',
key.RETURN: '\r',
key.BACKSPACE: chr(127),
}.get(symbol, chr(symbol) if is_ascii else None)
if not char:
# All other characters don't count as a key press
# (e.g., function keys, modifier keys, etc.)
return
if modifier & key.MOD_SHIFT:
char = char.upper()
self.set_needs_display()
self.handle_input(char)
示例2: handle_key_repeat
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def handle_key_repeat(self, dt):
from pyglet.window import key
if self.state.last_command == "SHELL":
return self.handle_shell()
elif self.state.last_command == "SAVE AS":
return self.handle_save_as()
if time.time() < self.next_key_repeat:
return
symbol, modifier = self.last_key_down, self.last_key_modifier
self.last_key_down = self.last_key_modifier = None
if not self.keyboard[symbol]:
return
has_shift = self.keyboard[key.LSHIFT] or self.keyboard[key.RSHIFT]
if bool(modifier & key.MOD_SHIFT) != has_shift:
return
self.pyglet_key_down(symbol, modifier, repeat_in=0.045)
示例3: run_gl
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def run_gl(self):
try:
import pyglet
except ImportError:
print("Cannot import pyglet. Running text mode instead.")
print("(hit any key to continue)")
getch()
self.run_text()
else:
self.setup_run()
self.last_key_down = None
self.last_key_modifier = None
self.next_key_repeat = 0
self.window = pyglet.window.Window(resizable=True)
self.window.set_handler('on_draw', self.render_gl)
self.window.set_handler('on_key_press', self.pyglet_key_down)
self.window.set_handler('on_resize', self.set_needs_display)
self.window.set_handler('on_show', self.set_needs_display)
self.keyboard = pyglet.window.key.KeyStateHandler()
self.window.push_handlers(self.keyboard)
pyglet.clock.schedule_interval(self.handle_key_repeat, 0.02)
pyglet.app.run()
示例4: __init__
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def __init__(self, width, height, aa):
pyglet.window.Window.__init__(self,
width,
height,
caption="Loxodromic transformation",
resizable=True,
visible=False,
vsync=False)
self._start_time = time.clock()
self.shader = Shader(["./glsl/loxodrome.vert"], ["./glsl/loxodrome.frag"])
self.buffer = pyglet.image.get_buffer_manager().get_color_buffer()
texture = create_image_texture(WOOD_TEXTURE)
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(gl.GL_TEXTURE_2D, texture)
with self.shader:
self.shader.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
self.shader.uniformf("iResolution", width, height, 0.0)
self.shader.uniformf("iTime", 0.0)
self.shader.uniformi("iTexture", 0)
self.shader.uniformi("AA", aa)
示例5: on_key_release
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def on_key_release(symbol, modifiers):
global player
global bigScreen
global smallScreen
if symbol == key.SPACE:
player.jump()
if symbol == key.PAGEUP:
if smallScreen == True:
glScalef(2.0, 2.0, 2.0)
window.set_size(window.width * 2, window.height * 2)
smallScreen = False
bigScreen = True
if symbol == key.PAGEDOWN:
if bigScreen:
glScalef(0.5, 0.5, 0.5)
window.set_size(window.width / 2 , window.height /2)
smallScreen = True
bigScreen = False
# Handle mouse presses
示例6: begin_clear_background
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def begin_clear_background():
global asteroids
global bullets
global animations
for bullet in bullets:
bullet.delete()
for animation in animations:
animation.delete()
asteroids = []
bullets = []
animations = []
player.visible = False
# --------------------------------------------------------------------------
# Create window
# --------------------------------------------------------------------------
示例7: draw
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def draw(self, x, y):
'''Abstract render method.
The cursor should be drawn with the "hot" spot at the given
coordinates. The projection is set to the pyglet default (i.e.,
orthographic in window-space), however no other aspects of the
state can be assumed.
:Parameters:
`x` : int
X coordinate of the mouse pointer's hot spot.
`y` : int
Y coordinate of the mouse pointer's hot spot.
'''
raise NotImplementedError('abstract')
示例8: _PlatformEventHandler
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def _PlatformEventHandler(data):
'''Decorator for platform event handlers.
Apply giving the platform-specific data needed by the window to associate
the method with an event. See platform-specific subclasses of this
decorator for examples.
The following attributes are set on the function, which is returned
otherwise unchanged:
_platform_event
True
_platform_event_data
List of data applied to the function (permitting multiple decorators
on the same method).
'''
def _event_wrapper(f):
f._platform_event = True
if not hasattr(f, '_platform_event_data'):
f._platform_event_data = []
f._platform_event_data.append(data)
return f
return _event_wrapper
示例9: on_resize
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def on_resize(self, width, height):
'''A default resize event handler.
This default handler updates the GL viewport to cover the entire
window and sets the ``GL_PROJECTION`` matrix to be orthogonal in
window space. The bottom-left corner is (0, 0) and the top-right
corner is the width and height of the window in pixels.
Override this event handler with your own to create another
projection, for example in perspective.
'''
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -1, 1)
gl.glMatrixMode(gl.GL_MODELVIEW)
示例10: close
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def close(self):
'''Close the window.
After closing the window, the GL context will be invalid. The
window instance cannot be reused once closed (see also `set_visible`).
The `pyglet.app.EventLoop.on_window_close` event is dispatched on
`pyglet.app.event_loop` when this method is called.
'''
from pyglet import app
if not self._context:
return
app.windows.remove(self)
self._context.destroy()
self._config = None
self._context = None
if app.event_loop:
app.event_loop.dispatch_event('on_window_close', self)
示例11: set_minimum_size
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def set_minimum_size(self, width, height):
'''Set the minimum size of the window.
Once set, the user will not be able to resize the window smaller
than the given dimensions. There is no way to remove the
minimum size constraint on a window (but you could set it to 0,0).
The behaviour is undefined if the minimum size is set larger than
the current size of the window.
The window size does not include the border or title bar.
:Parameters:
`width` : int
Minimum width of the window, in pixels.
`height` : int
Minimum height of the window, in pixels.
'''
raise NotImplementedError('abstract')
示例12: set_maximum_size
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def set_maximum_size(self, width, height):
'''Set the maximum size of the window.
Once set, the user will not be able to resize the window larger
than the given dimensions. There is no way to remove the
maximum size constraint on a window (but you could set it to a large
value).
The behaviour is undefined if the maximum size is set smaller than
the current size of the window.
The window size does not include the border or title bar.
:Parameters:
`width` : int
Maximum width of the window, in pixels.
`height` : int
Maximum height of the window, in pixels.
'''
raise NotImplementedError('abstract')
示例13: set_vsync
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def set_vsync(self, vsync):
'''Enable or disable vertical sync control.
When enabled, this option ensures flips from the back to the front
buffer are performed only during the vertical retrace period of the
primary display. This can prevent "tearing" or flickering when
the buffer is updated in the middle of a video scan.
Note that LCD monitors have an analogous time in which they are not
reading from the video buffer; while it does not correspond to
a vertical retrace it has the same effect.
With multi-monitor systems the secondary monitor cannot be
synchronised to, so tearing and flicker cannot be avoided when the
window is positioned outside of the primary display. In this case
it may be advisable to forcibly reduce the framerate (for example,
using `pyglet.clock.set_fps_limit`).
:Parameters:
`vsync` : bool
If True, vsync is enabled, otherwise it is disabled.
'''
raise NotImplementedError('abstract')
示例14: set_exclusive_mouse
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def set_exclusive_mouse(self, exclusive=True):
'''Hide the mouse cursor and direct all mouse events to this
window.
When enabled, this feature prevents the mouse leaving the window. It
is useful for certain styles of games that require complete control of
the mouse. The position of the mouse as reported in subsequent events
is meaningless when exclusive mouse is enabled; you should only use
the relative motion parameters ``dx`` and ``dy``.
:Parameters:
`exclusive` : bool
If True, exclusive mouse is enabled, otherwise it is disabled.
'''
raise NotImplementedError('abstract')
示例15: set_icon
# 需要导入模块: import pyglet [as 别名]
# 或者: from pyglet import window [as 别名]
def set_icon(self, *images):
'''Set the window icon.
If multiple images are provided, one with an appropriate size
will be selected (if the correct size is not provided, the image
will be scaled).
Useful sizes to provide are 16x16, 32x32, 64x64 (Mac only) and
128x128 (Mac only).
:Parameters:
`images` : sequence of `pyglet.image.AbstractImage`
List of images to use for the window icon.
'''
pass