Problem with DirectWaitBar options/values

Just as a practice I typed in the demo code from the manual for DirectWaitBar.

First the code in the manual will not complile without

from padac.pandaModules import TextNode.

That is not in the maual example.

After I entered that line the example complied fine but then I decided to add some other things just to practice. I added "range = 100, barRelief= SUNKEN) to the DirectWaitBar statement I got a python error that said

“NameError: name ‘SUNKEN’ is not defined”

Thinking I may need to add a bit of a frame to make that work I added

barBorderWidth=(5,5)
Still the same error.

The manual says these are all valid keywords to add to a DircectWaitBar statement why is it not working?

Here is my code:

import direct.directbase.DirectStart
from pandac.PandaModules import TextNode
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *

#add some text
bk_text = "This is my Demo"
textObject = OnscreenText(text = bk_text,pos = (0.95,0.95), scale = 0.07,fg = (1,0.5,0.5,1),align = TextNode.ACenter,mayChange=1)

#Callback fucntions to set text
def incBar(arg):
        bar['value'] += arg
        text = "Progress is:" + str(bar['value']) + "%"
        textObject.setText(text)
        
#create a frame
frame =DirectFrame(text = "main", scale = 0.001)
#add button
bar = DirectWaitBar(text = "",value=50, range = 100,barRelief = SUNKEN,barBorderWidth= (5,5),pos=[0,.4,.4])

# create 4 buttons
button_1 = DirectButton(text = "+1",scale = 0.05,pos =(-.3,.6,0),command = incBar,extraArgs = [1])
button_10 = DirectButton(text = "+10",scale = 0.05,pos =(0,.6,0),command = incBar,extraArgs = [10])
button_m1 = DirectButton(text = "-1",scale = 0.05,pos =(.3,.6,0),command = incBar,extraArgs = [-1])
button_m10 = DirectButton(text = "-10",scale = 0.05,pos =(.6,.6,0),command = incBar,extraArgs = [-10])

# run the tutorial
run()

After doing a bit of digging I came up with this solution.

The variables such as RAISED and SUNKEN are defined in the python file DirectGuiGlobals.py in the folder direct\src\gui.

When you import the module DirectGui

from direct.gui.DirectGui import *

the variables from DirectGuiGlobals.py are also imported.

This can be seen on the first line of DirectGui.py (also in the directory direct\src\gui). However DirectGuiGlobals.py is imported as DGG in DirectGui.py so as a result all variable calls from the DirectGuiGlobals module need to be prefixed with DGG. i.e. DGG.SUNKEN is a valid variable call.

It seems that the manual should be updated to show this ‘bug’

Robert

P.S. also

barBorderWidth=(5,5)

is quite a big value for the width, you will only see red on your screen, try something like 0.05. The below code works with a raised bar.

import direct.directbase.DirectStart
from pandac.PandaModules import TextNode
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *

#add some text
bk_text = "This is my Demo"
textObject = OnscreenText(text = bk_text,pos = (0.95,0.95), scale = 0.07,fg = (1,0.5,0.5,1),align = TextNode.ACenter,mayChange=1)

#Callback fucntions to set text
def incBar(arg):
        bar['value'] += arg
        text = "Progress is:" + str(bar['value']) + "%"
        textObject.setText(text)
       
#create a frame
frame =DirectFrame(text = "main", scale = 0.001)
#add button
bar = DirectWaitBar(text = "",value=50, range = 100,barRelief = DGG.RAISED,barBorderWidth= (0.05,0.05),pos=[0,.4,.4])

# create 4 buttons
button_1 = DirectButton(text = "+1",scale = 0.05,pos =(-.3,.6,0),command = incBar,extraArgs = [1])
button_10 = DirectButton(text = "+10",scale = 0.05,pos =(0,.6,0),command = incBar,extraArgs = [10])
button_m1 = DirectButton(text = "-1",scale = 0.05,pos =(.3,.6,0),command = incBar,extraArgs = [-1])
button_m10 = DirectButton(text = "-10",scale = 0.05,pos =(.6,.6,0),command = incBar,extraArgs = [-10])

# run the tutorial
run() 

or just create your own gauge :

Thanks ynjh_jo now we are going to get 50 “how did you do that’s?”

… How did you do that? :stuck_out_tongue:

Robert

dig it yourself, it’s not much :
discourse.panda3d.org/viewtopic.php?t=3875
it’s near the end of IDE.py
I hope it run on your system now.