Class: Interphase::Dialog
- Defined in:
- lib/interphase/widgets/dialog.rb
Overview
A base class representing a simple, blank dialog box.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action_to_integer(action) ⇒ Object
Converts an
#add_button
action
symbol to the GTK RESPONSE integer which it represents. -
#add_button(text, action) ⇒ Object
Adds a button to the dialog box.
-
#initialize(instance = nil, **options, &block) ⇒ Dialog
constructor
Construct a new blank dialog box.
-
#run ⇒ Object
Run this dialog box.
Methods inherited from Widget
#destroy, #method_missing, #on, #respond_to_missing?, #show, #size
Constructor Details
#initialize(instance = nil, **options, &block) ⇒ Dialog
Construct a new blank dialog box.
9 10 11 12 13 |
# File 'lib/interphase/widgets/dialog.rb', line 9 def initialize(instance = nil, **, &block) super(instance || Gtk::Dialog.new, **, &block) ['buttons']&.map { |btn| (*btn) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Interphase::Widget
Instance Method Details
#action_to_integer(action) ⇒ Object
Converts an #add_button
action
symbol to the GTK RESPONSE integer which it represents.
action
-
The action symbol to convert. Should be one of the valid values of
action
to#add_button
.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/interphase/widgets/dialog.rb', line 19 def action_to_integer(action) valid_actions = %i[none reject accept delete ok cancel close yes no apply help] throw ArgumentError, 'Invalid button action' \ unless valid_actions.include? action # Map :delete to its GTK equivalent action = :delete_event if action == :delete Gtk::Dialog.const_get("RESPONSE_#{action.to_s.upcase}") end |
#add_button(text, action) ⇒ Object
Adds a button to the dialog box.
text
-
The text to display on the button.
action
-
The action which occurs when this button is clicked. Must be one of:
:none
,:reject
,:accept
,:delete
,:ok
,:cancel
,:close
,:yes
,:no
,:apply
,:help
.
37 38 39 40 |
# File 'lib/interphase/widgets/dialog.rb', line 37 def (text, action) gtk_instance.(text, action_to_integer(action)) nil end |
#run ⇒ Object
Run this dialog box. This call will block execution until the dialog is closed. Consider using Window#in_background if blocking is not desired. You should usually call destroy
after this method, otherwise the dialog will remain even after selecting an option.
46 47 48 |
# File 'lib/interphase/widgets/dialog.rb', line 46 def run gtk_instance.run end |