Class: Gtk::Dialog

Inherits:
Window
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk3/dialog.rb,
lib/gtk3/deprecated.rb

Instance Method Summary collapse

Methods inherited from Window

#application, #application=, auto_startup_notification=, #child, #child=, #close, #decorated, #decorated=, #decorated?, #default_height, #default_height=, default_icon_name, default_icon_name=, #default_widget, #default_widget=, #default_width, #default_width=, #deletable, #deletable=, #deletable?, #destroy, #destroy_with_parent, #destroy_with_parent=, #destroy_with_parent?, #display, #display=, #focus, #focus=, #focus_visible, #focus_visible=, #focus_visible?, #focus_widget, #focus_widget=, #fullscreen, #fullscreen_on_monitor, #fullscreened=, #fullscreened?, #get_default_size, #group, #handle_menubar_accel, #handle_menubar_accel=, #handle_menubar_accel?, #has_group, #hide_on_close, #hide_on_close=, #hide_on_close?, #icon_name, #icon_name=, interactive_debugging=, #is_active, #is_active=, #is_active?, #is_fullscreen, #is_maximized, #is_suspended, list_toplevels, #maximize, #maximized=, #maximized?, #minimize, #mnemonics_visible, #mnemonics_visible=, #mnemonics_visible?, #modal, #modal=, #modal?, #present, #present_with_time, #resizable, #resizable=, #resizable?, #set_default_size, #set_icon, #set_icon_raw, #startup_id=, #suspended=, #suspended?, #title, #title=, #titlebar, #titlebar=, toplevels, #transient_for, #transient_for=, #unfullscreen, #unmaximize, #unminimize

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_events, #add_events_raw, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #drag_dest_set, #drag_dest_set_raw, #drag_source_set, #drag_source_set_raw, #error_bell, #events, #events_raw, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #render_icon_pixbuf, #render_icon_pixbuf_raw, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_allocation, set_connect_func, set_connect_func_raw, #set_events, #set_events_raw, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #style_get_property, #style_get_property_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initialize(options = {}) ⇒ Gtk::Widget

Creates a new GtkDialog with the given title and transient parent.

The flags argument can be used to make the dialog modal, have it destroyed along with its transient parent, or make it use a headerbar.

Button text/response ID pairs should be listed in pairs, with a nil pointer ending the list. Button text can be arbitrary text. A response ID can be any positive number, or one of the values in the [enumGtk.ResponseType] enumeration. If the user clicks one of these buttons, GtkDialog will emit the [signalGtk.Dialog::response] signal with the corresponding response ID.

If a GtkDialog receives a delete event, it will emit ::response with a response ID of %GTK_RESPONSE_DELETE_EVENT.

However, destroying a dialog does not emit the ::response signal; so be careful relying on ::response when using the %GTK_DIALOG_DESTROY_WITH_PARENT flag.

Here’s a simple example:

GtkWindow *main_app_window; // Window the dialog should show up on
GtkWidget *dialog;
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_dialog_new_with_buttons ("My dialog",
                                      main_app_window,
                                      flags,
                                      _("_OK"),
                                      GTK_RESPONSE_ACCEPT,
                                      _("_Cancel"),
                                      GTK_RESPONSE_REJECT,
                                      NULL);

Parameters:

  • title (String)

    Title of the dialog

  • parent (Gtk::Window)

    Transient parent of the dialog

  • flags (Gtk::DialogFlags)

    from GtkDialogFlags

  • first_button_text (String)

    text to go in first button

  • array (Array)

    response ID for first button, then additional buttons, ending with nil



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gtk3/dialog.rb', line 20

def initialize(options={})
  initialize_raw

  title   = options[:title]
  parent  = options[:parent]
  flags   = options[:flags]
  buttons = options[:buttons]

  set_title(title) if title
  set_transient_for(parent) if parent
  if flags
    unless flags.is_a?(DialogFlags)
      flags = DialogFlags.new(flags)
    end
    set_modal(true) if flags.modal?
    set_destroy_with_parent(true) if flags.destroy_with_parent?
  end

  add_buttons(*buttons) if buttons
end

Instance Method Details

