VS:RunLayoutDialog

From Vectorworks Developer
Revision as of 10:22, 28 September 2015 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Displays the specified dialog and initiates the dialog event loop. The dialog event loop is specified in a procedure subroutine that is passed as a parameter to the function.
FUNCTION RunLayoutDialog(
dialogID  :LONGINT;
callback  :PROCEDURE) : LONGINT;
def vs.RunLayoutDialog(dialogID, callback):
    return LONGINT

Parameters

dialogID LONGINT The index of the dialog to be displayed.
callback PROCEDURE The event loop subroutine for the dialog.

Return Value

Returns a LONGINT value indicating the button pressed to exit the dialog.

Remarks

RunLayoutDialog returns the index of the last control event (1 for OK and 2 for Cancel). The callback procedure has to be written like this:
PROCEDURE callback(VAR item : LONGINT; data :LONGINT);
BEGIN
message('Item: ', item, '  Data in that item: ', data);
END;
def callback(item, data):
   vs.Message('Item: ' + str(item) + '  Data in that item: '+ str(data));
	
    return item 

This function is also called before the dialog opens with a value of 2255 for item and when the dialog closes (value 2256). Despite the fact that the arguments to the callback procedure are VARd (so that they should have global bindings), these variables really only have bindings within the callback procedure. Even if you declare them globally. Fact of the matter is that you cannot specify arguments when you call the callback procedure, so there's no way to establish the global bindings of the VARd arguments. Inside the callback procedure, the item argument is set to the index of the last control event. The data argument is set to values appropriate for the type of control that was activated.

Do not use the VS:Wait() function in the event handler subroutine of Layout Manager dialogs. Doing so will freeze the script, though you can force quit it with a command-period.

If you want to prevent a dialog from terminating after someone has clicked on the OK button, set item equal to -1. Note that in Python there is no output parameters. So, this value should be returned.

Example

Python

def UIAskForStringsToReplace():
	# control IDs
	kOK             = 1
	kCancel         = 2
	kTxt1           = 4
	kTxt2           = 5
	kEdit1          = 6
	kTxt3           = 7
	kEdit2          = 8
	
	# dialog data
	UIAskForStringsToReplace.strFind		= ''
	UIAskForStringsToReplace.strReplace		= ''

	def CreateDialog():
		# Alignment constants
		kRight                = 1
		kBottom               = 2
		kLeft                 = 3
		kColumn               = 4
		kResize               = 0
		kShift                = 1

		dialog = vs.CreateResizableLayout( 'Rename All Symbols', True, 'OK', 'Cancel', True, False )

		# create controls
		vs.CreateStaticText( dialog, kTxt1, 'Replace a sub-string from all symbol names:', -1 )
		vs.CreateStaticText( dialog, kTxt2, 'Old sub-string:', -1 )
		vs.CreateEditText( dialog, kEdit1, '', 25 )
		vs.CreateStaticText( dialog, kTxt3, 'New sub-string:', -1 )
		vs.CreateEditText( dialog, kEdit2, '', 25 )

		# set relations
		vs.SetFirstLayoutItem( dialog, kTxt1 )
		vs.SetBelowItem( dialog, kTxt1, kTxt2, 0, 0 )
		vs.SetRightItem( dialog, kTxt2, kEdit1, 0, 0 )
		vs.SetBelowItem( dialog, kTxt2, kTxt3, 0, 0 )
		vs.SetRightItem( dialog, kTxt3, kEdit2, 0, 0 )

		# set alignments
		vs.AlignItemEdge( dialog, kEdit1, kLeft, 1, kShift );
		vs.AlignItemEdge( dialog, kEdit2, kLeft, 1, kShift );

		# set bindings
		vs.SetEdgeBinding        ( dialog, kEdit1, True, True, False, False )
		vs.SetEdgeBinding        ( dialog, kEdit2, True, True, False, False )

		return dialog
		
	def DialogHandler(item, data):
		if item == kOK: 
			UIAskForStringsToReplace.strFind		= vs.GetItemText( dialog, kEdit1 )
			UIAskForStringsToReplace.strReplace		= vs.GetItemText( dialog, kEdit2 )
	
		return item 
		
	dialog = CreateDialog()
	result = False
	if vs.RunLayoutDialog( dialog, DialogHandler ) == kOK:
		result = True
        
	return result, UIAskForStringsToReplace.strFind, UIAskForStringsToReplace.strReplace
	

ok, strFind, strReplace = UIAskForStringsToReplace()
vs.AlrtDialog( ok, ' - ', strFind, '-', strReplace )

Version

Availability: from VectorWorks9.0
Personal tools
NamespacesFFFF

Variants
Actions
Advanced Search
See Also
Navigation
Toolbox