Ejemplo n.º 1
0
 def test_minimize_maximize(self):
     print(__doc__)
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height, resizable=True)
     w.push_handlers(self)
     while not w.has_exit:
         w.dispatch_events()
     w.close()
Ejemplo n.º 2
0
 def test_resize(self):
     w = window.Window(200, 200, resizable=True)
     w.push_handlers(self)
     while not w.has_exit:
         window_util.draw_client_border(w)
         w.flip()
         w.dispatch_events()
     w.close()
Ejemplo n.º 3
0
 def test_caption(self):
     print(__doc__)
     w1 = window.Window(400, 200, resizable=True)
     w2 = window.Window(400, 200, resizable=True)
     count = 1
     w1.set_caption('Window caption %d' % count)
     w2.set_caption('\u00bfHabla espa\u00f1ol?')
     last_time = time.time()
     while not (w1.has_exit or w2.has_exit):
         if time.time() - last_time > 1:
             count += 1
             w1.set_caption('Window caption %d' % count)
             last_time = time.time()
         w1.dispatch_events()
         w2.dispatch_events()
     w1.close()
     w2.close()
Ejemplo n.º 4
0
 def test_method(self):
     win = window.Window()
     win.push_handlers(self)
     self.check_sequence(0, 'begin')
     while not win.has_exit and not self.finished:
         win.dispatch_events()
         self.check_timeout()
     win.close()
Ejemplo n.º 5
0
 def test_set_exclusive_mouse(self):
     print(__doc__)
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height)
     w.push_handlers(self)
     while not w.has_exit:
         w.dispatch_events()
     w.close()
Ejemplo n.º 6
0
 def test_set_fullscreen(self):
     self.w = w = window.Window(200, 200)
     w.push_handlers(self)
     w.push_handlers(WindowEventLogger())
     self.on_expose()
     while not w.has_exit:
         w.dispatch_events()
     w.close()
Ejemplo n.º 7
0
 def test_initial_fullscreen(self):
     print(__doc__)
     self.w = window.Window(fullscreen=True)
     self.w.push_handlers(self)
     self.on_expose()
     while not self.w.has_exit:
         self.w.dispatch_events()
     self.w.close()
Ejemplo n.º 8
0
    def init(self, *args, **kwargs):
        """Initializes the Director creating the main window.
        Keyword arguments are passed to pyglet.window.Window().

        All the valid arguments can be found here:

            - http://www.pyglet.org/doc/1.1/api/pyglet.window.Window-class.html
        
        :rtype: pyglet.window.Window                    
        :returns: The main window, an instance of pyglet.window.Window class.
        """

        # pop out the Cocos-specific flag
        do_not_scale_window = kwargs.pop('do_not_scale', False)

        #: pyglet's window object
        self.window = window.Window(*args, **kwargs)

        #: whether or not the FPS are displayed
        self.show_FPS = False

        #: stack of scenes
        self.scene_stack = []

        #: scene that is being run
        self.scene = None

        #: this is the next scene that will be shown
        self.next_scene = None

        # save resolution and aspect for resize / fullscreen
        if do_not_scale_window:
            self.window.push_handlers(on_resize=self.unscaled_resize_window)
        else:
            self.window.push_handlers(on_resize=self.scaled_resize_window)
        self.window.push_handlers(self.on_draw)
        self._window_original_width = self.window.width
        self._window_original_height = self.window.height
        self._window_aspect = self.window.width / float(self.window.height)
        self._offset_x = 0
        self._offset_y = 0

        # opengl settings
        self.set_alpha_blending()

        # init fps
        self.fps_display = clock.ClockDisplay()

        # python interpreter
        self.python_interpreter = None

        #: whether or not to show the python interpreter
        self.show_interpreter = False

        # default handler
        self.window.push_handlers(DefaultHandler())

        return self.window
Ejemplo n.º 9
0
    def setup_pyglet(self):
        """Configure Pyglet attributes.

        """
        self.window = window.Window(visible=False,
                                    caption=CAPTION,
                                    fullscreen=config.fullscreen)
        clock.schedule_interval_soft(self.tick, 1.0 / TICK_RATE)
        clock.schedule_interval_soft(self.update, 1.0 / UPDATE_RATE)
Ejemplo n.º 10
0
            def test_1(self):
                w = window.Window(200, 200)
                w.switch_to()
                glClearColor(1, 0, 1, 1)
                glClear(GL_COLOR_BUFFER_BIT)
                w.flip()

                self.user_verify('Empty window')
                w.close()
 def test_set_size(self):
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height, resizable=True)
     w.push_handlers(self)
     while not w.has_exit:
         w.dispatch_events()
         window_util.draw_client_border(w)
         w.flip()
     w.close()
 def test_resizable(self):
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height, resizable=True)
     glClearColor(1, 1, 1, 1)
     while not w.has_exit:
         w.dispatch_events()
         window_util.draw_client_border(w)
         w.flip()
     w.close()
