Module: Zerenity

Defined in:
lib/zerenity/base.rb,
lib/zerenity/info.rb,
lib/zerenity/list.rb,
lib/zerenity/entry.rb,
lib/zerenity/error.rb,
lib/zerenity/scale.rb,
lib/zerenity/warning.rb,
lib/zerenity/calendar.rb,
lib/zerenity/progress.rb,
lib/zerenity/question.rb,
lib/zerenity/textinfo.rb,
lib/zerenity/messagedialog.rb,
lib/zerenity/colorselection.rb

Overview

Zerenity provides a number of simple graphical dialogs.

Global Options

:title

The text displayed in the title bar.

:text

The text that will be displayed in the dialog (if needed).

:activatesDefault

If set to false disables the firing of the OK button when the Enter key is pressed.

Defined Under Namespace

Classes: Base, Calendar, ColorSelection, Entry, Error, Info, List, MessageDialog, Progress, ProgressProxy, Question, Scale, TextInfo, Warning

Constant Summary collapse

CLICKED =
"clicked"

Class Method Summary collapse

Class Method Details

.Calendar(options = {}) ⇒ Object

Creates a calendar dialog allowing the user to select a date. Returns a Time object representing the selected date or nil if Cancel is clicked.

Example Usage

date = Zerenity::Calendar(:text=>"Please select a date")


10
11
12
# File 'lib/zerenity/calendar.rb', line 10

def self.Calendar(options={})
  Calendar.run(options)
end

.ColorSelection(options = {}) ⇒ Object

Displays a color selection dialog. Returns the value of the color selected as #rrrrggggbbbb, where r, g and b are hex digits representing the red, green and blue components respectively

====Example Usage:
 Zereity::ColorSelection( :title => "Select a color" )


10
11
12
# File 'lib/zerenity/colorselection.rb', line 10

def self.ColorSelection( options = {} )  
  ColorSelection.run( options )
end

.Entry(options = {}) ⇒ Object

Displays a text entry box. Returns the text entered or nil if Cancel is pressed.

Options

:password

When set to true all all characters in the text entry area will be masked by the ‘*’ character.

Example Usage

name = Zerenity::Entry(:text=>"Please enter your name.")


12
13
14
# File 'lib/zerenity/entry.rb', line 12

def self.Entry(options={})
    Entry.run(options)
end

.Error(options = {}) ⇒ Object

Displays an error dialog.

Example Usage

Zerenity::Error(:text=>"An error has occured. Please check the system log.")


7
8
9
# File 'lib/zerenity/error.rb', line 7

def self.Error(options={})
  Error.run(options)
end

.Info(options = {}) ⇒ Object

Displays an informational popup dialog on the screen.

Examle Usage

Zerenity::Info(:text=>"Processing has completed.")


8
9
10
# File 'lib/zerenity/info.rb', line 8

def Zerenity::Info(options={})
  Info.run(options)
end

.List(options = {}) ⇒ Object

Displays a list dialog on the screen. Items in the list can be selected. Returns the rows which were selected or nil if Cancel is clicked.

Options

:columns

The names which will be displayed at the top og

each column. This option is mandatory.
:data

The data for the list, with each row being another array.

:radiolist

If this is set true the first column of the list will be rendered as a radiobutton. The first element of every data array should either be a true or false.

:checklist

If this is set true the first column of the list will be rendered as a checkbox. The first element of every data array should either be a true or false. When this is set mutiple rows can be selected and an array of selected rows are returned.

Note :radiolist and :checklist are mutually exclusive. If both are set true an exception is thrown. An exception is also thrown if the data rows are not equal length or they differ in length with the number of columns.

Example Usage

choice = Zerenity::List(:columns=>["Food","Energy"],:data=>[["Chips","200KJ"],["Chocolate","300KJ"]])


28
29
30
# File 'lib/zerenity/list.rb', line 28

def self.List(options={})
  List.run(options)
end

.Progress(options = {}, &block) ⇒ Object

Displays a progress bar which can be updated via a processing block which is passed a ProgressProxy object.

Options

:autoClose

The dialog will automatically close once the progressing block is complete.

:cancellable

If set to true the Cancel button is enabled and the ProgressProxy#cancelled? will be set to true if it is clicked. It is the responsibility of the processing block to monitor this attribute and perfom the necessary actions when it is ckicked.

Example Usage

Zerenity::Progress(:text=>"Processing...",:cancellable=>true,:title=>"Processing Files") do |progress|
  files.each_with_index do |file,index|
     progress.cancelled ? break : nil
     process_file(file)
     progress.update(index/files.size,"#{((index/files.size)*100).round}% Complete")
  end  
  if progress.cancelled?
    progress.text = "Cleaning up..."
    cleanup_files(files)
  end
end


27
28
29
# File 'lib/zerenity/progress.rb', line 27

def self.Progress(options={},&block)
  Progress.run(options,&block)
end

.Question(options = {}) ⇒ Object

Displays a question dialog. Returns true if OK is clicked, false if Cancel is clicked.

Example Useage

if Zerenity::Question(:text=>"Continue processing?")
  post_process_files()
end


11
12
13
# File 'lib/zerenity/question.rb', line 11

def self.Question(options={})
  Question.run(options)
end

.Scale(options = {}) ⇒ Object

Displays a sliding scale. Returns the value selected or nil if cancel is pressed.

Options

:min

The minimum value of the sliding scale. Defaults to 0.

:max

The maximum value of the sliding scale. Defaults to 100.

:step

The size of the value increment of the sliding scale for keyboard shortcuts. Defaults to 1.

:initial

The initial value of the sliding scale. Defaults to 0.

Example Usage

value = Zerenity::Scale(:text=>"Please select a value", :min => 1, :max => 250, :step => 3)


14
15
16
# File 'lib/zerenity/scale.rb', line 14

def self.Scale(options={})
  Scale.run(options)
end

.TextInfo(options = {}) ⇒ Object

Displays text in a multiline text info box.

Options

:editable

If set to true the text info box is editable.

:scrollable

If the size of the text does not fit in the height and width constraints, the text info box will become scrollable

:height,:width

The height and width of the text box, in pixels. Note this is not the height and weidth of the full window.

:text

The text to be displayed in the text info box.

Example Usage

Zerenity::TextIfno(:text=>File.new($0).read)


17
18
19
# File 'lib/zerenity/textinfo.rb', line 17

def self.TextInfo(options={})
  TextInfo.run(options)
end

.Warning(options = {}) ⇒ Object

Displays a warning dialog on the screen.

Example Usage

Zerenity::Warning(:text=>"This operation can cause data corruption if interrupted")


8
9
10
# File 'lib/zerenity/warning.rb', line 8

def self.Warning(options={})
  Warning.run(options)
end