Class: UI::Notification

Inherits:
Object
  • Object
show all

Overview

UI::Notification objects allows you to show native notifications in the desktop, they are positioned in the top right of your screen, they can be customized to have a message, icon and accept and/or dismiss buttons with callback blocks.

Version:

  • SketchUp 2017

Instance Method Summary # collapse

Constructor Details

#initialize(sketchup_extension, message, icon_name, icon_tooltip) ⇒ UI::Notification

The new method is used to create a new UI::Notification.

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

Examples:

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

Parameters:

  • sketchup_extension (SketchupExtension)

    Required sketchup_extension to identify the sender.

  • message (String)

    Optionally assign the message.

  • icon_name (String)

    Optionally set a path to an image.

  • icon_tooltip (String)

    Optionally set an image tooltip.

Version:

  • SketchUp 2017

Instance Method Details

#icon_nameString

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

Returns:

Version:

  • SketchUp 2017

#icon_name=(icon_name) ⇒ Boolean

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:

  • icon_name (String)

    String providing the icon filesystem path.

Returns:

  • (Boolean)

Version:

  • SketchUp 2017

#icon_tooltipString

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

Returns:

Version:

  • SketchUp 2017

#icon_tooltip=(icon_tooltip) ⇒ Boolean

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:

  • icon_tooltip (String)

    String providing the new icon Tooltip.

Returns:

  • (Boolean)

Version:

  • SketchUp 2017

#messageString

Gets the message as string.

Examples:

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

Returns:

Version:

  • SketchUp 2017

#message=(message) ⇒ Boolean

Sets a new message, notifications are meant for quick & brief messages, remember that they are dismissed automatically.

Examples:

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

Parameters:

  • message (String)

    String providing the new message.

Returns:

  • (Boolean)

Version:

  • SketchUp 2017

#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 (Block)

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

Returns:

  • (Boolean)

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

Returns:

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.

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 (Block)

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

Returns:

  • (Boolean)

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

Returns:

Version:

  • SketchUp 2017

#showBoolean

Shows the notification in the top right of the screen, the notifications will be ordered from top to bottom if multiple notifications are shown, it will automatically be dismissed if no action is taken.

Examples:

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

Returns:

  • (Boolean)

Version:

  • SketchUp 2017