Emmanuel GARCIA
2010-11-20 18:09:58 UTC
Hello,
I'm trying to build a 3D application with a 3D viewport and some GUI elements around it (buttons, scrollbars, etc).
I process viewport events in the begin_round() method of a soya.Body object.
It turns out that events that have been captured or that should have been captured by GUI elements, are not removed from the event queue, and are then processed also by the 3D viewport.
Below is a simplified code showing the problem: when I click on the GUI button or on the GUI window, the event is not consumed, contrary to what I expected, and is "propagated" to the 3D viewport which has an exit() handler.
I tried to achieve my goal using the widget and pudding packages but to no avail.
Can anyone help me?
Thanks,
Emmanuel
import sys, os, soya, soya.gui
soya.init()
class Controller(soya.Body):
def __init__(self, parent):
soya.Body.__init__(self, parent)
def begin_round(self):
soya.Body.begin_round(self)
for event in soya.MAIN_LOOP.events:
print event
if event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
sys.exit()
scene = soya.World(None)
camera = soya.Camera(scene)
Controller(scene)
root = soya.gui.RootLayer(None)
root.add(soya.gui.CameraViewport(root, camera))
root.add(soya.gui.Button())
root.add(soya.gui.Window())
soya.set_root_widget(root)
soya.MainLoop(scene).main_loop()
I'm trying to build a 3D application with a 3D viewport and some GUI elements around it (buttons, scrollbars, etc).
I process viewport events in the begin_round() method of a soya.Body object.
It turns out that events that have been captured or that should have been captured by GUI elements, are not removed from the event queue, and are then processed also by the 3D viewport.
Below is a simplified code showing the problem: when I click on the GUI button or on the GUI window, the event is not consumed, contrary to what I expected, and is "propagated" to the 3D viewport which has an exit() handler.
I tried to achieve my goal using the widget and pudding packages but to no avail.
Can anyone help me?
Thanks,
Emmanuel
import sys, os, soya, soya.gui
soya.init()
class Controller(soya.Body):
def __init__(self, parent):
soya.Body.__init__(self, parent)
def begin_round(self):
soya.Body.begin_round(self)
for event in soya.MAIN_LOOP.events:
print event
if event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
sys.exit()
scene = soya.World(None)
camera = soya.Camera(scene)
Controller(scene)
root = soya.gui.RootLayer(None)
root.add(soya.gui.CameraViewport(root, camera))
root.add(soya.gui.Button())
root.add(soya.gui.Window())
soya.set_root_widget(root)
soya.MainLoop(scene).main_loop()