How to use the pyglet.app function in pyglet

To help you get started, weā€™ve selected a few pyglet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lutris / lutris / lutris / coverflow / coverflow.py View on Github external
    @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()
github pyglet / pyglet / pyglet / app / base.py View on Github external
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()
github aigagror / GymGo / gym_go / envs / go_env.py View on Github external
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
github tisnik / presentations / pyglet / 03_on_draw_event.py View on Github external
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()
github kjyv / FloBaRoID / visualizer.py View on Github external
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)
github pyglet / pyglet / examples / opengl_core.py View on Github external
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()
github rcbyron / 2048-ai / client / old-ai.py View on Github external
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)
github benmoran56 / esper / examples / pyglet_example_batch.py View on Github external
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()
github pyglet / pyglet / experimental / mt_media / mt_app_carbon.py View on Github external
# 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
github ajhager / copycat / lib / pyglet / window / __init__.py View on Github external
"""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 = []