More DirectFrame and mouse clicking issues

I’m confused on how to make normal DirectFrames clickable. I’ve followed thread , but I still can’t seem to find the solution.

I’ve tried enabling [‘state’] to DGG.NORMAL, but it doesn’t seem to help. The only solution that I’ve find so far is to set pgFunc to PGButton but then I’m creating a button now and not an empty frame. My test code is below.

I create three frames using three different methods:

  1. using the most direct and naive view

def foo():
print “hello”

tframe = DirectFrame(pos=(-.5,0,0), frameSize=(-.2,.2,-.2,.2), state=DGG.NORMAL)
tframe.bind(DGG.B1CLICK, foo)

  1. Making my class

class zDirectFrame(DirectFrame):
def foo(self,event):
print “hello”

def __init__(self, *arg, **kw):

tframe1 = zzDirectButton(pos=(0,0,0), frameSize=(-.2,.2,-.2,.2), state=DGG.NORMAL)

  1. Making a stripped down button class

class zzDirectButton(DirectFrame):
def foo(self,event):
print “hello”

def __init__(self, parent = None, **kw):
	optiondefs = ( 
		('pgFunc',         PGButton,   None),
		('numStates',      4,          None),
	self.defineoptions(kw, optiondefs)
	DirectFrame.__init__(self, parent)          

tframe2 = zDirectFrame(pos=(0.5,0,0), frameSize=(-.2,.2,-.2,.2), state=DGG.NORMAL)

Of the three frames that are created, only last method is clickable, but then its a button so no surprise Can anybody spot my error?

B1CLICK is a synthetic event that means the user has clicked down-and-up on a DirectButton. It is only ever generated for buttons.

For any other object, you can bind to B1PRESS or B1RELEASE instead, which are the lower-level events that are generated in response to a raw mouse press or release.

So this code works:

tframe = DirectFrame(pos=(-.5,0,0), frameSize=(-.2,.2,-.2,.2), state=DGG.NORMAL)
tframe.bind(DGG.B1PRESS, foo)


Ah, ok. Thanks for the clarification! I’ll add a section to the wiki later as this question has come up several times.