Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@w.event
def on_mouse_press(x, y, button, modifiers):
if button == window.mouse.LEFT:
#filename = filenames[advance.i]
w.clicked = True
w.close()
pyglet.app.exit()
def exit(self):
"""Safely exit the event loop at the end of the current iteration.
This method is a thread-safe equivalent for setting
:py:attr:`has_exit` to ``True``. All waiting threads will be
interrupted (see :py:meth:`sleep`).
"""
self.has_exit = True
app.platform_event_loop.notify()
def on_key_press(symbol, modifiers):
if symbol == key.P:
self.window.close()
pyglet.app.exit()
self.user_action = None
elif symbol == key.R:
self.reset()
self.window.close()
pyglet.app.exit()
elif symbol == key.E:
self.window.close()
pyglet.app.exit()
self.user_action = -1
import pyglet
# vytvoÅenĆ okna
window = pyglet.window.Window(width=640,
height=480,
caption="Pyglet library")
@window.event
def on_draw():
"""Obsluha udĆ”losti - pÅekreslenĆ obsahu okna."""
window.clear()
# spuÅ”tÄnĆ smyÄky pro zpracovĆ”nĆ udĆ”lostĆ
pyglet.app.run()
def run(self):
self.window.set_visible()
#from IPython import embed
#embed()
if self.mode == 'b':
pyglet.app.run()
else:
#run one loop iteration only (draw one frame)
pyglet.clock.tick()
for window in pyglet.app.windows:
window.switch_to()
window.dispatch_events()
window.dispatch_event('on_draw')
window.flip()
if self.mode == 'c':
pyglet.clock.schedule_once(self.stop, 1/self.fps)
vertex_list.draw(GL_TRIANGLES)
batch.draw()
standalone_sprite.draw()
def update(dt):
for sprite in sprites:
sprite.rotation += 100 * dt % 360
if __name__ == "__main__":
pyglet.gl.glClearColor(0.2, 0.3, 0.3, 1)
pyglet.clock.schedule_interval(update, 1/60)
pyglet.app.run()
def start(graphic=True):
global board
board = Board(graphic)
board.spawn_tile()
board.spawn_tile()
if graphic:
pyglet.clock.schedule_interval(smart_move, 1/120)
pyglet.app.run()
else:
for i in range(0, 100):
print(i)
smart_move(0)
if board.lost:
break
board.show()
print("Score:", board.score)
if symbol in (key.LEFT, key.RIGHT):
world.component_for_entity(player, Velocity).x = 0
@window.event
def on_draw():
# Clear the window:
window.clear()
# Draw the batch of Renderables:
renderbatch.draw()
def update(dt):
# A single call to world.process() will update all Processors:
world.process()
pyglet.clock.schedule_interval(update, 1.0 / FPS)
pyglet.app.run()
# Do it now.
window._recreate_immediate()
sleep_time = self.idle()
if sleep_time is None:
sleep_time = constants.kEventDurationForever
elif sleep_time < 0.01 and allow_polling and self._allow_polling:
# Switch event loop to polling.
if in_events:
carbon.QuitEventLoop(self._event_loop)
self._force_idle = True
sleep_time = constants.kEventDurationForever
carbon.SetEventLoopTimerNextFireTime(timer, ctypes.c_double(sleep_time))
pyglet.app.EventLoop = MTCarbonEventLoop
"""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)
self._event_queue = []