Is it possible to make it so that if a DirectGUI object gets an event it garbles it up - so that my event listener doesn’t get it?
As it is, if you have a button, say, and an event listener for mouse1, when you click the button it will also send the mouse1 event to the handler.
I do not want this for (hopefully) obvious reasons…
I tried adding “accept” listeners to the gui so that when an object got a Focus/Unfocus event it would toggle a variable in my handler for whether input was caught or not.
That worked for Entries, but not buttons.
I also tried adding an accept for “mouse1” in buttons - but that just garbles all input then.
I figure there must be some simple solution to this somewhere…
Thanks
Really? It’s supposed to automatically suppress mouse button events when you click a DirectGui object. (In fact, the keyword parameter is suppressMouse = True, which is set by default. There is also suppressKeys = True, which is not set by default; this will suppress keyboard buttons also.)
It appears to work for me:
from direct.directbase.DirectStart import *
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
class Watcher(DirectObject):
def __init__(self):
self.accept('mouse1', self.mouseEvent)
def mouseEvent(self):
print "clicked mouse"
def buttonEvent():
print "clicked button"
w = Watcher()
b = DirectButton(text = 'button',
scale = 0.1,
pos = (-0.5, 0, 0),
command = buttonEvent,
)
run()
This print “clicked button” when I click over the button, and “clicked mouse” when I click anywhere else. It does not print “clicked mouse” when I click over the button.
Does it not work this way for you?
Note that while the ‘mouse1’ event is suppressed, the ‘mouse1-up’ event is not. The idea is never to suppress the -up events, or you might lose track of whether the mouse button is down (if the user, say, clicked down, moved the mouse over a button, and then released it there).
Well, that was one part of it, I was catching the mouse-up and not checking to make sure I got a mouse down first - so that is easy to fix. But what about the DirectEntry widget?
When I am typing into it an entry it still generates key press events.