2 # this has some dom related functions
9 from OpenGL
.GL
import *
11 from OpenGL
.GLU
import *
19 def parseLevel(level
):
20 parsed_stuff
= [[], {}]
22 if level
.hasAttributes():
23 for i
in range(len(level
.attributes
)):
25 attrname
= level
.attributes
.item(i
).name
.encode()
27 parsed_stuff
[1][attrname
] = level
.attributes
.item(1).value
.encode()
29 if len(level
.childNodes
) == 1 and level
.childNodes
[0].nodeType
== 3:
31 parsed_stuff
[0] = level
.childNodes
[0].nodeValue
.encode()
37 for node
in level
.childNodes
:
38 if node
.nodeType
== 1:
40 name
, contents
= parseLevel(node
)
41 parsed_stuff
[0].append([name
, contents
])
43 return level
.nodeName
.encode(), parsed_stuff
45 results
= parseLevel(dom
.childNodes
[0])
49 def reduceConfig(config
):
53 for item
in config
[1][0]:
54 results
[item
[0]] = item
[1][0]
58 def reduceObjectDef(file):
62 for item
in file[1][0]:
64 results
[item
[0]] = item
[1][0]
68 def reduceMenuDef(file):
74 for item
in file[1][0]:
79 if item
[0] == 'script':
82 if item
[0] != 'script' and item
[0] != 'name':
84 temp
['contents'] = item
[1][0]
85 temp
['type'] = item
[0]
86 elements
[temp
['id']] = temp
88 return name
, script
, elements
90 def reduceInstance(item
):
95 results
['contents'] = item
[1][0]
105 if e
.type == ACTIVEEVENT
:
106 data
['gain'] = e
.gain
107 data
['state'] = e
.state
109 if e
.type == KEYDOWN
:
110 data
['unicode'] = e
.unicode
118 if e
.type == MOUSEMOTION
:
121 data
['buttons'] = e
.buttons
123 if e
.type == MOUSEBUTTONUP
:
125 data
['button'] = e
.button
127 if e
.type == MOUSEBUTTONDOWN
:
129 data
['button'] = e
.button
131 if e
.type == JOYAXISMOTION
:
133 data
['axis'] = e
.axis
134 data
['value'] = e
.value
136 if e
.type == JOYBALLMOTION
:
138 data
['ball'] = e
.ball
141 if e
.type == JOYHATMOTION
:
144 data
['value'] = e
.value
146 if e
.type == JOYBUTTONUP
:
148 data
['button'] = e
.button
150 if e
.type == JOYBUTTONDOWN
:
152 data
['button'] = e
.button
154 if e
.type == VIDEORESIZE
:
155 data
['size'] = e
.size
159 if e
.type == VIDEOEXPOSE
:
162 if e
.type == USEREVENT
:
163 data
['code'] = e
.code
167 if e
.type == QUIT
: type = "QUIT"
168 if e
.type == ACTIVEEVENT
: type = "ACTIVEEVENT"
169 if e
.type == KEYDOWN
: type = "KEYDOWN"
170 if e
.type == KEYUP
: type = "KEYUP"
171 if e
.type == MOUSEMOTION
: type = "MOUSEMOTION"
172 if e
.type == MOUSEBUTTONUP
: type = "MOUSEBUTTONUP"
173 if e
.type == MOUSEBUTTONDOWN
: type = "MOUSEBUTTONDOWN"
174 if e
.type == JOYAXISMOTION
: type = "JOYAXISMOTION"
175 if e
.type == JOYBALLMOTION
: type = "JOYBALLMOTION"
176 if e
.type == JOYHATMOTION
: type = "JOYHATMOTION"
177 if e
.type == JOYBUTTONUP
: type = "JOYBUTTONUP"
178 if e
.type == JOYBUTTONDOWN
: type = "JOYBUTTONDOWN"
179 if e
.type == VIDEORESIZE
: type = "VIDEORESIZE"
180 if e
.type == VIDEOEXPOSE
: type = "VIDEOEXPOSE"
181 if e
.type == USEREVENT
: type = "USEREVENT"
186 glBegin(GL_TRIANGLES
)
188 glColor3f(1.0,0.0,0.0)
189 glVertex3f( 0.0, 1.0, 0.0)
190 glColor3f(0.0,1.0,0.0)
191 glVertex3f(-1.0,-1.0, 1.0)
192 glColor3f(0.0,0.0,1.0)
193 glVertex3f( 1.0,-1.0, 1.0)
195 glColor3f(1.0,0.0,0.0)
196 glVertex3f( 0.0, 1.0, 0.0)
197 glColor3f(0.0,0.0,1.0)
198 glVertex3f( 1.0,-1.0, 1.0)
199 glColor3f(0.0,1.0,0.0)
200 glVertex3f( 1.0,-1.0, -1.0)
202 glColor3f(1.0,0.0,0.0)
203 glVertex3f( 0.0, 1.0, 0.0)
204 glColor3f(0.0,1.0,0.0)
205 glVertex3f( 1.0,-1.0, -1.0)
206 glColor3f(0.0,0.0,1.0)
207 glVertex3f(-1.0,-1.0, -1.0)
210 glColor3f(1.0,0.0,0.0)
211 glVertex3f( 0.0, 1.0, 0.0)
212 glColor3f(0.0,0.0,1.0)
213 glVertex3f(-1.0,-1.0,-1.0)
214 glColor3f(0.0,1.0,0.0)
215 glVertex3f(-1.0,-1.0, 1.0)