Inputbox class

The Inputbox class makes it easy to create user input dialogs by providing a consistent interface to UI.inputbox for text fields and drop-down selections.

New updates 5/15/2009

* Access the values by name or by index.
* An each method to iterate the options.
* Reset fields to original values.
* Persistent storage using the Registry (or .plist file on Mac.)

Download inputbox.rb

Some examples of usage.


# my_plugin.rb
require 'inputbox'

# Create a new Inputbox. The name is used as part of the registry key.
# The registry key (if inputbox is saved) will be: "Inputbox_Unique Name"
@options = Inputbox.new("Unique Name")

@options.add("Name") # add a empty text input
@options.add("Age", 39) # a text input with 39 as the default value.
@options.add("Ruby", ["Beginner", "Intermediate", "Advanced"]) # Dropdown
@options.add("Sketchup", [1, 2, 3, 4, 5], 3) # dropdown, 3 as default

# Display the dialog
@options.show

# Access the options

# Iterate prompt, value pairs
@options.each { |k, v| puts "#{k.inspect} = #{v.inspect}" }

# By name
name = @options["Name"]

# By Index
age = @options[1]

# Persistent Storage
@options.save


Here's an example for creating the inputbox from registry values.

# my_plugin.rb
require 'inoutbox'

# Create
@options = Inputbox.new("Unique Name")

# Load
@options.load
if @options.prompts.empty?
  # Build Inputbox
  @options.add("Name")
end

# Display
# returns an Array of values
values = @options.show





No comments:

Popular Posts (Last 30 Days)