GUI events stopped happening?

I have a small prototype with a directGUI element. I am binding the mouse to it like this:

self.image.bind(B1PRESS, self.OnPressB1)

It was working and it stopped all of a sudden. I have no idea what I changed! Also the middle mouse button used to work to drag the elements and that no longer works either. I see the event getting added to the messenger on bind. It seems like the EventQueue no longer gets the message for this event. Any ideas what might have changed? Thanks in advance.

I figured out why it wasnt working. I reinstalled panda at some point and forgot to add “direct-gui-edit 1” to the config.prc. Why do I have to do this to get my gui events to work?

If you are binding to a label, you have to set it to the NORMAL state, rather than DISABLED, in order to receive mouse events (labels are normally DISABLED by default). You can do this at construction time like this:


label = DirectLabel(text = 'label', state = NORMAL, ...)

Or after construction, like this:


label['state'] = NORMAL

As it happens, if you have direct-gui-edit in effect, it puts all your labels in the NORMAL state anyway, to allow moving them around with the middle mouse button.

David

Thanks David! That did the trick. Now I have a slightly more difficult question:

 Lets say my window is not square.  The bounds of my directgui object is determined by the color values in its texture.  If the color is 0,0,0 I want to not handle the event in this object.  I have written a function (AdvancedHitTest) that determines this and it works properly.  
The only problem is I want the event to "pass through" this object to whatever is behind it.  Would I have to temporarily disable the event for this object and resend it through the messenger or is there a more elegant solution?

Thanks in advance.
Wired

Oh, dear. You want to receive an event for an object, and then after the fact, decide that really, the event should have been for some object underneath this one?

To be perfectly honest, I’m not sure you can even do it the way you propose. The code that generates the event is all very low-level, and you don’t have access to it from the Python code. Frankly, the DirectGui system just isn’t set up for this level of sophistication. You might be better off watching the mouse motion yourself (use base.mouseWatcherNode.hasMouse(), getMouseX(), getMouseY(), and listen for the generic button events) and handling all of the required logic in Python.

Though, the concept does intrigue me. Hmm, non-rectangular click regions for DirectGui objects. Hmm.

David

It might be fairly easy to add this to the functionality (I might end up doing it myself) because I would really like to have panda handle the hit testing for me.

First find the spot in code that decides you have clicked on a gui object. Change it so it calls a function on that object, passing the mouse coordinates and returns a boolean indicating if it was indeed within this window. If it returns true, then send the event through, if false then ignore this object for this event.

The directguiwidget class would define the function as always returning true. Any children can override this function with more specific functionality.

Would this be easy to implement?

Unfortunately, it’s not that simple, because of the language crossing. The mouse event is detected and processed by a low-level object in C++. You’d like it to call an event on your Python object. But the C++ code doesn’t know anything about Python; that’s just a layer bolted on top. In fact, aside from the language barrier, there are two different objects involved here; the DirectLabel actually has a member called pgItem, which is the Python wrapper around the low-level C++ object that actually handles the event detection. There are no back pointers from the low-level object to the high-level object, and even if there were, it would be difficult to make the C++ code call a method on your Python object.

David