123456789_123456789_123456789_123456789_123456789_

Class: UI::Notification

Relationships
Inherits: Object

Overview

Notification objects allows you to show native notifications in the desktop. Notifications can have a message, icon and accept and/or dismiss buttons with callback blocks.

Examples:

# For consistency, the accept (yes) and the dismiss (no) buttons
# are always displayed in the same order.
message = "A new version of pizza is available. Install now?"
@notification = UI::Notification.new(sketchup_extension, message)
@notification.on_accept("Pizza!") { puts "Pizza" }
@notification.on_dismiss("No thanks") { puts "No pizza" }
@notification.show

# The two options are however not treated differently by SketchUp and can
# also be used for questions with no strict yes/no answer.
message = "Pizza clashes with health. Select which one to keep."
@notification = UI::Notification.new(sketchup_extension, message)
@notification.on_accept("Pizza") { puts "Pizza" }
@notification.on_dismiss("Health") { puts "Salad" }
@notification.show

Version:

  • SketchUp 2017

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(sketchup_extension, message = nil, icon_name = nil, icon_tooltip = nil) ⇒ Notification

Note:

In order to insert line breaks into the message you need to use \r\n.

Creates a new Notification object.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world", "/path/to/icon",
    "Icon Tooltip")
@notification.show

Parameters:

  • sketchup_extension (SketchupExtension)

    ::SketchupExtension instance used to identify the source of the notification.

  • message (String) (defaults to: nil)

    Message to display.

  • icon_name (String) (defaults to: nil)

    Path to an icon to display along with the message.

  • icon_tooltip (String) (defaults to: nil)

    Tooltip for the icon.

Version:

  • SketchUp 2017

Instance Attribute Details

#icon_nameString (rw)

Gets the icon name, this is the path that will be used to get the icon from the file system path.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world", "/path/to/icon",
    "Icon Tooltip")
puts "Icon Name: #{@notification.icon_name}"
@notification.show

Version:

  • SketchUp 2017

#icon_name=(icon_name) ⇒ Boolean (rw)

Sets the icon path, this icon will be loaded from the path give, the path has to be a local filesystem path.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.icon_name = "/path/to/icon"
@notification.show

Parameters:

Version:

  • SketchUp 2017

#icon_tooltipString (rw)

Gets the icon Tooltip, this is the string that appear when the mouse is over the icon.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world", "/path/to/icon",
    "Icon Tooltip")
puts "Tooltip: #{@notification.icon_tooltip}"
@notification.show

Version:

  • SketchUp 2017

#icon_tooltip=(icon_tooltip) ⇒ Boolean (rw)

Sets the icon Tooltip, this string will appear when the mouse is over the icon.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.icon_tooltip = "icon Tooltip"
@notification.show

Parameters:

Version:

  • SketchUp 2017

#messageString (rw)

Gets the message as string.

Examples:

@notification = UI::Notification.new(sketchup_extension)
puts "This is the current message: #{@notification.message}"
@notification.show

Version:

  • SketchUp 2017

#message=(message) ⇒ Boolean (rw)

Note:

In order to insert line breaks into the message you need to use \r\n.

Sets a new message. Notifications are meant for quick and brief messages. These message disappear automatically after a short while if they are not interacted with.

Examples:

@notification = UI::Notification.new(sketchup_extension)
@notification.message = "Hello world"
@notification.show

Parameters:

Version:

  • SketchUp 2017

Instance Method Details

#on_accept(title, block) ⇒ Boolean

Shows a button in the notification with the given title and callback block, both arguments are required.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.on_accept("Accept")  do |notification, title|
   puts "The user pressed [#{title}] with message #{notification.message}"
end
@notification.show

Parameters:

  • title (String)

    Sets the title of the button.

  • block (Proc)

    Sets the action callback, this will be called when the user clicks on the dismiss button.

Raises:

  • (RuntimeError)

    When calling on_accept when the notification has already been shown.

Version:

  • SketchUp 2017

#on_accept_titleString

Returns the accept’s button title.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.on_accept("Accept")  do |notification, title|
   puts "The user pressed #{notification.on_accept_title}"
end
@notification.show

Version:

  • SketchUp 2017

#on_dismiss(title, block) ⇒ Boolean

Shows a button in the notification with the given title and callback block. Both arguments are required. This callback is only called if you press the Dismiss button, not when the time runs out and the notification automatically disappears.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.on_dismiss("Close")  do |notification, title|
   puts "The user pressed [#{title}] with message #{notification.message}"
end
@notification.show

Parameters:

  • title (String)

    Sets the title of the button.

  • block (Proc)

    Sets the action callback, this will be called when the user clicks on the dismiss button.

Raises:

  • (RuntimeError)

    When calling on_dismiss when the notification has already been shown.

Version:

  • SketchUp 2017

#on_dismiss_titleString

Returns the dismiss’s button title.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.on_dismiss("Close")  do |notification, title|
   puts "The user pressed #{notification.on_dismiss_title}"
end
@notification.show

Version:

  • SketchUp 2017

#showBoolean

Shows the notification. If not interacted with, the notification will disappear without calling any callbacks.

Examples:

@notification = UI::Notification.new(sketchup_extension, "Hello world")
@notification.show

Version:

  • SketchUp 2017