PGitems and mouse events

Hi,
I am currently trying to get an understanding of the PGitems in Panda, and I am stuck on the mouse event detection.
Here’s the code :

#! /usr/bin/python
# -*- coding:utf-8 -*-

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.task import Task


myPGItem		= PGItem('myPGItem')
myPGItem		. setFrame(-0.5, 0.5, -0.5, 0.5)

myFrameStyle	= PGFrameStyle()
myFrameStyle	. setType(PGFrameStyle.TFlat)
myFrameStyle	. setColor(0.1, 0.9, 0.1, 1)
myPGItem		. setFrameStyle(0, myFrameStyle)

myPath		= NodePath('myPath')
myPath		. attachNewNode(myPGItem)
myPath		. reparentTo(aspect2d)


class EventHandler(DirectObject) :
	
	def __init__(self) :
		self.accept(myPGItem.getEnterEvent(), self.onEnter)
		
	def onEnter(self) :
		print "on enter"
	
ev = EventHandler()

run()

What I was hoping to get is the console to print “on enter” whenever the mouse enters the PGItem (a big green square) but it does not. So I guess somehow the mousewatcher supposed to fire the ENTER event does not fire it or the EventHandler object does not get it, or it’s something else…
I ran it under Windows Vista and Ubuntu 8.04, it failed likewise on both systems.
Does anyone see what is wrong in my code ?

Thanks

Laurent

here:

#! /usr/bin/python 
# -*- coding:utf-8 -*-

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.task import Task

class myPGItem(PGItem) :
  def __init__(self, name="PGItem", parent=aspect2d) :
    PGItem.__init__(self, name=name)
    self.setFrame(-0.5, 0.5, -0.5, 0.5)
    fs=PGFrameStyle()
    fs.setType(PGFrameStyle.TFlat)
    fs.setColor(0.1, 0.9, 0.1, 1)
    self.setFrameStyle(0, fs)
    self.NP=parent.attachNewNode(self)

    DO=DirectObject()
    DO.accept(self.getEnterEvent(), self.onEnter)

    self.NP.setPos(0,0,0)
    self.setActive(True)
    
  def onEnter(self, evt) :
    print "on enter:"+repr(evt)
    
item = myPGItem()

run()

I made it work on my way - hope fits for you as well

And it works great !!!
The missing part was the [color=blue]myPGItem.setActive(True), which does exactly what the documentation says it does :

I should have read it a bit more carefully :unamused:
Thanks a whole bunch for your help

indeed it was the missing setActive - RTFM is a lesson I never get use to learn enough as well, even if I’m not a P3D n00b so don’t get discouraged but try and try :wink: