示例#1
0
	def OnInit( self ):
		
		self.drawCapture = 0
		self.capturedImage = ()
		self.useStringDraw = 0
		self.reverseShape = 0
		self.capturedImageFormat = GL_RGB
		
		self.planRot = 0;
		self.frameIter = 0;
		
		self.iter = 0
		self.strPos = 0
		self.newSystemTime = 45
		self.systemIterator = 0
		self.uniqueIDs = []
		
		self.whichSTR = 0
		

		glutReshapeWindow( 1400, 850)
		glutPositionWindow( 0, 0 )
		glutFullScreen( )
		
		self.time = Timer( duration = 60.0, repeating = 1 )
		self.time.addEventHandler( "fraction", self.OnTimerFraction )
		self.time.register (self)
		self.time.start ()
		
		#self.updater = Timer(duration = 61, repeating = 1)
		#self.updater.addEventHandler("cycle", self.updateFromSQL )
		#self.updater.register(self)
		#self.updater.start ()
		
		
		self.rot = 0
		
		self.offset = 3
		
		#dragging flag
		self.startDrag = 0
		
		#holder for last detail rendered planet
		self.lastDetail = ()
		
		
		#make some random planets and systems
		#self.universe = universe.Universe()
		
		self.addEventHandler( 'keypress', name='s', function=self.OnSave )
		
		#get fonts
		providers = fontprovider.getProviders( 'solid' )
		if not providers:
			raise ImportError( """NONONO solid font providers registered! Demo won't function properly!""" )
		registry = self.getTTFFiles()
		styles = []
		for font in registry.familyMembers( 'SANS' ):
			names = registry.fontMembers( font, 400, 0)
			for name in names:
				styles.append( fontstyle3d.FontStyle3D(
					family = [name],
					size = .06,
					justify = "LEFT",
					thickness = .02,
					quality = 3,
					renderSides = 1,
					renderFront = 1,
					renderBack = 1,
				))
		self.styles = styles
		
		#render all ascii
		self.ascii = []
		asciiNum = 32
		while asciiNum<128:
			self.ascii.append( basenodes.Text( fontStyle=self.styles[0], string=chr(asciiNum) ) )
			asciiNum += 1
						
				
		####	Starting SQL Integration Here
		self.universe = universe.Universe()
		numSys = 1
		self.universe.addSys(self.systemIterator)
		
		conn = MySQLdb.connect( host = "ec2-75-101-245-127.compute-1.amazonaws.com",
								user = "******",
								passwd = "ohhai",
								db = "wikihole")
		self.stringArray = []
		cursor = conn.cursor()
		cursor.execute( "SELECT * FROM history")
		self.planetMoons = list();
		offsetset = 0
		while (1):
			row = cursor.fetchone()
			if row == None:
				break
			print "%s\t%s\t%s" % (row[0], row[2], row[1])	
			if(not offsetset):
				self.offset = row[0]
				offsetset = 1
				lastTime = "%s" % row[2]
				thisTime = "%s" % row[2]
			else:
				lastTime = thisTime
				thisTime = "%s" % row[2]
			
			if( not gethistory.timeDiff(lastTime, thisTime, self.newSystemTime) ):
				self.systemIterator = self.systemIterator + 1
				self.universe.addSys(self.systemIterator)
				print "MADE NEW SYSTEM"
				#print lastTime
				#print thisTime
			
			url = row[1]
			
			self.uniqueIDs.append(row[0])
			
			imageurls = gethistory.getImageUrls(url)
			
			
			#make geometry array for description
			geom = []
			gNum = 0
			descripStr = gethistory.getDescription(url)
			
			while gNum<200:
				strr = descripStr[ gNum ]  #self.bigString[ gNum ] 
				asciiNumber = ord( strr )-32
				if( not asciiNumber>=0 or not asciiNumber<=95 ):
					asciiNumber = 0
					print "OUTOFBOUNDS"
				geom.append( self.ascii[ asciiNumber ] )
				gNum += 1
				
			if( self.whichSTR == 0):
				self.whichSTR = 1
			else:
				self.whichSTR = 0
				
			print self.whichSTR
							
				
			#render font geom for title
			names = url.split('/')
			wikititle = names[len(names) - 1]
			wikititle = wikititle.replace('_', ' ')
			self.stringArray.append(wikititle)
			title = basenodes.Text( fontStyle=self.styles[0], string=wikititle )
			
			#get list of image urls for planet moons
			fileList = list()
			for image in imageurls:
				linetoExec = "wget " + image

				fullpath = image.split('/')
				existsOrNot =  os.path.exists( fullpath[len(fullpath) - 1] )
				if(existsOrNot):
					fileList.append( fullpath[len(fullpath) - 1] )
				else:
					fileList.append( fullpath[len(fullpath) - 1] )
					os.system(linetoExec)  #uncomment this before real runs
			#self.planetMoons.append(fileList)
			
			####
			#FINALLY add the planet to the current solar system
			self.universe.addPlanet(row[0], len(imageurls), title, geom, fileList)
					

						
		"""Setup callbacks and build geometry for rendering"""
		#on mouse down
		self.addEventHandler( "mousebutton", button = 0, state=1, function = self.mouseDown )
		#on mouse up
		self.addEventHandler( "mousebutton", button = 0, state = 0, function = self.mouseUp )
				
		glutinteractivecontext.GLUTInteractiveContext.setupDefaultEventCallbacks(self)
		
		self.initialPosition = ( 0,0,20 )
		self.STEPDISTANCE = 5.0
		self.newPos = self.initialPosition
		self.goTo = 0
