Class: UI::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/sketchup-api-stubs/stubs/UI/Notification.rb

Overview

UI::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

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



119
120
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 119

def initialize(sketchup_extension, message, icon_name, icon_tooltip)
end

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



41
42
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 41

def icon_name
end

#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



58
59
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 58

def icon_name=(icon_name)
end

#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



72
73
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 72

def icon_tooltip
end

#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



89
90
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 89

def icon_tooltip=(icon_tooltip)
end

#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



132
133
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 132

def message
end

#message=(message) ⇒ Boolean

Sets a new message. Notifications are meant for quick & brief messages. Remember that they disappear 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



149
150
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 149

def message=(message)
end

#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



178
179
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 178

def on_accept(title, block)
end

#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



193
194
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 193

def on_accept_title
end

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



224
225
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 224

def on_dismiss(title, block)
end

#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



239
240
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 239

def on_dismiss_title
end

#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

Returns:

  • (Boolean)

Version:

  • SketchUp 2017



252
253
# File 'lib/sketchup-api-stubs/stubs/UI/Notification.rb', line 252

def show
end