/[gzz]/gzz/gfx/util/disp.py
ViewVC logotype

Diff of /gzz/gfx/util/disp.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by jvk, Tue Mar 4 09:28:19 2003 UTC revision 1.5 by jvk, Tue Mar 4 11:10:25 2003 UTC
# Line 55  def filescene(vs, file): Line 55  def filescene(vs, file):
55    
56      a = float(xs) / ys      a = float(xs) / ys
57      s,t = xt,yt      s,t = xt,yt
     print texid  
58      code = """      code = """
59      PushAttrib ENABLE_BIT      PushAttrib ENABLE_BIT
60      BindTexture TEXTURE_2D %(texid)s      BindTexture TEXTURE_2D %(texid)s
# Line 78  def filescene(vs, file): Line 77  def filescene(vs, file):
77      End      End
78      PopAttrib      PopAttrib
79      """ % locals()      """ % locals()
80      print code      #print code
81      l = getDList(code)      l = getDList(code)
82            
83      vs.put(background((.36, .84, 1.0)))      vs.put(background((.36, .84, 1.0)))
84      cs = vs.affineCS(0, "foo", 0, 0, 0, ys, 0, 0, ys)      cs = vs.affineCS(0, "foo", 0, 0, 0, ys, 0, 0, ys)
85      vs.map.put(l, cs)      vs.map.put(l, cs)
86    
87    
88    keys = []
89    starttime = 0
90    mintime = 0
91    toid = 0
92    
93  class Bindings(AbstractBinder):  class Bindings(AbstractBinder):
94      def keystroke(self, s):      def keystroke(self, key):
95          print "KEY: '%s'"%s          time = System.currentTimeMillis()
96            if time - starttime >= mintime:
97                if key in keys:
98                    endTrial(time - starttime, key)
99                    
100            print "KEY: '%s'"%key
101    
102      def mouse(self, e):      def mouse(self, e):
103          print "MOUSE: '%s'"%e          print "MOUSE: '%s'"%e
104            
105      def timeout(self, o):      def timeout(self, o):
106          print str(System.currentTimeMillis()) + " TIMEOUT ",o          time = System.currentTimeMillis()
107            if o == toid:
108                endTrial(time - starttime, "TIMEOUT")
109            print str(time) + " TIMEOUT ",o
110    
111    
112    trials = []
113    
114    def nextTrial():
115        global trials
116        if len(trials) == 0:
117            return 0
118    
119        trial = trials.pop(0)
120        print "Starting trial:", trial
121        
122        global keys, mintime
123        keys = trial["keys"]
124        mintime = trial["min"]
125    
126        vs = w.createVobScene()
127        filescene(vs, trial["file"])
128        w.renderStill(vs, 0)
129        global starttime
130        starttime = System.currentTimeMillis()
131    
132        print "Start time", starttime
133        global toid
134        if trial["max"] > 0:
135            toid += 1
136            print "Scheduling timeout", toid, "at", trial["max"], "ms"
137            w.addTimeout(trial["max"], toid)
138        
139        return 1
140    
141    def endTrial(time, key):
142        global toid
143        toid += 1
144    
145        print "Trial ended:", time, key
146    
147        if not nextTrial():
148            print "End of exper"
149    
150  class Main(Runnable):  class Main(Runnable):
151    
152      def run(self):      def run(self):
153            global w
154          w = gfxapi.createWindow()          w = gfxapi.createWindow()
155          w.setLocation(0,0,xs,ys)          w.setLocation(0,0,xs,ys)
156          w.registerBinder(Bindings())          w.registerBinder(Bindings())
157    
158            print "Reading trials"
159            global trials
160            trials = []
161          f = open(sys.argv[1], "r")          f = open(sys.argv[1], "r")
162          lines = f.readlines()          while 1:
163          f.close()              line = f.readline()
164                if line == "": break
         for line in lines:  
165              fields = line.split()              fields = line.split()
166                desc = f.readline()
167                
168                trials.append( { "desc" : desc,
169                                 "file" : fields[0],
170                                 "min" : int(fields[1]),
171                                 "max" : int(fields[2]),
172                                 "keys" : fields[3:],
173                                 } )
174            f.close()
175            print "Read", len(trials), "trials"
176    
177              file = fields[0]          # Start
178              vs = w.createVobScene()          nextTrial()
             filescene(vs, file)  
             w.renderStill(vs, 0)  
179                    
180    
181  gfxapi = GraphicsAPI.getInstance()  gfxapi = GraphicsAPI.getInstance()

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26