So I’m printing an array of strings in a circle and Ideally I’d like to click on them so I can do further action. However the setPos() doesn’t seem to set the text where it should. If it did I would just find the area I can click on using the intial setPos coordinantes and string size to determine if I clicked on the string or not. However its not placing the strings in the desired location. Any thoughts why that might be?
from direct.showbase.ShowBase import ShowBase
from direct.showbase.DirectObject import DirectObject
from direct.showbase import DirectObject
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *
from panda3d.core import lookAt
import urllib2
from bs4 import BeautifulSoup
import numpy as np
import sys
import os
import math
Tag = np.empty((25), dtype=object)
cos=math.cos
sin=math.sin
pi=math.pi
from direct.gui.OnscreenText import OnscreenText
from pandac.PandaModules import TextNode
def createText(n,Max,string):
r=.9
x=cos((2*pi*n)/Max)*r
y=sin((2*pi*n)/Max)*r
#textObject = OnscreenText(text = string, pos = (x, y,0), scale = 0.04)
text = TextNode('DebugConsole')
text.setText(string)
textNodePath = aspect2d.attachNewNode(text)
textNodePath.setScale(0.045)
textNodePath.setPos(x,0,y)
text.setFrameColor(1,1,1,1)
text.setFrameAsMargin(.2,.2,.2,.2)
#text.setCardColor(1, .01, 0.01, .01)
#text.setCardAsMargin(1, 1, 1, 1)
#text.setCardDecal(True)
class Click(DirectObject.DirectObject):
def __init__(self):
self.accept('mouse1',self.Pos)
def Pos(self):
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
print x
print y
#ans = raw_input('Start Search: ')
Search = "Cars"
#Search=ans.replace(" ","_")
base = ShowBase()
base.setBackgroundColor(0, 0, 250)
base.disableMouse()
base.camera.setPos(0, 0, 4)
base.camera.lookAt( 0, 0, 0 )
tag=np.empty((150),dtype=object)
tags=np.empty((150),dtype=object)
etf_page = "https://en.wikipedia.org/wiki/"+Search
url = etf_page
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content,"lxml")
#l=len(soup.findAll("p"))
para=soup.findAll("p")
e=0
h=0
t=0
max=20
for n in range(0,10):
try:
l=para[n].findAll('a')
for link in l:
title= link.get('title')
#print title
if title:
if "Help" in title:
h=h+1
else:
tags[t]=title
t=t+1
if t==max:
n=10
except:
e=e+1
for a in range(0,max):
tag[a]=tags[a].replace(" ","_")
numN=max
for i in range (0,numN):
createText(i,numN,tags[i])
Click()
base.run()