Im still working with Blender 2.4x so here’s my classic example for an interface in Blender 2.4x:
from Blender import *
from Blender.BGL import *
normal_info = 0
err_not_critical = 1
err_critical = 2
a_nice_message = 3
info_code = normal_info
threshold = 0.00001
msg = "Here is the Info bar..."
stNewRow = "
"
xLeft = 10
yUpperButtons = 490
wMax = 640
RowHeight = 15
RowDistance = 3
yRow = RowHeight + RowDistance
yLowerButtons = 35
yButton = 18
yBigButton = 25
wButton = 60
wb14 = int(1.4*wButton)
flOnlyOnce = True
menu_item = 1
num = 10
num_2 = 20
num_2_min = num
num_2_max = 5*num
#############################################################
# Graphics #
#############################################################
def makeForm(st):
global menu_item
global num
global num_2
global num_2_min
global num_2_max
global value
global mode
y = yUpperButtons-RowHeight
BGL.glClearColor(0.5, 0.5, 0.5, 1)
BGL.glColor3f(0.8,0.6,0.6) # Light red
y = 3*yRow
BGL.glRectf(4,yLowerButtons-2*yRow,800,y)
BGL.glColor3f(0.6,0.8,0.6) # Light green
y = 21*yRow
BGL.glRectf(4,yLowerButtons+4,800,y)
BGL.glColor3f(0.8,0.6,0.6) # Light red
BGL.glRectf(4,y,800,y+5*yRow)
x = xLeft
y = yLowerButtons-yBigButton-2
Draw.Button("Redraw",4,x,y,2*wButton,yBigButton)
x = x+2*wButton
Draw.Button("Exit",1,x,y,wMax,yBigButton)
x = xLeft
y = yLowerButtons+2*yRow
# Double conversion cause after the first cycle num results
num_val = int(str(num)) # in the Num value
num = Draw.Number("Num_value:",2,x,y,2*wb14,yButton,num_val,0,100,"A test numeric control")
x = x+5*wb14
num_val_2 = int(str(num_2)) # in the Num 2 value
num_2 = Draw.Number("Num_value_2:",3,x,y,2*wb14,yButton,num_val_2,num_2_min,num_2_max,"A test numeric control 2")
y = yLowerButtons+6*yRow
name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3"
# Double conversion cause after the first cycle menu_item results
menu_val = int(str(menu_item)) # in a MenuItem value
menu_item = Draw.Menu(name,5,x,y,2*wb14,yButton,menu_val,"A test menu")
x = xLeft
y = yUpperButtons+6
BGL.glColor3f(1,1,0)
BGL.glRasterPos2d(x,y)
Draw.Text("Blender Interface test, ver. 0.1.0")
BGL.glColor3f(0,0,1)
y = y-yRow
BGL.glRasterPos2d(x,y)
Draw.Text("by Emil Lozanov <a.k.a. Abidos> - 2009")
Info(st,info_code)
#######################################
def Info(st,info_code=normal_info):
y = yUpperButtons+RowHeight+5
Info_y(st,y,info_code)
def Info_y(st,y,info_code):
if (info_code == normal_info):
BGL.glColor3f(0,0,0.6) # Dark blue
elif (info_code == err_not_critical):
BGL.glColor3f(0.8,0.6,0.6) # Light red
elif (info_code == err_critical):
BGL.glColor3f(0.9,0,0) # Bright red
elif (info_code == a_nice_message):
BGL.glColor3f(0,0.6,0) # Dark green
else:
BGL.glColor3f(0,0,0) # Black
BGL.glRectf(xLeft,y,wMax,y+RowHeight)
BGL.glColor3f(1,1,1)
BGL.glRasterPos2d(xLeft+2,y+3)
Draw.Text(st)
##############################################################
def draw():
global msg
global flOnlyOnce
t = sys.time()
st = "t = "+str(t)+" "+msg
makeForm(st)
if flOnlyOnce:
flOnlyOnce = False
print
print
print "##############################################"
print "# #"
print "# * * * Blender Interface test * * * #"
print "# #"
print "# Written by Emil Lozanov, a.k.a. Abidos #"
print "# #"
print "# version 0.1.0 - 02.09.2009 #"
print "# #"
print "##############################################"
print
##### " * * * Done only once * * * "
print
print "==>>> Processing time = %.0f milliseconds" % (1000*(sys.time()-t))
print
print "========================================================================="
print
#############################################################
####### Event, bevent procs #####################
#############################################################
def event(evt,val):
global msg
global value
global mode
if not val:
return
if (evt == Draw.QKEY) or (evt == Draw.ESCKEY):
Draw.Exit()
Redraw(Window.Types.SCRIPT)
#######################################
def bevent(evt):
global msg
global info_code
global num
global num_2
global num_2_min
global num_2_max
info_code = normal_info
if (evt==1):
Draw.Exit()
elif (evt==2): # Test NUM value ======================================
st = "From bevent --> num_value = "+str(num)
msg = st
print st
print
num_2_min = int(str(num))
num_2_max = 5*int(str(num))
if num_2 < num_2_min:
num_2 = num_2_min
if num_2 > num_2_max:
num_2 = num_2_max
elif (evt==3): # Test NUM value 2 ======================================
st = "From bevent --> num_value 2 = "+str(num_2)
msg = st
print st
print
elif (evt==4): # Test REDRAW feature ======================================
st = "From bevent --> Redraw()"
msg = st
print st
print
info_code = a_nice_message
elif (evt==5): # Test MENU value ======================================
st = "From bevent --> menu_item = "+str(menu_item)
msg = st
print st
print
elif (evt<=98): # Not active yet.....
st = "From bevent --> Not active yet..."
msg = st
elif (evt==99): # Other ======================================
st = "From bevent --> Other......"
msg = st
print st
print
elif (evt>99): # Out of range.....
st = "From bevent --> Out of range..."
msg = st
Draw.Exit()
Redraw()
##############################################################
Draw.Register(draw, event, bevent)
Some constants may be not used in this example but it is takes from a bigger inteface so pls dont pay much attention on this. Anyway the above shows you creation and use of a menu plus 2 integer boxes that dependable - the second one can use values ONLY in the range of the value of the first one to 5 times this value. All actions are appropriately reported at a special InfoBar plus at the console. InfoBar change color is demonstrated by clicking the Redraw button… Actions (such as initializations) that are to me done only at the beginning are put in the the if flOnlyOnce: section in draw() proc. The event() and bevent() procs are expandable… Currently, bevent() proc effectively responds to button events from 1 to 5 and “supports” such events till 99… You may wish to customize it further - feel free to do so!
Referring to this thread, I’d call the menus “drop-ups” rather than “drop-downs”, unless you find a way to make them really drop-down (which I would be interested to know HOW-TO)…
Regards,