欢迎光临
我们一直在努力

ruby代码

 

 
WebDialog

 

 

 

WebDialog

SketchUp 6.0+

class

Parent: Object

Introduction

The Ruby WebDialog class allows you to create and interact with DHTML dialog
boxes from Ruby. This is the best way to generate complex, embedded UIs
inside SketchUp, but it does generally require HTML and Javascript expertise.

If your goal is to simply display a website to your users, consider using UI.getURL, 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:
http://sketchupapi.blogspot.com/2008/02/sharing-data-between-sketchup-ruby-and.html

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:
http://extensions.sketchup.com/en/content/advanced-camera-tools
The link would be:

 <a href="skp:launchEW@advanced-camera-tools">Get Advanced Camera Tools</a>

 

Methods

WebDialog.add_action_callbackSketchUp 6.0+
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.

Arguments:

callback_name
The name of the callback method to be invoked from the webdialog.
dialog
The dialog.
params
Any parameters passed to the dialog from HTML. This is passed as a single string.

Returns:

nil
 # In Ruby code...
 dlg.add_action_callback("ruby_messagebox") {|dialog, params|
   UI.messagebox("You called ruby_messagebox with: " + params.to_s)
 }

 # JavaScript inside the page loaded into the WebDialog:
 # window.location = 'skp:ruby_messagebox@Hello World';

 

WebDialog.allow_actions_from_hostSketchUp 6.0+
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.

Arguments:

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

Returns:

nil
 dialog.allow_actions_from_host("sketchup.com")

 

WebDialog.bring_to_frontSketchUp 6.0+
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.

Returns:

nil
 dialog.bring_to_front

 

WebDialog.closeSketchUp 6.0+
The close method is used to close the webdialog.

Returns:

nil
 dialog.close

 

WebDialog.execute_scriptSketchUp 6.0+
The execute_script method is used to execute a JavaScript string on the web
dialog.

Arguments:

script
The JavaScript script to execute on the webdialog.

Returns:

nil
 js_command = "document.getElementById('id').innerHTML = 'Hi!'"
 dialog.execute_script(js_command)

 

WebDialog.get_default_dialog_colorSketchUp 6.0+
The get_default_dialog_color method is used to get the default dialog color
for the web dialog.

Returns:

color
a six digit hexidecimal number representing the
color
 dialog.get_default_dialog_color
 #ece9d8

 

WebDialog.get_element_valueSketchUp 6.0+
The get_element_value method is used to get a value, with a given
element_id, from the web dialog’s DOM.

Arguments:

element_id
The name of the element in your HTML code.

Returns:

String containing the retrieved value.
 # In Ruby code:
 dialog.get_element_value("myTextInput")

 # In webdialog's HTML:
 <input type="text" id="myTextInput" value="hello"/>

 

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

Returns:

height
the maximum height in pixels
 max = dialog.max_height

 

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

Arguments:

width
The maximum height in pixels

Returns:

nil
 dialog.max_height = 400

 

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

Returns:

width
the maximum width in pixels
 max = dialog.max_width

 

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

Arguments:

width
The maximum width in pixels

Returns:

nil
 dialog.max_width = 500

 

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

Returns:

height
the minimum height in pixels
 min = dialog.min_height

 

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

Arguments:

width
The minimum height in pixels

Returns:

nil
 dialog.min_height = 100

 

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

Returns:

width
the minimum width in pixels
 min = dialog.min_width

 

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

Arguments:

width
The minimum width in pixels

Returns:

nil
 dialog.min_width = 200

 

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.

Arguments:

nav_buttons
true to hide the buttons, false to show them

Returns:

dialog
the updated WebDialog
 dialog.navigation_buttons_enabled = false

 

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.

Returns:

nav_buttons
true if the buttons are visible.
 nav_buttons = dialog.navigation_buttons_enabled?

 

WebDialog.newSketchUp 6.0+
The new method is used to create a new webdialog.

Default width is 250. Default height is 250. Default left is 0. Default top
is 0. WebDialogs are resizable by default.

Note that 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.

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.
pref_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.
top
The number of pixels from the top.
resizable
true if you want the webdialog to be resizable, false if not.

Returns:

dialog
the newly created WebDialog object.
 dlg = UI::WebDialog.new("Show sketchup.com", true,
   "ShowSketchupDotCom", 739, 641, 150, 150, true);
 dlg.set_url "http://www.sketchup.com"
 dlg.show

 

WebDialog.post_urlSketchUp 6.0+
The post_url method is used to send the data to a url using the HTTP POST
method.

Arguments:

url
The url to send the data.
data
The data to be sent.

Returns:

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

 

WebDialog.screen_scale_factorSketchUp 2014+
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.

Returns:

screen scale factor
 factor = dialog.screen_scale_factor

 

WebDialog.set_background_colorSketchUp 6.0+
The set_background_color method is used to set the background color for the
webdialog.

Arguments:

color
A six digit hexidecimal color.

Returns:

nil
 dlg.set_background_color("f3f0f0")

 

WebDialog.set_fileSketchUp 6.0+
The set_file method is used to identify a local HTML file to display in the
webdialog.

Arguments:

filename
The filename for the webdialog file (HTML file).
path
(optional) A path that filename is relative to.

Returns:

nil
 dialog.set_file "c:\\mypage.html"

 

WebDialog.set_full_securitySketchUp 7.0+
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.

Returns:

dialog
the updated WebDialog
 dialog.set_full_security

 

WebDialog.set_htmlSketchUp 6.0+
The set_html method is used to load a webdialog with a string of provided
HTML.

Arguments:

html_string
A string of valid html to display in your webdialog.

Returns:

nil
 html= 'Hello world!'
 dialog.set_html(html)

 

WebDialog.set_on_closeSketchUp 6.0+
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).

Arguments:

block
Ruby block to perform when the dialog closes.

Returns:

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

 

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

Arguments:

left
The number of pixels from the left.
top
The number of pixels from the top of the screen.

Returns:

nil
 dialog.set_position(100,50)

 

WebDialog.set_sizeSketchUp 6.0+
The set_size method is used to set the size of the webdialog, in pixels.

Arguments:

w
Width of the webdialog.
h
Height of the webdialog.

Returns:

nil
 dialog.set_size(320,240)

 

WebDialog.set_urlSketchUp 6.0+
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.

Arguments:

url
The URL for a specific web site.

Returns:

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

 

WebDialog.showSketchUp 6.0+
The show method is used to display a non-modal dialog box.

Arguments:

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

Returns:

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

 

WebDialog.show_modalSketchUp 6.0+
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.

Arguments:

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

Returns:

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

 

WebDialog.visible?SketchUp 6.0+
The visible? method is used to tell if the webdialog is currently shown.

Returns:

visibility
true if visible.
 vis = dialog.visible?

 

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

Arguments:

image_path
The destination path of the saved image.
option
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
The x coordinate of the upper left corner of the region to grab.
top_left_y
The x coordinate of the upper left corner of the region to grab.
bottom_right_x
The x coordinate of the lower right corner of the region to grab.
bottom_right_y
The x coordinate of the lower right corner of the region to grab.
 dialog.write_image('c:/grab.jpg', 70, 0, 0, 100, 100)
 dialog.write_image('c:/grab.png', 4, 0, 0, 100, 100)

 

 

本站资源来源于互联网和网友分享,版权归原作者所有图南素材 » ruby代码

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
_×
广而告之: