SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

WebDialog class

The Ruby WebDialog class to create and interact with, DHTML dialog boxes, called webdialogs in this documentation, from Ruby. This class supports DHTML webdialogs created with JavaScript.

Parent:

Methods: add_action_callback, allow_actions_from_host, bring_to_front, close, execute_script, get_default_dialog_color, get_element_value, new, post_url, set_background_color, set_file, set_html, set_on_close, set_position, set_size, set_url, show, show_modal, visible?

Example Code: units.rb and units.html in Tools\HelpContent_en. This webdialog appears when you first run SketchUp and is used to set your default units for your locale.

TOTD.rb in Tools directory and the tips html pages in Tools\HelpContent_en\Tip\Tips. This Ruby file and series webdialogs are used to display the Learning Center (Window > Learning Center).

Class methods


new

The new method is used to create a new webdialog.

Syntax

dialog = UI::WebDialog.new dialog_title, scrollable, preferences_key, left, top, resizable

Arguments

dialog_title - the title to be displayed in the webdialog

scrollable - true if you want to allow scrollbars, false if you do not want to allow scrollbars.

preferences_key - the registry entry where the location and size of the dialog will be saved. If preferences_key is not included, the location and size will not be stored.

width - the width of the webdialog.

height - the height of the webdialog.

left - the number of pixels from the left-side of the screen to position the dialog.

top - the number of pixels from the top of the screen to position the dialog.

resizable - true if you want the webdialog to be resizable, false if you do not want the webdialog to be resizable.

Return Value

dialog - the newly created WebDialog object.

Comments

Default width is 250. Default height is 250. Default left is 0. Default top is 0.

Example

dlg = UI::WebDialog.new("Choose Default Settings", true, "Units Picker", 739, 641, 150, 150, true);

Instance Methods


add_action_callback

The add_action_callback method establishes a Ruby callback method that your web dialog can call to perform some function.

Syntax

dialog.add_action_callback ("callback_method_name){|d,p| activities_to_perform}

Arguments

callback_method_name - the name of the callback method to be invoked from the webdialog.

d - the dialog

p - any parameters passed to the dialog from HTML

activities_to_perform - Ruby syntax performed when the callback_method_name is invoked from the webdialog.

Comments

Use the skp:callback_method_name to invoke the callback method from your webdialog. Your JavaScript in the webdialog will invoke the callback method with a string representing arguments to the callback method.

Example

In Ruby code: 

dlg.add_action_callback("on_template_changed") {|d,p|
	a = p.split(',');
	t = a[0];
	d = a[1];
	# put them together
	t += "-" + d;
	# find it in the template_paths
	template_paths.each {|p|
		if(t == File.basename(p,".skp"))
		template = p;
		return
		end
	}
}

In webdialog:

function onTemplateChanged()
{
	window.location='skp:on_template_changed@' + document.getElementById('TemplateSelect').value + ',' + dim;
}

 

 


allow_actions_from_host

By default, actions are only allowed on the host where the webdialog is displayed. The allow_actions_from_host method is used to selectively allow actions to take place on a host remote from the host where the webdialog exists. If the webdialog is local, no remote host is allowed unless you use this method.

Syntax

dialog.allow_actions_from_host hostname

Arguments

hostname - the name of the secure host that your webdialog can access safely.

 

 


bring_to_front

The bring_to_front method is used to bring the webdialog to the front of all the windows on the desktop.

Syntax

dialog.bring_to_front

Example

 

 

 


close

The close method is used to close the webdialog.

Syntax

dialog.close

 

 


execute_script

The execute_script method is used to execute a JavaScript string on the web dialog.

Syntax

dialog.execute_script("script")

Arguments

script - the JavaScript script to execute on the webdialog.

Example

dialog.execute_script("document.getElementById('someId').innerHTML= '<b>Hi There!</b>'");

 

 


get_default_dialog_color

The get_default_dialog_color method is used to get the default dialog color for the web dialog.

Syntax

color = dialog.get_default_dialog_color	

Return Value

color - a six digit hexidecimal number representing the color

 

 


get_element_value

The get_element_value method is used to get a value, with a given element_id, from the web dialog.

Syntax

dialog.get_element_value("element_id")

Arguments

element_id - the name of the element in your HTML code.

Example

In Ruby code:

dlg.get_element_value("myTextInput") 

In webdialog:

<input type=text id="myTextInput">...

 


post_url

The post_url method is used to send the data to a url using the HTTP POST method.

Syntax

dialog.post_url url, data

Arguments

url - the url to send the data.

data - the data to be sent.

Example

 

 


set_background_color

The set_background_color method is used to set the background color for the webdialog.

Syntax

dialog.set_background_color = "color"

Arguments

color - a six digit hexidecimal color.

Example

dlg.set_background_color("f3f0f0");

 

 


set_file

The set_file method is used to identify the HTML file, representing the webdialog, to display in the browser..

Syntax

dialog.set_file filename, relativetopath

Arguments

filename - the filename for the webdialog file (HTML file).

relativetopath - a path that filename is relative to.

Example

html = File.dirname(__FILE__) + "/units.html";
	if(html.length == 0)
		return false;
	end



dlg.set_file(html, nil);

 

 


set_html

The set_html method is used to load a webdialog with a string of provided HTML.

Syntax

dialog.set_html html_string

Arguments

html_string - a string of valid html to display in your webdialog

 

 


set_on_close

The set_on_close method is used to establish one or more activities to perform when the dialog closes (such as saving values stored in the dialog).

Syntax

dialog.set_on_close { activities_to_perform }

Arguments

activities to perform - Ruby syntax performed when the dialog closes.

 

 


set_position

The set_position method is used to set the position of the webdialog relative to the screen.

Syntax

dialog.set_position left, top

Arguments

left - the number of pixels from the left-side of the screen to position the dialog.

top - the number of pixels from the top of the screen to position the dialog.

 

 


set_size

The set_size method is used to set the size of the webdialog.

Syntax

dialog.set_size w,h

Arguments

w - width of the webdialog.

h - height of the webdialog.

 

 


set_url

The set_url method is used to load a webdialog with the content at a specific URL. This method allows you to load web sites in a webdialog.

Syntax

dialog.set_url url

Arguments

url - the URL for a specific web site.

Example

dialog.set_url "http://www.google.com"

 

 


show

The show method is used to display a non-modal dialog box.

Syntax

dialog.show { activities_to_perform }

Arguments

activities_to_perform - Ruby syntax performed when the dialog is displayed.

Example

dialog.show {
  	dialog.execute_script("document.getElementById('someId').innerHTML= '<b>Hi There!</b>'");
}

 


show_modal

The show_modal method is used to display a model dialog box.

Syntax

dialog.show_model { activities_to_perform }

Arguments

activities_to_perform - Ruby syntax performed when the dialog is displayed.

Example

dlg.show_modal{ 
	// execute JavaScript code called "init_templates" in the webdialog
	// code.
	dlg.execute_script("init_templates(" + args + ")");
}

 

 


visible?

The visible? method is used to determine if webdialog is visible.

Syntax

status = dialog.visible?

Return Value

status - true if visible, false if not visible.

 

SketchUp  Ruby API Reference: WebDialog class

© Google Inc. 2007 sketchup.google.com