#add_action_widget(child, response_id) ⇒ nil

Adds an activatable widget to the action area of a GtkDialog.

GTK connects a signal handler that will emit the [signalGtk.Dialog::response] signal on the dialog when the widget is activated. The widget is appended to the end of the dialog’s action area.

If you want to add a non-activatable widget, simply pack it into the action_area field of the GtkDialog struct.

Parameters:

  • child (Gtk::Widget)

    an activatable widget

  • response_id (Integer)

    response ID for child

Returns:

  • (nil)

#add_button(text, response_id) ⇒ Gtk::Widget

Adds a button with the given text.

GTK arranges things so that clicking the button will emit the [signalGtk.Dialog::response] signal with the given response_id. The button is appended to the end of the dialog’s action area. The button widget is returned, but usually you don’t need it.

Parameters:

  • button_text (String)

    text of button

  • response_id (Integer)

    response ID for the button

Returns:

  • (Gtk::Widget)

    the GtkButton widget that was added



58
59
60
# File 'lib/gtk3/dialog.rb', line 58

def add_button(text, response_id)
  add_button_raw(text, ResponseType.resolve(response_id))
end

#add_button_rawGtk::Widget

Adds a button with the given text.

GTK arranges things so that clicking the button will emit the [signalGtk.Dialog::response] signal with the given response_id. The button is appended to the end of the dialog’s action area. The button widget is returned, but usually you don’t need it.

Parameters:

  • button_text (String)

    text of button

  • response_id (Integer)

    response ID for the button

Returns:

  • (Gtk::Widget)

    the GtkButton widget that was added



# File 'lib/gtk3/dialog.rb', line 57

#add_buttons(*buttons) ⇒ nil

Adds multiple buttons.

This is the same as calling [methodGtk.Dialog.add_button] repeatedly. The variable argument list should be nil-terminated as with [ctorGtk.Dialog.new_with_buttons]. Each button must have both text and response ID.

Parameters:

  • first_button_text (String)

    button text

  • array (Array)

    response ID for first button, then more text-response_id pairs

Returns:

  • (nil)


51
52
53
54
55
# File 'lib/gtk3/dialog.rb', line 51

def add_buttons(*buttons)
  buttons.each do |text, response_id|
    add_button(text, response_id)
  end
end

#content_areaGtk::Box

Returns the content area of dialog.

Returns:

  • (Gtk::Box)

    the content area GtkBox.

#get_response_for_widget(widget) ⇒ Integer

Gets the response id of a widget in the action area of a dialog.

Parameters:

  • widget (Gtk::Widget)

    a widget in the action area of dialog

Returns:

  • (Integer)

    the response id of widget, or %GTK_RESPONSE_NONE if widget doesn’t have a response id set.

#get_widget_for_response(response_id) ⇒ Gtk::Widget

Gets the widget button that uses the given response ID in the action area of a dialog.

Parameters:

  • response_id (Integer)

    the response ID used by the dialog widget

Returns:

  • (Gtk::Widget)

    the widget button that uses the given response_id



63
64
65
# File 'lib/gtk3/dialog.rb', line 63

def get_widget_for_response(response_id)
  get_widget_for_response_raw(ResponseType.resolve(response_id))
end

#get_widget_for_response_rawGtk::Widget

Gets the widget button that uses the given response ID in the action area of a dialog.

Parameters:

  • response_id (Integer)

    the response ID used by the dialog widget

Returns:

  • (Gtk::Widget)

    the widget button that uses the given response_id



# File 'lib/gtk3/dialog.rb', line 62

#header_barGtk::HeaderBar

Returns the header bar of dialog.

Note that the headerbar is only used by the dialog if the [propertyGtk.Dialog:use-header-bar] property is true.

Returns:

#initialize_rawGtk::Widget

Creates a new GtkDialog with the given title and transient parent.

The flags argument can be used to make the dialog modal, have it destroyed along with its transient parent, or make it use a headerbar.

Button text/response ID pairs should be listed in pairs, with a nil pointer ending the list. Button text can be arbitrary text. A response ID can be any positive number, or one of the values in the [enumGtk.ResponseType] enumeration. If the user clicks one of these buttons, GtkDialog will emit the [signalGtk.Dialog::response] signal with the corresponding response ID.

