Class: UI::WebDialog废弃的

继承于:
Object
  • Object
显示所有

概述

废弃了。

请使用HtmlDialog that was introduced in SketchUp 2017.

Ruby WebDialog类允许你在Ruby中创建DHTML对话框并与之互动。

如果你的目标是向你的用户简单地显示一个网站,可以考虑使用openURL,这将在他们的默认浏览器中显示一个网页,而不是在SketchUp的对话框中。

请看这篇博文,里面有一个详细的、分步骤的例子。sketchupapi.blogspot.com/2008/02/sharing-data-between-sketchup-ruby-and.html

在Windows下,IE在webdialogs的渲染模式与你在普通浏览器中看到的不同。它默认会选择一个较早的渲染模式,不同版本的SketchUp会使用不同的模式。为了可靠地控制您在 Windows 下的 webdialogs 的渲染模式,您需要插入一个特殊的 META 兼容性标签。

// 始终强制使用最新的版本: <meta http-equiv="X-UA-Compatible" content="IE=edge"/> // 锁定一个特定的IE版本: <meta http-equiv="X-UA-Compatible" content="IE=8" />

从SketchUp 2013开始,您可以在您的对话框中嵌入一个特殊的HTML链接,以启动扩展仓库并显示指定的扩展页面。如果你的扩展与另一个扩展有依赖关系,并且你想引导用户安装该扩展,那么这就很有用。

例如,要启动一个扩展的页面,其URL是。extensions.sketchup.com/en/content/advanced-camera-tools该链接将是:

例子:

<a href="skp:[email protected]">获取高级相机工具</a>。

版本:

  • SketchUp 6.0

实例方法总结# collapse

构造函数细节

#initialize(dialog_title = "", scrollable = true, pref_key = nil, width = 250, height = ) ⇒Object #initialize(properties) ⇒UI::WebDialog

注意:

自从SU2017年以来,对话框的位置和大小都是DPI感知的--它将自动根据显示器的DPI缩放。指定的单位与传统的低DPI显示器上的一样。

注意:

嵌入对话框中的浏览器取决于用户的操作系统。在Mac上,Safari被嵌入,而在PC上,无论安装了什么版本的Internet Explorer都会被嵌入。

新的new方法被用来创建一个新的webdialog。

250, left = 0, top = 0, resizable = true)

@param [String] dialog_title [email protected] [Boolean] scrollable 如果你想允许滚动条,则为true;如果你不想允许滚动条,[email protected] [String, nil] pref_key 将保存对话框的位置和大小的注册表项。如果不包括preferences_key,[email protected] [Integer] width [email protected] [Integer] height [email protected] [Integer] left [email protected] [Integer] top [email protected] [Integer] resizable 如果你想让webdialog可调整大小,则为true;如果不想,[email protected] [UI::WebDialog]。

例子。

dlg = UI::WebDialog.new("显示sketchup.com", true,
  "ShowSketchupDotCom", 739, 641, 150, 150, true);
dlg.set_url "http://www.sketchup.com"
dlg.show

重载。

  • #initialize(properties) ⇒UI::WebDialog

    参数。

    • properties (Hash)&mdash。

      一个包含新创建的对话框的初始属性的哈希值。

    选项哈希(properties):

    • :dialog_title (String)
    • :preferences_key (String)
    • :scrollable (Boolean)
    • :resizable (Boolean) — 默认:true
    • :width (整数) — 默认:250
    • :height (整数) — 默认:250
    • :left (整数) — 默认:0
    • :top (整数) — 默认:0
    • :min_width (整数) — 默认值:0
    • :min_height (整数) — 默认值:0
    • :max_width (整数) — 默认值:-1
    • :max_height (整数) — 默认值:-1
    • :full_security (整数) — 默认。false
    • :mac_only_use_nswindow (整数) — 默认:false

    版本:

    • SketchUp 7.0

版本:

  • SketchUp 6.0

实例方法详情

#add_action_callback(callback_name) {|dialog, params| ... } ⇒Object

add_action_callback方法建立了一个Ruby回调方法,你的网页对话框可以调用它来执行一些功能。

使用skp:callback_method_name来从你的webdialog调用回调方法。你在webdialog中的JavaScript将用一个代表回调方法参数的字符串来调用回调方法。

