|
SketchUp Ruby API Reference |
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).
The new method is used to create a new webdialog.
dialog = UI::WebDialog.new dialog_title, scrollable, preferences_key, left, top, resizable
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.
dialog - the newly created WebDialog object.
Default width is 250. Default height is 250. Default left is 0. Default top is 0.
dlg = UI::WebDialog.new("Choose Default Settings", true, "Units Picker", 739, 641, 150, 150, true);
The add_action_callback method establishes a Ruby callback method that your web dialog can call to perform some function.
dialog.add_action_callback ("callback_method_name){|d,p| activities_to_perform}
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.
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.
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;
}
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.
dialog.allow_actions_from_host hostname
hostname - the name of the secure host that your webdialog can access safely.
The bring_to_front method is used to bring the webdialog to the front of all the windows on the desktop.
dialog.bring_to_front
The close method is used to close the webdialog.
dialog.close
The execute_script method is used to execute a JavaScript string on the web dialog.
dialog.execute_script("script")
script - the JavaScript script to execute on the webdialog.
dialog.execute_script("document.getElementById('someId').innerHTML= '<b>Hi There!</b>'");
The get_default_dialog_color method is used to get the default dialog color for the web dialog.
color = dialog.get_default_dialog_color
color - a six digit hexidecimal number representing the color
The get_element_value method is used to get a value, with a given element_id, from the web dialog.
dialog.get_element_value("element_id")
element_id - the name of the element in your HTML code.
In Ruby code:
dlg.get_element_value("myTextInput")
In webdialog:
<input type=text id="myTextInput">...
The post_url method is used to send the data to a url using the HTTP POST method.
dialog.post_url url, data
url - the url to send the data.
data - the data to be sent.
The set_background_color method is used to set the background color for the webdialog.
dialog.set_background_color = "color"
color - a six digit hexidecimal color.
dlg.set_background_color("f3f0f0");
The set_file method is used to identify the HTML file, representing the webdialog, to display in the browser..
dialog.set_file filename, relativetopath
filename - the filename for the webdialog file (HTML file).
relativetopath - a path that filename is relative to.
html = File.dirname(__FILE__) + "/units.html"; if(html.length == 0) return false; end dlg.set_file(html, nil);
The set_html method is used to load a webdialog with a string of provided HTML.
dialog.set_html html_string
html_string - a string of valid html to display in your webdialog
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).
dialog.set_on_close { activities_to_perform }
activities to perform - Ruby syntax performed when the dialog closes.
The set_position method is used to set the position of the webdialog relative to the screen.
dialog.set_position left, top
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.
The set_size method is used to set the size of the webdialog.
dialog.set_size w,h
w - width of the webdialog.
h - height of the webdialog.
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.
dialog.set_url url
url - the URL for a specific web site.
dialog.set_url "http://www.google.com"
The show method is used to display a non-modal dialog box.
dialog.show { activities_to_perform }
activities_to_perform - Ruby syntax performed when the dialog is displayed.
dialog.show {
dialog.execute_script("document.getElementById('someId').innerHTML= '<b>Hi There!</b>'");
}
The show_modal method is used to display a model dialog box.
dialog.show_model { activities_to_perform }
activities_to_perform - Ruby syntax performed when the dialog is displayed.
dlg.show_modal{
// execute JavaScript code called "init_templates" in the webdialog
// code.
dlg.execute_script("init_templates(" + args + ")");
}
The visible? method is used to determine if webdialog is visible.
status = dialog.visible?
status - true if visible, false if not visible.
|
SketchUp Ruby API Reference: WebDialog class |
© Google Inc. 2007 sketchup.google.com |