Class: UI::WebDialog Deprecated
Relationships | |
Inherits: | Object |
Overview
Please use HtmlDialog
that was introduced in SketchUp 2017.
The Ruby WebDialog
class allows you to create and interact with DHTML dialog boxes from Ruby.
If your goal is to simply display a website to your users, consider using openURL, which will show them a web page in their default browser rather than inside a dialog in SketchUp.
See this blog post for a detailed, step-by-step example: sketchupapi.blogspot.com/2008/02/sharing-data-between-sketchup-ruby-and.html
Under Windows the IE render mode is different in webdialogs than from what you see in the normal browser. It will by default pick an older render mode and different versions of SketchUp will use different modes. In order to reliably control the render mode of your webdialogs under Windows you need to insert a special META compatibility tag:
// To always force the latest version available:
< http-equiv="X-UA-Compatible" content="IE=edge"/>
// To lock to a specific IE version:
< http-equiv="X-UA-Compatible" content="IE=8"/>
Starting with SketchUp 2013, you can embed a special HTML link in your dialog that will launch Extension Warehouse and show a specified extension’s page. This can be useful if your extension has a dependency on another one and you would like to direct the user to install that extension.
For example, to launch an extension’s page whose URL is: extensions.sketchup.com/en/content/advanced-camera-tools The link would be:
Class Method Summary
-
.new(dialog_title = "", scrollable = true, pref_key = nil, width = 250, height = 250, left = 0, top = 0, resizable = true) ⇒ UI::WebDialog
constructor
The
new
method is used to create a new webdialog.
Instance Attribute Summary
-
#max_height ⇒ Integer
rw
The max_height method is used to get the maximum height that the user is allowed to resize the dialog to.
-
#max_height=(height) ⇒ Integer
rw
The max_height= method is used to set the maximum height that the user is allowed to resize the dialog to.
-
#max_width ⇒ Integer
rw
The max_width method is used to get the maximum width that the user is allowed to resize the dialog to.
-
#max_width=(width) ⇒ Integer
rw
The max_width= method is used to set the maximum width that the user is allowed to resize the dialog to.
-
#min_height ⇒ Integer
rw
The min_width method is used to get the minimum height that the user is allowed to resize the dialog to.
-
#min_height=(height) ⇒ Integer
rw
The min_height= method is used to set the minimum height that the user is allowed to resize the dialog to.
-
#min_width ⇒ Integer
rw
The min_width method is used to get the minimum width that the user is allowed to resize the dialog to.
-
#min_width=(width) ⇒ Integer
rw
The min_width= method is used to set the minimum width that the user is allowed to resize the dialog to.
-
#navigation_buttons_enabled=(nav_buttons) ⇒ Boolean
rw
The navigation_buttons_enabled= method is used to set whether the home, next, and back buttons are visible at the top of the
WebDialog
on the mac. -
#navigation_buttons_enabled? ⇒ Boolean
rw
The navigation_buttons_enabled? method is used to get whether the home, next, and back buttons are visible at the top of the
WebDialog
on the mac. -
#visible? ⇒ Boolean
readonly
The visible? method is used to tell if the webdialog is currently shown.
Instance Method Summary
-
#add_action_callback(callback_name) {|dialog, params| ... } ⇒ Object
The add_action_callback method establishes a Ruby callback method that your web dialog can call to perform some function.
-
#allow_actions_from_host(hostname) ⇒ Boolean
By default, actions are only allowed on the host where the webdialog is displayed.
-
#bring_to_front ⇒ UI::WebDialog
The bring_to_front method is used to bring the webdialog to the front of all the windows on the desktop.
-
#close ⇒ nil
The close method is used to close the webdialog.
-
#execute_script(script) ⇒ Boolean
The execute_script method is used to execute a JavaScript string on the web dialog.
-
#get_default_dialog_color ⇒ String
The get_default_dialog_color method is used to get the default dialog color for the web dialog.
-
#get_element_value(element_id) ⇒ String
The get_element_value method is used to get a value, with a given element_id, from the web dialog’s DOM.
-
#post_url(url, data) ⇒ nil
The post_url method is used to send the data to a url using the HTTP POST method.
-
#screen_scale_factor ⇒ Float
The screen_scale_factor method returns the ratio of screen pixels to logical window units (called ‘points’ on Mac) for the screen this
WebDialog
is currently in. -
#set_background_color(color) ⇒ nil
The set_background_color method is used to set the background color for the webdialog.
-
#set_file(filename, path = nil) ⇒ nil
The #set_file method is used to identify a local HTML file to display in the webdialog.
-
#set_full_security ⇒ UI::WebDialog
The set_full_security method is used to place the
WebDialog
into a higher security mode where remote URLs and plugins (such as Flash) are not allowed inside the browser. -
#set_html(html_string) ⇒ nil
The set_html method is used to load a webdialog with a string of provided HTML.
-
#set_on_close { ... } ⇒ nil
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).
-
#set_position(left, top) ⇒ nil
The set_position method is used to set the position of the webdialog relative to the screen, in pixels.
-
#set_size(w, h) ⇒ nil
The set_size method is used to set the size of the webdialog, in pixels.
-
#set_url(url) ⇒ nil
The set_url method is used to load a webdialog with the content at a specific URL.
-
#show {|dialog| ... } ⇒ nil
The show method is used to display a non-modal dialog box.
-
#show_modal {|dialog| ... } ⇒ nil
The show_modal method is used to display a modal dialog box.
-
#write_image(image_path, option, top_left_x, top_left_y, bottom_right_x, bottom_right_y)
The write_image method is used to grab a portion of the web dialog screen and save the image to the given file path.
Constructor Details
.new(dialog_title = "", scrollable = true, pref_key = nil, width = 250, height = 250, left = 0, top = 0, resizable = true) ⇒ WebDialog
.new(properties) ⇒ WebDialog
WebDialog
.new(properties) ⇒ WebDialog
Since SU2017 the position and size of the dialog is DPI aware - it will scale to the DPI of the monitor automatically. Specify units as they would be on a traditional low-DPI monitor.
The browser which is embedded inside the dialog depends on the user’s OS. On Mac, Safari is embedded, while on the PC whatever version of Internet Explorer is installed will be embedded.
The new
method is used to create a new webdialog.
Instance Attribute Details
#max_height ⇒ Integer
(rw)
The max_height method is used to get the maximum height that the user is allowed to resize the dialog to.
#max_height=(height) ⇒ Integer
(rw)
As of SU2017 this will automatically scale the height by the same factor as UI.scale_factor.
The max_height= method is used to set the maximum height that the user is allowed to resize the dialog to.
#max_width ⇒ Integer
(rw)
The max_width method is used to get the maximum width that the user is allowed to resize the dialog to.
#max_width=(width) ⇒ Integer
(rw)
As of SU2017 this will automatically scale the width by the same factor as UI.scale_factor.
The max_width= method is used to set the maximum width that the user is allowed to resize the dialog to.
#min_height ⇒ Integer
(rw)
The min_width method is used to get the minimum height that the user is allowed to resize the dialog to.
#min_height=(height) ⇒ Integer
(rw)
As of SU2017 this will automatically scale the height by the same factor as UI.scale_factor.
The min_height= method is used to set the minimum height that the user is allowed to resize the dialog to.
#min_width ⇒ Integer
(rw)
The min_width method is used to get the minimum width that the user is allowed to resize the dialog to.
#min_width=(width) ⇒ Integer
(rw)
As of SU2017 this will automatically scale the width by the same factor as UI.scale_factor.
The min_width= method is used to set the minimum width that the user is allowed to resize the dialog to.
#visible? ⇒ Boolean
(readonly)
The visible? method is used to tell if the webdialog is currently shown.
Instance Method Details
#add_action_callback(callback_name) {|dialog, params| ... } ⇒ Object
The add_action_callback method establishes a Ruby callback method that your web dialog can call to perform some function.
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.
Note that you’re sending data down to Ruby as a single string that’s passed via the window.location bar. In Internet Explorer on PC, there is a length limit of 2038 characters for this bar, so if you’re needing to pass large data down you might consider using get_element_value to pull in a longer string from a hidden input field in the HTML.
#allow_actions_from_host(hostname) ⇒ Boolean
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.
#bring_to_front ⇒ WebDialog
The bring_to_front method is used to bring the webdialog to the front of all the windows on the desktop. See show_modal for how to ensure that your WedDialogs are on top.
#close ⇒ nil
The close method is used to close the webdialog.
#execute_script(script) ⇒ Boolean
The execute_script method is used to execute a JavaScript string on the web dialog.
#get_default_dialog_color ⇒ String
The get_default_dialog_color method is used to get the default dialog color for the web dialog.
#get_element_value(element_id) ⇒ String
The get_element_value method is used to get a value, with a given element_id, from the web dialog’s DOM.
#post_url(url, data) ⇒ nil
The post_url method is used to send the data to a url using the HTTP POST method.
#screen_scale_factor ⇒ Float
The screen_scale_factor method returns the ratio of screen pixels to logical window units (called ‘points’ on Mac) for the screen this WebDialog
is currently in. On a retina screen Mac, this ratio will be greater than 1.0. On Windows this always return 1.0.
#set_background_color(color) ⇒ nil
The set_background_color method is used to set the background color for the webdialog.
#set_file(filename, path = nil) ⇒ nil
The #set_file
method is used to identify a local HTML file to display in the webdialog.
#set_full_security ⇒ WebDialog
The set_full_security method is used to place the WebDialog
into a higher security mode where remote URLs and plugins (such as Flash) are not allowed inside the browser. This defaults to false when a new WebDialog
is created.
#set_html(html_string) ⇒ nil
The set_html method is used to load a webdialog with a string of provided HTML.
#set_on_close { ... } ⇒ nil
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).
#set_position(left, top) ⇒ nil
As of SU2017 this will automatically scale the x and y by the same factor as UI.scale_factor.
The set_position method is used to set the position of the webdialog relative to the screen, in pixels.
#set_size(w, h) ⇒ nil
As of SU2017 this will automatically scale the width and height by the same factor as UI.scale_factor.
The set_size method is used to set the size of the webdialog, in pixels.
#set_url(url) ⇒ nil
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.
#show {|dialog| ... } ⇒ nil
The show method is used to display a non-modal dialog box.
#show_modal {|dialog| ... } ⇒ nil
The show_modal method is used to display a modal dialog box. In SketchUp 6 and 7, this behaves differently on Mac vs. PC. On the PC, it shows a truly modal dialog, meaning so long as the WebDialog
is visible, no input can be performed elsewhere inside SketchUp. On the Mac, “modal” WebDialogs do not behave this way, but instead are “always on top” of other windows.
#write_image(image_path, option, top_left_x, top_left_y, bottom_right_x, bottom_right_y)
The write_image method is used to grab a portion of the web dialog screen and save the image to the given file path.