请注意,你是以一个字符串的形式向Ruby发送数据,该字符串通过window.location bar传递。在PC上的Internet Explorer中,这个栏的长度限制为2038个字符,所以如果你需要传递大量的数据,你可以考虑使用get_element_value来从HTML中的隐藏输入字段拉入一个较长的字符串。

例子:

# 在Ruby代码中...dlg.add_action_callback("ruby_messagebox") {|dialog, params|
  UI.messagebox("你调用ruby_messagebox时使用了:" + params.to_s)
}

# 页面内的JavaScript被加载到WebDialog中。# window.location = 'skp:[email protected] World';

返回nil。

Parameters:

  • callback_name

    The name of the callback method to be invoked from the webdialog.

Yields:

  • (dialog,params)

Yield Parameters:

  • dialog

    The dialog.

  • params

    Any parameters passed to the dialog from HTML. This is passed as a single string.

Returns:

  • nil

Version:

  • SketchUp 6.0

#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.

Examples:

dialog.allow_actions_from_host("sketchup.com")

Parameters:

  • hostname (String)

    The name (domain) of the host that your webdialog can access safely.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#bring_to_frontUI::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.

Examples:

dialog.bring_to_front

Returns:

Version:

  • SketchUp 6.0

#closenil

The close method is used to close the webdialog.

Examples:

dialog.close

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#execute_script(script) ⇒Boolean

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

Examples:

js_command = "document.getElementById('id').innerHTML = '<b>Hi!</b>'"
dialog.execute_script(js_command)

Parameters:

  • script (String)

    The JavaScript script to execute on the webdialog.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#get_default_dialog_colorString

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

Examples:

dialog.get_default_dialog_color
#ece9d8

Returns:

  • (String)

    a six digit hexidecimal number representing the color

Version:

  • SketchUp 6.0

#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.

Examples:

# In Ruby code: dialog.get_element_value("myTextInput") # In webdialog's HTML: <input type="text" id="myTextInput" value="hello">

Parameters:

  • element_id (String)

    The name of the element in your HTML code.

Returns:

  • (String)

    a string containing the retrieved value.

Version:

  • SketchUp 6.0

#max_heightInteger

The max_height method is used to get the maximum height that the user is allowed to resize the dialog to.

Examples:

max = dialog.max_height

Returns:

  • (Integer)

    the maximum height in pixels

Version:

  • SketchUp 7.0

#max_height=(height) ⇒Integer

Note:

As of SU2017 this will automatically scale the height by the same factor asUI.scale_factor.

The max_height= method is used to set the maximum height that the user is allowed to resize the dialog to.

Examples:

dialog.max_height = 400

Parameters:

  • height (Integer)

    The maximum height in pixels

Returns:

  • (Integer)

Version:

  • SketchUp 7.0

#max_widthInteger

The max_width method is used to get the maximum width that the user is allowed to resize the dialog to.

Examples:

max = dialog.max_width

Returns:

  • (Integer)

    the maximum width in pixels

Version:

  • SketchUp 7.0

#max_width=(width) ⇒Integer

Note:

As of SU2017 this will automatically scale the width by the same factor asUI.scale_factor.

The max_width= method is used to set the maximum width that the user is allowed to resize the dialog to.

Examples:

dialog.max_width = 500

Parameters:

  • width (Integer)

    The maximum width in pixels

Returns:

  • (Integer)

Version:

  • SketchUp 7.0

#min_heightInteger

The min_width method is used to get the minimum height that the user is allowed to resize the dialog to.

Examples:

min = dialog.min_height

Returns:

  • (Integer)

    the minimum height in pixels

Version:

  • SketchUp 7.0

#min_height=(height) ⇒Integer

Note:

As of SU2017 this will automatically scale the height by the same factor asUI.scale_factor.

The min_height= method is used to set the minimum height that the user is allowed to resize the dialog to.

Examples:

dialog.min_height = 100

Parameters:

  • height (Integer)

    The minimum height in pixels

Returns:

  • (Integer)

Version:

  • SketchUp 7.0

#min_widthInteger

The min_width method is used to get the minimum width that the user is allowed to resize the dialog to.

Examples:

min = dialog.min_width

Returns:

  • (Integer)

    the minimum width in pixels

Version:

  • SketchUp 7.0

#min_width=(width) ⇒Integer

Note:

As of SU2017 this will automatically scale the width by the same factor asUI.scale_factor.

The min_width= method is used to set the minimum width that the user is allowed to resize the dialog to.

Examples:

dialog.min_width = 200

