How to use the pyglet.window 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 pyglet / pyglet / examples / noisy / noisy.py View on Github external
"""

import random
import sys

from pyglet.gl import *
import pyglet
from pyglet.window import key

BALL_IMAGE = 'ball.png'
BALL_SOUND = 'ball.wav'

if len(sys.argv) > 1:
    BALL_SOUND = sys.argv[1]

window = pyglet.window.Window(640, 480)

sound = pyglet.resource.media(BALL_SOUND, streaming=False)
balls_batch = pyglet.graphics.Batch()
balls = []
label = pyglet.text.Label('Press space to add a ball, backspace to remove',
                          font_size=14,
                          x=window.width // 2, y=10,
                          anchor_x='center')


class Ball(pyglet.sprite.Sprite):
    ball_image = pyglet.resource.image(BALL_IMAGE)
    width = ball_image.width
    height = ball_image.height

    def __init__(self):
github bitcraft / PURIKURA / old-camera / preview-horror.py View on Github external
self.sprite = pyglet.sprite.Sprite(image)

    def draw(self):
        self.sprite.draw()
        #self.prev_sprite.opactiy = 100
        #self.prev_sprite.draw()

update_interval = 1./60
preview_size = (640,480)

w, h = preview_size
minimum, maximum = min(preview_size), max(preview_size)
crop_dim = (((maximum - minimum)/2), 0,
            maximum - ((maximum - minimum)/2), minimum)

window = pyglet.window.Window(fullscreen=True)

def capture(dt=0):
    global live_view
    c.capture_image('photo.jpg')
    im = Image.open('photo.jpg')
    im.thumbnail(preview_size)
    im = im.transpose(Image.FLIP_TOP_BOTTOM)
    width, height = im.size
    image = ImageData(width, height, im.mode, im.tostring())
    #window.clear()
    image.blit(0,0)
    live_view = False


if __name__ == '__main__':
    camera = piggyphoto.camera()
github swiftcoder / simplui / simplui / button.py View on Github external
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
		if button == pyglet.window.mouse.LEFT and self._down:
			if self.active_region.hit_test(x, y):
				self.shapes['frame'].patch = self.theme['button']['image_down']
			else:
				self.shapes['frame'].patch = self.theme['button']['image_up']
			
			return pyglet.event.EVENT_HANDLED
				
		Widget.on_mouse_drag(self, x, y, dx, dy, button, modifiers)
		return pyglet.event.EVENT_UNHANDLED
github tisnik / presentations / pyglet / 03_on_draw_event.py View on Github external
# vim: set fileencoding=utf-8

# ---------------------------------------------------------------------
#
# Demonstrační příklady využívající knihovnu Pyglet
#
# Příklad číslo 3: obsluha události - překreslení obsahu okna
#
# ---------------------------------------------------------------------


# všechny třídy a funkce jsou obsaženy v jediném modulu nazvaném pyglet
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 neozhaoliang / pywonderland / src / fractal3d / fractal3d.py View on Github external
def __init__(self, width, height, scene_file, AA=4):
        """
        :param width and height: size of the window in pixels.

        :param scene_file: the fragment shader file to render.

        :param AA: antialiasing level, AA=4 is good enough (but also slow).
        """
        pyglet.window.Window.__init__(self,
                                      width,
                                      height,
                                      caption="Fractal3D",
                                      resizable=True,
                                      visible=False,
                                      vsync=False)
        self._start_time = time.clock()
        self.AA = AA
        self.shader = Shader(["./glsl/fractal3d.vert"], [scene_file])
        self.scene = pathlib.Path(scene_file).resolve().stem
        self.init_shader()
        self.buffer = pyglet.image.get_buffer_manager().get_color_buffer()
github andrea-cuttone / geoplotlib / geoplotlib / core.py View on Github external
self.draw_label_background(l, painter)
        painter.batch_draw()
        for l in self.labels.values():
            l.draw()


    def clear(self):
        for l in self.labels.values():
            l.text = ''


    def add_colorbar(self, cmap, vmax, colormap_scale):
        self.colorbar = UiManager.Colorbar(cmap, vmax, colormap_scale, self.font_size)


class GeoplotlibApp(pyglet.window.Window):

    def __init__(self, geoplotlib_config):
        super(GeoplotlibApp, self).__init__(geoplotlib_config.screen_w, geoplotlib_config.screen_h,
                                            fullscreen=False, caption='geoplotlib')
        global SCREEN_W, SCREEN_H
        SCREEN_W = geoplotlib_config.screen_w
        SCREEN_H = geoplotlib_config.screen_h

        self.geoplotlib_config = geoplotlib_config

        self.ticks = 0
        self.ui_manager = UiManager()
        self.proj = Projector()
        self.map_layer = MapLayer(geoplotlib_config.tiles_provider, skipdl=False)

        self.scroll_delay = 0
github pyglet / pyglet / examples / multiple_windows.py View on Github external
glRectf(-1, -1, 1, 1)


r = 0


def update(dt):
    global r
    r += 1
    if r > 360:
        r = 0


pyglet.clock.schedule_interval(update, 1 / 20.)

w1 = pyglet.window.Window(200, 200, caption='First window', resizable=True)
w1.on_resize = on_resize
w1.on_draw = on_draw
w1.switch_to()
setup()

w2 = pyglet.window.Window(300, 300, caption='Second window', resizable=True)
w2.on_resize = on_resize
w2.on_draw = on_draw
w2.switch_to()
setup()

# On some platforms the actual framebuffer size is bigger than the window.
pixel_ratio = w1.get_pixel_ratio()

pyglet.app.run()
github furas / python-examples / pyglet / animated-background-with-suqares / main.py View on Github external
self.render()
        
    def render(self):
        self.all_sprites = []
        for y in range(1, 600, 50):
            for x in range(2, 800, 50):
                i = random.choice(self.all_images)
                s = pyglet.sprite.Sprite(i, x, y, batch=self.my_batch)
                self.all_sprites.append(s)  # <-- try without this line and you will no see image
        
    def draw(self):
        self.my_batch.draw()
            
# --- main ---
            
window = pyglet.window.Window(width=800, height=600)
#print(window.get_size())

island = Board()

@window.event()
def on_draw():
    window.clear()
    island.draw()
    
def update(dt):
    island.render()
    
pyglet.clock.schedule_interval(update, 0.1)

pyglet.app.run()
github tisnik / presentations / pyglet / 08_triangle.py View on Github external
#
# Demonstrační příklady využívající knihovnu Pyglet
#
# Příklad číslo 8: ukázka použití základních funkcí OpenGL
#                  vykreslení trojúhelníku vyplněného RGB gradientem
#
# ---------------------------------------------------------------------

# všechny třídy a funkce jsou obsaženy v jediném modulu nazvaném pyglet
import pyglet

# druhý import s funkcemi převzatými z OpenGL
from pyglet.gl import *

# vytvoření okna
window = pyglet.window.Window(width=640,
                              height=480,
                              caption="Pyglet+OpenGL")


@window.event
def on_draw():
    """Obsluha události - překreslení obsahu okna."""
    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    glBegin(GL_TRIANGLES)
    glColor3f(1, 0, 0)
    glVertex2f(window.width/2, 0)
    glColor3f(0, 1, 0)
    glVertex2f(0, window.height)
    glColor3f(0, 0, 1)
    glVertex2f(window.width, window.height)
github swiftcoder / simplui / simplui / dialogue.py View on Github external
def on_mouse_release(self, x, y, button, modifiers):
		if button == pyglet.window.mouse.LEFT and self._in_drag:
			self._in_drag = False
			return pyglet.event.EVENT_HANDLED
		
		SingleContainer.on_mouse_release(self, x, y, button, modifiers)
		return pyglet.event.EVENT_UNHANDLED