If a GtkDialog receives a delete event, it will emit ::response with a response ID of %GTK_RESPONSE_DELETE_EVENT.

However, destroying a dialog does not emit the ::response signal; so be careful relying on ::response when using the %GTK_DIALOG_DESTROY_WITH_PARENT flag.

Here’s a simple example:

GtkWindow *main_app_window; // Window the dialog should show up on
GtkWidget *dialog;
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_dialog_new_with_buttons ("My dialog",
                                      main_app_window,
                                      flags,
                                      _("_OK"),
                                      GTK_RESPONSE_ACCEPT,
                                      _("_Cancel"),
                                      GTK_RESPONSE_REJECT,
                                      NULL);

Parameters:

  • title (String)

    Title of the dialog

  • parent (Gtk::Window)

    Transient parent of the dialog

  • flags (Gtk::DialogFlags)

    from GtkDialogFlags

  • first_button_text (String)

    text to go in first button

  • array (Array)

    response ID for first button, then additional buttons, ending with nil

Returns:



# File 'lib/gtk3/dialog.rb', line 19

#response(response_id) ⇒ nil

Emits the ::response signal with the given response ID.

Used to indicate that the user has responded to the dialog in some way.

Parameters:

  • response_id (Integer)

    response ID

Returns:

  • (nil)

#runObject



42
43
44
45
46
47
48
49
# File 'lib/gtk3/dialog.rb', line 42

def run
  response_id = run_raw
  if response_id < 0
    ResponseType.new(response_id)
  else
    response_id
  end
end

#run_rawObject



41
# File 'lib/gtk3/dialog.rb', line 41

alias_method :run_raw, :run

#set_default_response(response_id) ⇒ Object Also known as: default_response=



68
69
70
# File 'lib/gtk3/dialog.rb', line 68

def set_default_response(response_id)
  set_default_response_raw(ResponseType.resolve(response_id))
end

#set_default_response_rawObject



67
# File 'lib/gtk3/dialog.rb', line 67

alias_method :set_default_response_raw, :set_default_response

#set_response_sensitive(response_id, setting) ⇒ nil

A convenient way to sensitize/desensitize dialog buttons.

Calls gtk_widget_set_sensitive (widget, <b>setting</b>) for each widget in the dialog’s action area with the given response_id.

Parameters:

  • response_id (Integer)

    a response ID

  • setting (Boolean)

    true for sensitive

Returns:

  • (nil)

#use_header_barInteger Also known as: use_header_bar_raw

true if the dialog uses a headerbar for action buttons instead of the action-area.

For technical reasons, this property is declared as an integer property, but you should only set it to true or false.

Creating a dialog with headerbar

Builtin GtkDialog subclasses such as [classGtk.ColorChooserDialog] set this property according to platform conventions (using the [propertyGtk.Settings:gtk-dialogs-use-header] setting).

Here is how you can achieve the same:

g_object_get (settings, "gtk-dialogs-use-header", &header, NULL);
dialog = g_object_new (GTK_TYPE_DIALOG, header, TRUE, NULL);

Returns:

  • (Integer)

    use-header-bar

#use_header_bar=(use_header_bar) ⇒ Integer

true if the dialog uses a headerbar for action buttons instead of the action-area.

For technical reasons, this property is declared as an integer property, but you should only set it to true or false.

Creating a dialog with headerbar

Builtin GtkDialog subclasses such as [classGtk.ColorChooserDialog] set this property according to platform conventions (using the [propertyGtk.Settings:gtk-dialogs-use-header] setting).

Here is how you can achieve the same:

g_object_get (settings, "gtk-dialogs-use-header", &header, NULL);
dialog = g_object_new (GTK_TYPE_DIALOG, header, TRUE, NULL);

Parameters:

  • use_header_bar (Integer)

Returns:

  • (Integer)

    use-header-bar

  • (Integer)

    use-header-bar

#use_header_bar?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/gtk3/dialog.rb', line 77

def use_header_bar?
  use_header_bar_raw != 0
end