示例#2
0
	def updateFromSQL(self):
		print "ACTUALLY CALLED updateFromSQL!!! wohoo!!!\n"
		largestRecord = -12
		for ident in self.uniqueIDs:
			if(ident > largestRecord):
				largestRecord = ident
		
		
		conn = MySQLdb.connect( host = "ec2-75-101-245-127.compute-1.amazonaws.com",
								user = "******",
								passwd = "ohhai",
								db = "wikihole")
								
		cursor = conn.cursor()
		cursor.execute("SELECT * FROM history WHERE id = %d" % largestRecord)
		row = cursor.fetchone()
		lastHighest = "%s" % row[2]
		

		
		
		cursor = conn.cursor()
		cursor.execute( "SELECT * FROM history WHERE id > %d" % largestRecord)
		
		print "checking for records larger than %d" % largestRecord
		first = 1
		while (1):
			row = cursor.fetchone()
			if row == None:
				break
			print "%s\t%s\t%s" % (row[0], row[2], row[1])	
			if(first):
				lastTime = lastHighest
				thisTime = "%s" % row[2]
				first = 0
			else:
				lastTime = thisTime
				thisTime = "%s" % row[2]

			if( not gethistory.timeDiff(lastTime, thisTime, self.newSystemTime) ):
				self.systemIterator = self.systemIterator + 1
				self.universe.addSys(self.systemIterator)
				print "MADE NEW SYSTEM"
				#print lastTime
				#print thisTime
			url = row[1]
			self.uniqueIDs.append(row[0])
			imageurls = gethistory.getImageUrls(url)

			#render font geom for title
			names = url.split('/')
			wikititle = names[len(names) - 1]
			wikititle = wikititle.replace('_', ' ')
			self.stringArray.append(wikititle)
			title = basenodes.Text( fontStyle=self.styles[0], string=wikititle )

			#make geometry array for description
			geom = []
			gNum = 0
			descripStr = gethistory.getDescription(url)
			
			while gNum<200:
				strr = descripStr[ gNum ]  #self.bigString[ gNum ] 
				asciiNumber = ord( strr )-32
				if( not asciiNumber>=0 or not asciiNumber<=95 ):
					asciiNumber = 0
					print "OUTOFBOUNDS"
				geom.append( self.ascii[ asciiNumber ] )
				gNum += 1

			fileList = list()
			#do this stuff in a thread
			for image in imageurls:
				linetoExec = "wget " + image
				fullpath = image.split('/')
				fileList.append( fullpath[len(fullpath) - 1] )
				os.system(linetoExec)  #uncomment this before real runs
				
				self.planetMoons.append(fileList)

			#self.universe.addPlanet(row[0], len(imageurls))
			self.universe.addPlanet(row[0], len(imageurls), title, geom, fileList)
			names = url.split('/')
			wikititle = names[len(names) - 1]
			wikititle = wikititle.replace('_', ' ')
			self.stringArray.append(wikititle)