![]()  | 
	
| 
		 
			 
			#1  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
				
				Event handling
			 
			
			
			I am having a problem regarding event handling, and I haven't yet been able to figure out the cause of the problem.  Any assistance you could provide in this regard would be greatly appreciated.  
		
		
		
		
		
		
		
		
	
	I created a PlaceMarkerEvt class to handle mouse click events, which allows users to create three points in a given map environment (and a fourth click removes all created points). The application allows users to change the map environment by typing on the keyboard, and each map environment utilizes the PlaceMarkerEvt class. The problem is that the PlaceMarkerEvt class works without flawlessly in the initial map environment; however, when the map environment is changed, it no longer works the way it is supposed to work. Output: # Initial map environment 1: [-21.214298248291016, 13.693742752075195, 96.99993896484375, '2013-03-28 10:59:15.947000'] 2: [27.049070358276367, -7.507974147796631, 95.81939697265625, '2013-03-28 10:59:16.397000'] 3: [-22.711130142211914, -32.831119537353516, 91.01387786865234, '2013-03-28 10:59:16.847000'] 4: Remove points removeShapes() - POINTS REMOVED # Map environment is changed -- duplicates coordinates recordings and does not remove points 1: [-31.70626449584961, 2.459872245788574, 94.83840942382812, '2013-03-28 10:59:20.997000'] 1: [-31.70626449584961, 2.459872245788574, 94.83840942382812, '2013-03-28 10:59:20.998000'] 2: [7.19222354888916, -4.607730865478516, 99.53379821777344, '2013-03-28 10:59:21.381000'] 2: [7.19222354888916, -4.607730865478516, 99.53379821777344, '2013-03-28 10:59:21.382000'] 3: [-2.733815908432007, -18.645051956176758, 97.84542846679688, '2013-03-28 10:59:21.814000'] 3: [-2.733815908432007, -18.645051956176758, 97.84542846679688, '2013-03-28 10:59:21.815000'] 4: Remove points removeShapes() - POINTS REMOVED 4: Remove points removeShapes() - POINTS REMOVED Code: 
	import viz
import vizmat
import vizshape
import datetime
class PlaceMarkerEvt(viz.EventClass):
	
	def __init__(self,locMarker):
		
		viz.EventClass.__init__(self)
		
		self.count = 1  # Mouse click count
		
		self.callback(viz.MOUSEDOWN_EVENT, self.placeMarker)
		
		self.locMarker = locMarker
		
	def placeMarker(self, w):
		
		global shape1, shape2, shape3
		
		if self.count < 4:
			
			line = viz.MainWindow.screenToWorld(viz.mouse.getPosition())
			pos = vizmat.MoveAlongVector(line.begin,line.dir,100)
						
			coor = [] # Create list for xyz coordinate
			
			if self.count == 1:  # First mouse click
				shape1 = vizshape.addCircle()
				shape1.color(viz.RED)
				shape1.billboard()
				shape1.setPosition(pos)
				coor = shape1.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			elif self.count == 2: #Second mouse click
				shape2 = vizshape.addCircle()
				shape2.color(viz.GREEN)
				shape2.billboard()
				shape2.setPosition(pos)
				coor = shape2.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			elif self.count ==3: #Third mouse click
				shape3 = vizshape.addCircle()
				shape3.color(viz.BLUE)
				shape3.billboard()
				shape3.setPosition(pos)
				coor = shape3.getPosition()
				coor.append(str(datetime.datetime.now()))
								
			print str(self.count) + ": " + str (coor)
			
			self.count += 1 # Update count
			
		else: # Fourth mouse click
			print str(self.count) + ": Remove points"
			self.removeShapes()
	
	def removeShapes(self):
		shape1.remove()
		shape2.remove()
		shape3.remove()
		print "removeShapes() - POINTS REMOVED"
		# Reset count
		self.count = 1
		
if __name__ == '__main__':	
	
	viz.setMultiSample(4)
	viz.fov(60)
	viz.go()
	
	mapEnvList = []
	gDome = 0
	
	mapEnvList.append(viz.add(viz.ENVIRONMENT_MAP,'gpo_L.jpg'))
	mapEnvList.append(viz.add(viz.ENVIRONMENT_MAP,'th_L.jpg'))
	
	def selectEnvironment(index):
		
		if index in [1, 2]:
			gDome.texture(mapEnvList[index-1])
			env = mapEnvList[index-1]
		PlaceMarkerEvt(env)
	
	gDome = viz.add('skydome.dlc',0,'',0,0,0,0,viz.WORLD)
	
	vizact.onkeydown('1', selectEnvironment, 1)
	vizact.onkeydown('2', selectEnvironment, 2)
	
	selectEnvironment(1)
	
	viz.link( viz.Mouse , viz.addTexQuad(viz.SCREEN,texture=viz.add('crosshair.png')) )
	viz.mouse.setVisible(viz.OFF)
	import vizcam
	vizcam.PanoramaNavigate()
 | 
		
  | 
	
		
  | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Mouse event: how to detect no mouse move event, how to set mouse position? | Zhi | Vizard | 3 | 04-11-2011 07:25 PM | 
| how to cancel event? | shahramy | Vizard | 1 | 12-20-2010 09:52 AM | 
| Distance or position based event? | vissimutah | Vizard | 1 | 08-25-2009 01:26 PM | 
| event detection and handling | Chandan | Vizard | 1 | 10-13-2006 05:01 PM | 
| sending event markers to a monitoring computer | mikestatic | Vizard | 3 | 01-26-2006 10:23 AM |