WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-02-2016, 01:47 PM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
BUTTON_EVENT_Unavailable

#Create main menu object
import vizmenu
menu = vizmenu.add()

#Align the menu in the enter of the top of the screen.
menu.setAlignment( vizmenu.CENTER )

#Scale the menu up
vizmenu.MENU_FONT_SIZE = 24

#Create five menu subjects
n1 = menu.add( 'n1' )
z1 = menu.add( 'z1' )

#Create sub-menu with label for n1
n_checkbox = n1.add( viz.CHECKBOX, 'n11' )
n_checkbox.setScale([3]*3)

#Create sub-menu with label for z1
z_checkbox_p = z1.add( viz.CHECKBOX, 'z11' )
z_checkbox_p.setScale([3]*3)

z_checkbox_n = z1.add( viz.CHECKBOX, 'z12' )
z_checkbox_n.setScale([3]*3)

def onButton_trigger(obj,state):

global z111
global z222

#judgement for z1
if obj == z_checkbox_p:
if state == viz.DOWN:
z111 = True
print 'zt1=',z111
else:
z111 = False

#judgement for z2
if obj == z_checkbox_n:
if state == viz.DOWN:
z222 = True
print 'zt2=',z222
else:
z222 = False
viz.callback(viz.BUTTON_EVENT, onButton_trigger)

def onButton_trigger2(obj,state):

global n11

#judgement for z1
if obj == n_checkbox:
if state == viz.DOWN:
n11 = True
print 'n11=',n11
else:
n11 = False

viz.callback(viz.BUTTON_EVENT, onButton_trigger2)

Why is the code only valid for the later viz.BUTTON_EVENT? But not both of them?
Reply With Quote
  #2  
Old 07-08-2016, 01:21 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Please follow the guidelines for posting Vizard code. That way it will be easier for us to reproduce the problem and help.
Reply With Quote
  #3  
Old 07-14-2016, 09:02 AM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
Thanks

Code:
import vizmenu
menu = vizmenu.add()

#Align the menu in the enter of the top of the screen. 
menu.setAlignment( vizmenu.CENTER )

#Scale the menu up
vizmenu.MENU_FONT_SIZE = 24

#Create five menu subjects
n1 = menu.add( 'n1' )
z1 = menu.add( 'z1' )

#Create sub-menu with label for n1
n_checkbox = n1.add( viz.CHECKBOX, 'n11' )
n_checkbox.setScale([3]*3)

#Create sub-menu with label for z1
z_checkbox_p = z1.add( viz.CHECKBOX, 'z11' )
z_checkbox_p.setScale([3]*3)

z_checkbox_n = z1.add( viz.CHECKBOX, 'z12' )
z_checkbox_n.setScale([3]*3)

def onButton_trigger(obj,state):

    global z111
    global z222	

    #judgement for z1
    if obj == z_checkbox_p: 
        if state == viz.DOWN: 
            z111 = True
            print 'zt1=',z111	
        else: 
            z111 = False

    #judgement for z2
    if obj == z_checkbox_n: 
        if state == viz.DOWN: 
            z222 = True
            print 'zt2=',z222	
        else: 
            z222 = False

viz.callback(viz.BUTTON_EVENT, onButton_trigger)

def onButton_trigger2(obj,state):

    global n11

    #judgement for z1
    if obj == n_checkbox: 
        if state == viz.DOWN: 
            n11 = True
            print 'n11=',n11	
        else: 
            n11 = False

viz.callback(viz.BUTTON_EVENT, onButton_trigger2)

Last edited by haohaoxuexi1; 07-14-2016 at 09:10 AM.
Reply With Quote
  #4  
Old 07-16-2016, 09:17 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
If you're going to use the viz.callback command to handle button events then you should set it up with one callback function. Another way to do this is using vizact.onbuttondown and vizact.onbuttonup. In this case, you should create separate callback functions for each button event:

Code:
import vizact

def n11ButtonDown():
	print 'n11'
	
def z11ButtonDown():
	print 'z11'
	
def z12ButtonDown():
	print 'z12'
	
vizact.onbuttondown(n_checkbox,n11ButtonDown)
vizact.onbuttondown(z_checkbox_p,z11ButtonDown)
vizact.onbuttondown(z_checkbox_n,z12ButtonDown)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:44 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC