Menu button values

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
damir
Posts: 0
Joined: Tue Feb 21, 2006 7:50 pm

Menu button values

Post by damir »

My english isn't that good but I will try to explain what I need:

I have 2 menus, I have created them in this way:

Code: Select all

import Blender
from Blender import *

# Globals
glob_menu1 = Draw.Create(0)
glob_menu2 = Draw.Create(0)

mnu1Content = "Menu1%t|Option1|Option2"
mnu2Content = ""

menuDict = {"Option1":["Option1_1","Option1_2"],"Option2":["Option2_1","Option2_2","Option2_3"]}

def fillMenu2(val):
    
    global mnu1Content, mnu2Content, menuDict
    
    option = mnu1Content.split('|')[val]
    mnu2Content = "Menu2%t"
    for item in menuDict[option]:
        print item
        mnu2Content = mnu2Content+"|"+item
    Draw.Redraw()

def draw():
  
    global glob_menu1, glob_menu2, mnu1Content, mnu2Content
    
    BGL.glClearColor(0.600000,0.600000,0.600000,1)
    BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
 
    glob_menu1 = Draw.Menu(mnu1Content,1,10,10,100,20,glob_menu1.val,'Menu1')
    glob_menu2 = Draw.Menu(mnu2Content,2,120,10,100,20,glob_menu2.val,'Menu2')
    
    Draw.PushButton('Quit',3,230,10,50,20,'Exit script')

def event(evt,val): #ESC key press
    
    if evt == Draw.ESCKEY and not val:
        Draw.Exit()
    
def bevent(evt):    
    
    global glob_menu1
    
    if evt == 1:
        fillMenu2(glob_menu1.val)
    
    elif evt == 2:
        pass
    
    elif evt == 3:
        Draw.Exit()

Draw.Register(draw,event,bevent)
How can I control default menu selection? When script starts, both menus are blank (there's no text in menu box) until I change to some option in Menu1. I could set Draw.Create(1) for both menus, but that will show Option1 only for Menu1, Menu2 will be still empty until I chage option for Menu1. And If I change Menu1 to Option2, then change Menu2 to Option2_3, and then again change Menu1 to Option1, Menu2 value will still be 3 and it will show nothing.
I don't know a different way to create this so if anyone understands what I ask please help.
Thanks!

Post Reply