PDA

View Full Version : wxPython and Flock of Birds


Atul Thakur
01-14-2008, 02:27 PM
Hi:
Encountered another problem where I am trying to embed my script in wx and use the flock of birds. My script just hangs without throwing any error. Kindly point me to any example of such type. I searched but could not find.
regards,
-Atul
import viz, wx

viz.go(viz.EMBEDDED|viz.TRACKER)

class VizFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Virtual Training Studio - Training Module", size=(800,600),style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)

window = wx.Window(self,-1)

#IMPORTANT: YOU MUST SET THE WINDOW BEFORE RUNNING ANY OTHER VIZ COMMANDS
viz.setwindow(window.GetHandle())

print "window setting"

#IMPORTANT: SETUP A TIMER TO BE CALLED CONTINUOSLY, IN THIS CASE, EVERY 10 MILLISECONDS
self.timer = wx.Timer(self, 5000)
self.timer.Start(10)
#self.Bind(wx.EVT_TIMER, self.OnTimer)
wx.EVT_TIMER(self, 5000, self.OnTimer)


def OnTimer(self, event):
#IMPORTANT: YOU MUST MANUALLY UPDATE THE GRAPHICS FRAME
viz.updateframe()

def Quit(self):
self.timer.Stop()
self.Close()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = VizFrame(None)
frame.Show(True)
pos = [0,0,0]

room = viz.add("room.wrl")
room.translate(0,0,3)

table = viz.add("table.wrl")
table.translate(0,0,3)

def onkeydown(key):
if key == 'a':
pos = sensor_obj.get(viz.EULER, viz.ABSOLUTE_WORLD)
print pos
viz.callback(viz.KEYDOWN_EVENT,onkeydown)

PORT_FOB = 1
BAUD_FOB = 115200
sensor = viz.add('flockofbirds.dls')
sensor.reset()
sensor_obj = viz.add(viz.GROUP)
sensor_obj.link(sensor)
viz.tracker()
app.MainLoop()

farshizzo
01-16-2008, 10:32 AM
I ran your code and it didn't hang. What line of code is the script hanging on?

Atul Thakur
01-16-2008, 11:36 AM
I ran your code and it didn't hang. What line of code is the script hanging on?
The code run fine if I comment out the fob invocation lines (PORT_FOB = 1 onwards till viz.tracker()).
But the code I posted hangs otherwise for me. On the Vizard output console I get
************************************************** ****************************
* VIZARD 2.53g *
* *
************************************************** ****************************

Loading File: room.wrl
Scaling image 'eastwall.jpg' from (1200,512) to (1024,512)
Loading File: table.wrl

And a gray window (not responding) pops up with hourglass cursor.

Actually, I am using FOB in a larger code and I figured out that this part is giving problem.

regards,
-Atul

Atul Thakur
01-16-2008, 11:58 AM
To be precise the code hangs on flg line
sensor = viz.add('flockofbirds.dls')

The flock is working fine otherwise on vizard (i.e.with other codes without wx)

-Atul