Parameters:

  • width (Integer)

    The minimum width in pixels

Returns:

  • (Integer)

Version:

  • SketchUp 7.0

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. This method has no use on the PC, as these buttons are never displayed.

Examples:

dialog.navigation_buttons_enabled = false

Returns:

  • (Boolean)

Version:

  • SketchUp 7.0

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. This method has no use on the PC, as these buttons are never displayed.

On the mac, this defaults to true for new WebDialogs.

Examples:

nav_buttons = dialog.navigation_buttons_enabled?

Returns:

  • (Boolean)

Version:

  • SketchUp 7.0

#post_url(url, data) ⇒nil

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

Examples:

data = dialog.post_url("http://www.mydomain.com/formchecker.cgi",data)

Parameters:

  • url (String)

    The url to send the data.

  • data (String)

    The data to be sent.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#screen_scale_factorFloat

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.

Examples:

factor = dialog.screen_scale_factor

Returns:

  • (Float)

    screen scale factor

Version:

  • SketchUp 2014

#set_background_color(color) ⇒nil

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

Examples:

dlg.set_background_color("f3f0f0")

Parameters:

  • color (String)

    A six digit hexidecimal color.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#set_file(filename, path = nil) ⇒nil

The#set_filemethod is used to identify a local HTML file to display in the webdialog.

Examples:

file = File.join(__dir__, 'mypage.html')
dialog.set_file(file)

Parameters:

  • filename (String)

    The filename for the webdialog file (HTML file).

  • path (String) (defaults to:nil)

    A path that filename is relative to.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#set_full_securityUI::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.

Examples:

dialog.set_full_security

Returns:

Version:

  • SketchUp 7.0

#set_html(html_string) ⇒nil

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

Examples:

html= '<b>Hello world!</b>'
dialog.set_html(html)

Parameters:

  • html_string (String)

    A string of valid html to display in your webdialog.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#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).

Examples:

dialog.set_on_close{ UI.messagebox("Closing the webDialog") }

Yields:

  • Ruby block to perform when the dialog closes.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#set_position(left, top) ⇒nil

Note:

As of SU2017 this will automatically scale the x and y by the same factor asUI.scale_factor.

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

Examples:

dialog.set_position(100,50)

Parameters:

  • left (Integer)

    The number of pixels from the left.

  • top (Integer)

    The number of pixels from the top of the screen.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#set_size(w, h) ⇒nil

Note:

As of SU2017 this will automatically scale the width and height by the same factor asUI.scale_factor.

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

Examples:

dialog.set_size(320,240)

Parameters:

  • w (Integer)

    Width of the webdialog.

  • h (Integer)

    Height of the webdialog.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#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.

Examples:

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

Parameters:

  • url (String)

    The URL for a specific web site.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#show{|dialog| ... } ⇒nil

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

Examples:

dialog.show {
  dialog.execute_script("alert(10)");
}

Yields:

  • (dialog)

    (optional) Ruby code to perform when the dialog is first displayed.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#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.

Examples:

dialog.show_modal {
  dialog.execute_script("alert(10)");
}

Yields:

  • (dialog)

    (optional) Ruby code to perform when the dialog is first displayed.

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#visible?Boolean

The visible? method is used to tell if the webdialog is currently shown.

Examples:

vis = dialog.visible?

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#write_image(image_path, option, top_left_x, top_left_y, bottom_right_x, bottom_right_y) ⇒Object

The write_image method is used to grab a portion of the web dialog screen and save the image to the given file path.

Examples:

dialog.write_image('c:/grab.jpg', 70, 0, 0, 100, 100)
dialog.write_image('c:/grab.png', 4, 0, 0, 100, 100)

Parameters:

  • image_path (String)

    The destination path of the saved image.

  • option (Integer)

    Specifies what method to use when saving the image. For JPG/JPEG images, this specifies the image quality and can range from 1 to 100. For PNG images this specifies the compression algorithm: <4 (best speed), 4-8 (default), or >=9 (best compression).

  • top_left_x (Integer)

    The x coordinate of the upper left corner of the region to grab.

  • top_left_y (Integer)

    The x coordinate of the upper left corner of the region to grab.

  • bottom_right_x (Integer)

    The x coordinate of the lower right corner of the region to grab.

  • bottom_right_y (Integer)

    The x coordinate of the lower right corner of the region to grab.

Version:

  • SketchUp 7.1