DirectFrame with multiple geoms/states?

Hi,

I’m working on some gui widgets and often need to be able to switch between multiple states, which also have a different graphical representation.

Basically, very similar to the DirectButton that has it’s four states (rollover, clicked, etc.) with four different geoms, one for each state.

But since this is not a clickable widget I want to use a DirectFrame instead of a Button.
From reading the docs and looking at the code, I believe that DirectFrame is capable of doing it, but I don’t understand how.

I tried the following:

myFrame = DirectFrame(relief = None, geom = (geom0, geom1), numStates = 2)
myFrame["state"] = 1

So the idea was that I tell the frame that it should have 2 states and I pass in two geometries.
It created the two components (they show up in myFrame.components()) but the geom never switches.

What am I doing wrong?

Cheers,

Erik

Hmm, I think myFrame[“state”] is used to control its clickable/nonclickable state, and isn’t related to this multiple visual state feature.

Instead, try:

myFrame.guiItem.setState(1)

David

Hi David,

No, that didn’t work either.
I again looked at the code of some Direct* classes but that code seems to be beyond me… :wink:

Any other ideas?
It’s not a huge deal because I can always change the geometries of a DirectFrame by re-assigning the geom, such as

myFrame["geom"] = geoms[1]

but that way I’d still have to keep my geometry lists somewhere… It would just be convnient to have that work in the DirectGui widgets internally…

Erik

I just tried it, and it works perfectly for me. Are you sure you were testing it properly?

David

Hi David,

I’m sorry that I have waisted your time. It DOES work fine. I don’t know how I tested it in the first place and came to the conclusion that it wouldn’t work.

Anyway, maybe it’s beneficial for others, so here my quick test that demonstrates that DirectFrame objects can have multiple states and switch between them:

import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from direct.interval.IntervalGlobal import *

# function to switch the states of DirectGui Widget
def switchState(frame, statenum):
    frame.guiItem.setState(statenum)

smiley = loader.loadModel("smiley.egg.pz")
box = loader.loadModel("box.egg.pz")

# add some frames with a single state - I merely display them for reference, to check how my two states will look like..
f1 = DirectFrame(relief = None, geom = smiley, scale = 0.1, pos = (-1,0,0))
f2 = DirectFrame(relief = None, geom = box, scale = 0.1, pos = (1,0,0))

# frame with multiple states
f3 = DirectFrame(relief = None, geom = (box, smiley), numStates = 2, scale = 0.1)

# cerate an interval that switches the state every second
interval = Sequence(Wait(1.0), Func(switchState, f3, 1), Wait(1.0), Func(switchState, f3, 0))
interval.loop()

#run!
run()