Ejemplo n.º 13
0
            def test_1(self):
                w = window.Window(200, 200)
                w.switch_to()
                glClearColor(1, 0, 1, 1)
                glClear(GL_COLOR_BUFFER_BIT)
                w.flip()

                self.user_verify('Please choose yes (or press Enter)')
                w.close()
Ejemplo n.º 14
0
 def test_set_visible(self):
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height)
     w.push_handlers(self)
     while not w.has_exit:
         glClear(GL_COLOR_BUFFER_BIT)
         w.dispatch_events()
         w.flip()
     w.close()
 def test_style_tool(self):
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height, 
                                style=window.Window.WINDOW_STYLE_TOOL)
     glClearColor(1, 1, 1, 1)
     while not w.has_exit:
         glClear(GL_COLOR_BUFFER_BIT)
         w.flip()
         w.dispatch_events()
     w.close()
 def test_set_icon(self):
     self.width, self.height = 200, 200
     self.w = w = window.Window(self.width, self.height)
     w.set_icon(image.load(icon_file))
     glClearColor(1, 1, 1, 1)
     while not w.has_exit:
         glClear(GL_COLOR_BUFFER_BIT)
         w.dispatch_events()
         w.flip()
     w.close()
Ejemplo n.º 17
0
    def __init__(self):
        self.world = World()
        self.win = window.Window(fullscreen=False, vsync=True, width=window_dimensions[0], height=window_dimensions[1])
        self.camera = Camera(self.win, zoom=200.0)
        self.hud = Hud(self.win)


        self.win.push_handlers(self.world.player.key_handler)

        clock.set_fps_limit(60)
 def test_method(self):
     win = window.Window(fullscreen=True)
     try:
         win.push_handlers(self)
         self.check_sequence(0, 'begin')
         while not win.has_exit and not self.finished:
             win.dispatch_events()
             self.check()
     finally:
         win.close()
Ejemplo n.º 19
0
 def __init__(self):
     seed(0)
     self.world = World()
     self.win = window.Window(fullscreen=True, vsync=True)
     self.camera = Camera(self.win, self.world, zoom=8)
     self.hud = Hud(self.win, self.world)
     # clock.set_fps_limit(30)
     glEnable(GL_BLEND)
     glDisable(GL_DEPTH_TEST)
     glClearColor(0, 0, 1, 1)
Ejemplo n.º 20
0
    def test_method(self):
        win = window.Window(visible=False)
        win.dispatch_events()
        win.push_handlers(self)

        win.set_visible(True)
        self.check_sequence(0, 'begin')
        while not win.has_exit and not self.finished:
            win.dispatch_events()
            self.check_timeout()
Ejemplo n.º 21
0
def test_context_noshare_texture():
    w1 = window.Window(200, 200)
    w1.switch_to()
    textures = c_uint()
    glGenTextures(1, byref(textures))
    texture = textures.value

    glBindTexture(GL_TEXTURE_2D, texture)
    data = (c_ubyte * 4)()
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 data)
    assert glIsTexture(texture)

    w2 = window.Window(200, 200, context=create_context(None))
    w2.switch_to()
    assert not glIsTexture(texture)

    w1.close()
    w2.close()
