From: Young-Jin L. <yl...@ui...> - 2002-01-08 21:26:50
|
Hi, I was looking for some help for the problem I got while I was trying to extend VPython little bit. I wanted to assign some properties on the VPython object. For instance, I want to give a VPython sphere object a particular name. By assigning a unique name on the VPython object, I will be able to do bookkeeping them using a dictionary. Here is what I tried. from visual import * class Ball: def __init__( self, name, color ): self.sphere = sphere( color = color ) self.name = name; def clickOn( self ): print self.name scene.range = 4 components = {} ball1 = Ball( "Ball 1", (0, 1, 0) ) components[ ball1.sphere ] = ball1 while 1: if scene.mouse.clicked: m = scene.mouse.getclick() #scene.mouse.pick.color = (0, 0, 1) global components b = components.get( scene.mouse.pick ) if b: print "1" print b.clickOn() print "2" loc = m.pos #print loc sphere( pos = loc, radius = 0.1, color = (1,0,0) ) I created one sphere object and assigned the only property, the name, and put it into the global dictionary. Then when I get a mouse click, I examined the clicked object, checked the global dictionary, and if it is the case, print out the name of it. When I ran this test script, I expected to get "1\nBall 1\n2", but I got "1\nBall 1\nNone\n2". I have no idea where "None" came from. Is there anybody who can help me with this problem? Is this the right way of extending VPython? Any comment on any of above questions will be greatly appreciated. TIA. YJ |