Top Level Namespace

Defined Under Namespace

Modules: GladeGUI, VR

Instance Method Summary collapse

Instance Method Details

#alert(message, options = {}) ⇒ String, ...

The alert method creates a pop-up alert in your program. It creates a modal window that halts execution of your code until the user closes it. Its great for displaying messages and debugging. It also has the option of displaying a text entry box for getting text input from the user. This small tool can save hundreds of lines of code in your programs. It can be used extesnively to display all types of messages and request all types of user input.

The alert box can disply 1, 2 or 3 buttons. The first button is denoted using the symbol: :button_yes button and is always displayed. You can add :button_no and :button_cancel.

If you want to add these buttons, just set their values to whatever text you want them to display and they will appear. Likewise, if you add the option, :input_text, a text entry box will appear.

There are many examples in the “alert_box” example project.

Examples:

alert("Continue?", button_no: "Nope", button_cancel: "Quit", parent: self) 
alert "The file you selected is already on disk.  Do you want to overwrite it?",
  headline: "Overwrite FIle?",
  button_yes: "Overwrite",
  button_no: "Reload From Disk",
  button_cancel: "Cancel"

Parameters:

  • message (String)

    text message to display in alert box. Uses markup.

  • options (Hash) (defaults to: {})

    – Hash of options: :button_yes => text on the button that returns true.

Options Hash (options):

  • :button_yes (String)

    Text that appears on the “yes” button.

  • :button_no (String)

    Text that appears on “no” button. (set to make no button appear)

  • :button_cancel (String)

    Text that appears on “cancel” button. (set to make cancel button appear)

  • :input_text (String)

    Text that appears in entry box. (set to make entry box appear)

  • :headline (String)

    Larger headline over text message.

  • :title (String)

    Title of the alert box window. Defaults to :headline.

  • :width (Integer)

    The width in pixels of the window. Used for wrapping text.

  • :parent (Object #builder)

    The window that the alert box is always on top of.

Returns:

  • (String)

    text in the text entry field when the :button_yes button is pressed

  • (true)

    When the :button_yes button is selected and there's no text entry box.

  • (false)

    When :button_no is pressed

  • (nil)

    When :button_cancel or the “X” button is pressed.



105
106
107
108
109
# File 'lib/Alert.rb', line 105

def alert(message, options = {})
  ans = VR::Alert::DialogAnswer.new()
  VR::Alert.new(message, ans, options).show_glade(options[:parent])
  return ans.answer 
end

#clear_eventsObject

Waits for all penting events to finish before continuing.



458
459
460
461
462
# File 'lib/GladeGUI.rb', line 458

def clear_events()  
  while (Gtk.events_pending?)
    Gtk.main_iteration
  end
end

#oinspect(obj = self) ⇒ Object

Displays object on screen and halts the program. Anywhere in your code you can halt the execution, and display an object in a window like this:

alert anyobject

Also, at any window, if you press the F8 key, the object inspector will run. Try it.

Parameters:

  • obj (Object) (defaults to: self)

    Any object that you want to display.

Returns:

  • none.



43
44
45
# File 'lib/oinspect/ObjectInspectorGUI.rb', line 43

def oinspect(obj=self)
  VR::ObjectInspector::ObjectInspectorGUI.new(obj).show_glade()
end