Ejemplo n.º 22
0
def main():
    worldMaxX = 640
    worldMaxY = 480
    win = window.Window(worldMaxX, worldMaxY, caption='Wyggles')
    #
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    #glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA)
    #glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    #
    # Set up rendering state for the offscreen buffer
    #glEnable(GL_DEPTH_TEST)
    #glDepthFunc(GL_LEQUAL)
    #glClearColor(0.0, 0.0, 0.2, 0.5)
    #glClearDepth(1.0)
    # Override default Escape key behaviour
    def on_key_press(symbol, modifiers):
        if symbol == key.ESCAPE:
            sys.exit()

    win.on_key_press = on_key_press
    #
    spawnWalls()
    root = spriteEngine.get_root()
    #line intersection isn't cutting it
    #spawnBoxes(root) ;
    spawnBalls(root)
    #spawnApple(root) ;
    spawnApple()
    spawnWyggles(root)
    intervalTime = 10
    imgName = "grass"
    imgSrc = data.filepath(imgName + ".png")
    element = image.load(imgSrc)

    def update(dt):
        #
        win.clear()
        #
        #element.blit(0, 0, 0)
        blitY = 0
        while (blitY < worldMaxY):
            blitX = 0
            while (blitX < worldMaxX):
                element.blit(blitX, blitY, 0)
                blitX = blitX + element.width
            blitY = blitY + element.height
        #
        spriteEngine.step(dt)
        win.flip()

    pyglet.clock.schedule_interval(update, .01)
    pyglet.app.run()
    '''
Ejemplo n.º 23
0
 def test_initial_fullscreen(self):
     self.w = window.Window(fullscreen=True)
     try:
         self.w.push_handlers(self)
         self.w.push_handlers(WindowEventLogger())
         self.on_expose()
         while not self.w.has_exit:
             self.w.dispatch_events()
     finally:
         self.w.close()
     self.user_verify('Pass test?', take_screenshot=False)
Ejemplo n.º 24
0
            def test_1(self):
                w = window.Window(200, 200)
                w.switch_to()
                glClearColor(1, 0, 1, 1)
                glClear(GL_COLOR_BUFFER_BIT)
                w.flip()

                try:
                    self.user_verify('Please select "n" and enter any reason')
                finally:
                    w.close()
 def test_activate(self):
     w = window.Window(200, 200)
     w.push_handlers(WindowEventLogger())
     last_time = time.time()
     while not w.has_exit:
         if time.time() - last_time > 5:
             w.activate()
             last_time = time.time()
             print 'Activated window.'
         w.dispatch_events()
     w.close()
Ejemplo n.º 26
0
 def test_activate(self):
     print(__doc__)
     w = window.Window(200, 200)
     last_time = time.time()
     while not w.has_exit:
         if time.time() - last_time > 5:
             w.activate()
             last_time = time.time()
             print('Activated window.')
         w.dispatch_events()
     w.close()
Ejemplo n.º 27
0
    def setup_pyglet(self):
        """Configure Pyglet attributes.

        """
        self.window = window.Window(visible=False,
                                    caption=CAPTION,
                                    fullscreen=config.fullscreen)
        clock.schedule_interval_soft(self.tick, 1.0 / TICK_RATE)
        clock.schedule_interval_soft(self.update, 1.0 / UPDATE_RATE)
        self.window.set_mouse_cursor(
            window.ImageMouseCursor(data.load_image("cursor.png"), 4, 60))
Ejemplo n.º 28
0
 def test_set_fullscreen(self):
     self.w = w = window.Window(200, 200)
     try:
         w.push_handlers(self)
         w.push_handlers(WindowEventLogger())
         self.on_expose()
         while not w.has_exit:
             w.dispatch_events()
     finally:
         w.close()
     self.user_verify('Pass test?', take_screenshot=False)
Ejemplo n.º 29
0
def main():
    import ctypes
    import time

    from pyglet import app, clock, font, gl, image, window

    from MusicDefs import MusicDefs

    #pic = PianoOctavePic(width=400, height=200)
    pic = HexagonalLayoutPic(D=100, scale=SCALE_MAJOR_DIATONIC, tonic=1, h=4)

    window = window.Window(width=pic.width, height=pic.height)
    #ft = font.load('Arial', 24)
    #text = font.Text(ft, 'Hello World')

    # create data shared by ImageSurface and Texture
    data = (ctypes.c_ubyte * (pic.width * pic.height * 4))()
    stride = pic.width * 4
    surface = cairo.ImageSurface.create_for_data(data, cairo.FORMAT_ARGB32,
                                                 pic.width, pic.height, stride)
    texture = image.Texture.create_for_size(gl.GL_TEXTURE_2D,
                                            pic.width * pic.height, gl.GL_RGBA)

    def update_surface(dt, surface):
        ctx = cairo.Context(surface)
        pic.draw_pic(ctx)

    @window.event
    def on_draw():
        window.clear()

        gl.glEnable(gl.GL_TEXTURE_2D)

        gl.glBindTexture(gl.GL_TEXTURE_2D, texture.id)
        gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, pic.width, pic.height,
                        0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, data)

        gl.glBegin(gl.GL_QUADS)
        gl.glTexCoord2f(0.0, 1.0)
        gl.glVertex2i(0, 0)
        gl.glTexCoord2f(1.0, 1.0)
        gl.glVertex2i(pic.width, 0)
        gl.glTexCoord2f(1.0, 0.0)
        gl.glVertex2i(pic.width, pic.height)
        gl.glTexCoord2f(0.0, 0.0)
        gl.glVertex2i(0, pic.height)
        gl.glEnd()

        #text.draw()

        #print('FPS: %f' % clock.get_fps())

    clock.schedule_interval(update_surface, 1 / 120.0, surface)
    app.run()
Ejemplo n.º 30
0
    def test_context_share_list(self):
        w1 = window.Window(200, 200)
        try:
            w1.switch_to()
            glist = glGenLists(1)
            glNewList(glist, GL_COMPILE)
            glLoadIdentity()
            glEndList()
            self.assertTrue(glIsList(glist))
        except:
            w1.close()
            raise

        w2 = window.Window(200, 200)
        try:
            w2.switch_to()
            self.assertTrue(glIsList(glist))
        finally:
            w1.close()
            w2.close()