View Single Post
  #2  
Old 02-20-2008, 10:36 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You can try using the undocumented vizdlg module for displaying forms. It allows more advanced form layouts and dialog like components. Here is sample code that creates a custom dialog/form and displays it when the 'p' key is pressed:
Code:
import viz
viz.go()

import vizdlg

class MyForm(vizdlg.Dialog):

	def __init__(self,**kw):
		
		#Initialize base class
		vizdlg.Dialog.__init__(self,**kw)
		
		#Add row of checkboxes
		row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
		row.addItem(viz.addText('Checkboxes'))
		self.check1 = row.addItem(viz.addCheckbox())
		self.check2 = row.addItem(viz.addCheckbox())
		self.check3 = row.addItem(viz.addCheckbox())
		
		#Add row to dialog content section
		self.content.addItem(row)
	
		#Add a subgroup containing slider/textbox
		group = vizdlg.Panel()
		
		#Add row for slider to subgroup
		row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
		row.addItem(viz.addText('Slider'))
		self.slider = row.addItem(viz.addSlider())
		group.addItem(row)
		
		#Add row for textbox to subgroup
		row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
		row.addItem(viz.addText('Textbox'))
		self.textbox = row.addItem(viz.addTextbox())
		group.addItem(row)
		
		#Add group to dialog content section
		self.content.addItem(group)

		#Hide cancel button
		self.cancel.visible(0)
		
		#Rename accept button to 'submit'
		self.accept.message('Submit')
		
import viztask

def FormTask():

	#Create input form
	form = MyForm(title='Form title')

	#Link form to center of screen
	viz.link(viz.MainWindow.CenterCenter,form)

	while True:
		
		#Wait for 'p' key to be pressed
		yield viztask.waitKeyDown('p')
		
		#TODO: Pause simulation
		
		#Display form
		yield form.show()
		
		if form.accepted:
			#User pressed 'Submit', process data
			print 'Checkboxes:',form.check1.get(),form.check2.get(),form.check3.get()
			print 'Slider:',form.slider.get()
			print 'Textbox:',form.textbox.get()
		
		#TODO: Resume simulation
		
	#Remove form when completely finished with it
	form.remove()
	
viztask.schedule( FormTask() )
Reply With Quote