adonthell-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-commits] CVS: adonthell/test guitest.py, NONE, 1.1 Makefile.a


From: VENNIN Joel <address@hidden>
Subject: [Adonthell-commits] CVS: adonthell/test guitest.py, NONE, 1.1 Makefile.am, 1.2, 1.3
Date: Mon, 28 Jul 2003 08:57:07 -0400

Update of /cvsroot/adonthell/adonthell/test
In directory subversions:/tmp/cvs-serv7241

Modified Files:
        Makefile.am 
Added Files:
        guitest.py 
Log Message:
Add an example how to use gui


--- NEW FILE ---
from adonthell import gfx, input, gui
import sys, time

## Our exit variable
letsexit = 0

def handle_keys (ev):
    global letsexit
    if ev.type() == input.keyboard_event.KEY_PUSHED:
        if ev.key() == input.keyboard_event.ESCAPE_KEY:
            letsexit = 1
            print "Escape pressed, leaving..."
if __name__ == '__main__':
    ## Initialize the gfx and input systems
    if not gfx.init("sdl"): raise "Can't load gfx backend!"
    if not input.init("sdl"): raise "Can't load input backend!"
    
    ## Set us a nice window
    gfx.screen.set_video_mode(640, 480)

    ## Create our input_listener and connect the callback
    ## to handle keyboard events
    il = input.listener()
    il.connect_keyboard_function(handle_keys)

    ## Add the listener to the manager
    input.manager.add(il)

    ## gui stuff
    cont = gui.container ()
    cont.setSize (50, 50)
    cont.setLocation (20, 30)

    a = gui.base ()
    a.setSize (40,20)
    a.setLocation (30, 10)

    cont.addChild (a)

    ## Run this loop until letsexit is set to 1 by the
    ## callback function. Every time a key event is raised,
    ## the input manager will send it to the listeners it handles
    ## (that is, only the one we've connected) which will call the
    ## callback function that has been connected to handle keyboard events.
    while not letsexit:
        gfx.screen.update ()
        input.manager.update()
        #gfx.screen.draw ()
        cont.update ()
        cont.draw ()
        
    ## Do some cleanup, and we're ready to exit!
    input.cleanup()
    gfx.cleanup()

    sys.exit(0)

Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/test/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Makefile.am 27 Jul 2003 14:08:20 -0000      1.2
--- Makefile.am 28 Jul 2003 12:57:05 -0000      1.3
***************
*** 1,5 ****
  CXXFLAGS += -I$(top_srcdir)/src/
  
! EXTRA_DIST = gfxtest.py inputtest.py
  noinst_PROGRAMS = callbacktest inputtest
  
--- 1,5 ----
  CXXFLAGS += -I$(top_srcdir)/src/
  
! EXTRA_DIST = gfxtest.py inputtest.py guitest.py
  noinst_PROGRAMS = callbacktest inputtest
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]