event happens, do something other in that case

a newbie question…

i have a DirectButton. if i rollover it, an event is fired.
how can i recognise this event, and if it is fired, do something other (like creating another button, image,…)?

i know there is messenger.toggleVerbose() to get all events happening, but how can i check “enter-pg0” (for rollover-buttonframe-0 i think) is happening, and how can i then fire up other functions?
sorry for my bad english…


You can use DirectObject.accept(‘eventname’,funcname) to have the events handled by a function. This page explains everything:

thanks for your highspeed answer :wink:

now i got this working with e.g. “accept(‘mouse1’,self.doit)”.

but when i set it to “accept(‘enter-pg0’,self.doit)”, i get some errors:

 File "D:\work\aexp\tests\testerei\src\root\example.py", line 104, in ?
  File "C:\Panda3D-1.4.2\direct\src\showbase\ShowBase.py", line 2176, in run
  File "C:\Panda3D-1.4.2\direct\src\task\Task.py", line 930, in run
  File "C:\Panda3D-1.4.2\direct\src\task\Task.py", line 862, in step
  File "C:\Panda3D-1.4.2\direct\src\task\Task.py", line 764, in __stepThroughList
    ret = self.__executeTask(task)
  File "C:\Panda3D-1.4.2\direct\src\task\Task.py", line 684, in __executeTask
    ret = task(*task.extraArgs)
  File "C:\Panda3D-1.4.2\direct\src\showbase\EventManager.py", line 47, in eventLoopTask
  File "C:\Panda3D-1.4.2\direct\src\showbase\EventManager.py", line 41, in doEvents
  File "C:\Panda3D-1.4.2\direct\src\showbase\EventManager.py", line 98, in processEvent
    messenger.send(eventName, paramList)
  File "C:\Panda3D-1.4.2\direct\src\showbase\Messenger.py", line 240, in send
    method (*(extraArgs + sentArgs))
TypeError: doit() takes exactly 1 argument (2 given)

any ideas?

It means, that ‘enter-pg0’ is trying to pass an argument to your function self.doit, while it doesnt take any arguments.
Define your function like this:

  def doit(self,arg):
    #do with 'arg' whatever you want

EDIT: i just wrote this post a bit too early…
now it works!
thanks very much for your help

seems like the above code (accept(‘mouse1’…) creates new events.
it executes a function when mouse1 is clicked.

my problem is a bit different: i have a button that is already bound to a mouseaction.

i now want to recognize if that “button-clicked” mouse event, and then do do some function.

do you know what i mean?

When you create a DirectButton, you simply pass any function you like to its command= keyword parameter. This function will be called when the button is clicked.

For a more advanced feature, with any DirectGui object, you can use the DirectGui bind() method to associate functions with esoteric mouse operations. See this thread for more info on that.