Class: Gtk::InfoBar

Inherits:
Widget
  • Object
show all
Defined in:
(unknown)

Overview

GtkInfoBar can be used to show messages to the user without a dialog.

An example GtkInfoBar

It is often temporarily shown at the top or bottom of a document. In contrast to [classGtk.Dialog], which has an action area at the bottom, GtkInfoBar has an action area at the side.

The API of GtkInfoBar is very similar to GtkDialog, allowing you to add buttons to the action area with [methodGtk.InfoBar.add_button] or [ctorGtk.InfoBar.new_with_buttons]. The sensitivity of action widgets can be controlled with [methodGtk.InfoBar.set_response_sensitive].

To add widgets to the main content area of a GtkInfoBar, use [methodGtk.InfoBar.add_child].

Similar to [classGtk.MessageDialog], the contents of a GtkInfoBar can by classified as error message, warning, informational message, etc, by using [methodGtk.InfoBar.set_message_type]. GTK may use the message type to determine how the message is displayed.

A simple example for using a GtkInfoBar:

GtkWidget *message_label;
GtkWidget *widget;
GtkWidget *grid;
GtkInfoBar *bar;

// set up info bar
widget = gtk_info_bar_new ();
bar = GTK_INFO_BAR (widget);
grid = gtk_grid_new ();

message_label = gtk_label_new ("");
gtk_info_bar_add_child (bar, message_label);
gtk_info_bar_add_button (bar,
                         _("_OK"),
                         GTK_RESPONSE_OK);
g_signal_connect (bar,
                  "response",
                  G_CALLBACK (gtk_widget_hide),
                  NULL);
gtk_grid_attach (GTK_GRID (grid),
                 widget,
                 0, 2, 1, 1);

// ...

// show an error message
gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!");
gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR);
gtk_widget_show (bar);

GtkInfoBar as GtkBuildable

GtkInfoBar supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs action_area).

GtkInfoBar supports adding action widgets by specifying “action” as the “type” attribute of a <child> element. The widget will be added either to the action area. The response id has to be associated with the action widget using the <action-widgets> element.

CSS nodes

GtkInfoBar has a single CSS node with name infobar. The node may get one of the style classes .info, .warning, .error or .question, depending on the message type. If the info bar shows a close button, that button will have the .close style class applied.

Instance Method Summary collapse

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(first_button_text, array) ⇒ Gtk::Widget

Creates a new GtkInfoBar with buttons.

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

Parameters:

  • first_button_text (String)

    ext to go in first button

  • array (Array)

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

Instance Method Details

#add_action_widget(child, response_id) ⇒ nil

Add an activatable widget to the action area of a GtkInfoBar.

This also connects a signal handler that will emit the [signalGtk.InfoBar::response] signal on the message area when the widget is activated. The widget is appended to the end of the message areas action area.

Parameters:

  • child (Gtk::Widget)

    an activatable widget

  • response_id (Integer)

    response ID for child

Returns:

  • (nil)

#add_button(button_text, response_id) ⇒ Gtk::Button

Adds a button with the given text.

Clicking the button will emit the [signalGtk.InfoBar::response] signal with the given response_id. The button is appended to the end of the info bar's action area. The button widget is returned, but usually you don't need it. that was added

Parameters:

  • button_text (String)

    text of button

  • response_id (Integer)

    response ID for the button

Returns:

#add_buttons(first_button_text, array) ⇒ nil

Adds multiple buttons.

This is the same as calling [methodGtk.InfoBar.add_button] repeatedly. The variable argument list should be nil-terminated as with [ctorGtk.InfoBar.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, ending with nil

Returns:

  • (nil)

#add_child(widget) ⇒ nil

Adds a widget to the content area of the info bar.

Parameters:

Returns:

  • (nil)

#default_response=(response_id) ⇒ nil

Sets the last widget in the info bar’s action area with the given response_id as the default widget for the dialog.

Pressing “Enter” normally activates the default widget.

Note that this function currently requires info_bar to be added to a widget hierarchy.

Parameters:

  • response_id (Integer)

    a response ID

Returns:

  • (nil)

#message_typeGtk::MessageType

The type of the message.

The type may be used to determine the appearance of the info bar.

Returns:

#message_type=(message_type) ⇒ Gtk::MessageType

The type of the message.

The type may be used to determine the appearance of the info bar.

Parameters:

Returns:

#remove_action_widget(widget) ⇒ nil

Removes a widget from the action area of info_bar.

The widget must have been put there by a call to [methodGtk.InfoBar.add_action_widget] or [methodGtk.InfoBar.add_button].

Parameters:

Returns:

  • (nil)

#remove_child(widget) ⇒ nil

Removes a widget from the content area of the info bar.

Parameters:

  • widget (Gtk::Widget)

    a child that has been added to the content area

Returns:

  • (nil)

#response(response_id) ⇒ nil

Emits the “response” signal with the given response_id.

Parameters:

  • response_id (Integer)

    a response ID

Returns:

  • (nil)

#revealedBoolean

Returns whether the info bar is currently revealed.

Returns:

  • (Boolean)

    the current value of the [propertyGtk.InfoBar:revealed] property

#revealed=(revealed) ⇒ Boolean

Whether the info bar shows its contents.

Parameters:

  • revealed (Boolean)

Returns:

  • (Boolean)

    revealed

  • (Boolean)

    revealed

#revealed?Boolean

Whether the info bar shows its contents.

Returns:

  • (Boolean)

    revealed

#set_response_sensitive(response_id, setting) ⇒ nil

Sets the sensitivity of action widgets for response_id.

Calls gtk_widget_set_sensitive (widget, setting) for each widget in the info bars’s action area with the given response_id. A convenient way to sensitize/desensitize buttons.

Parameters:

  • response_id (Integer)

    a response ID

  • setting (Boolean)

    TRUE for sensitive

Returns:

  • (nil)

#show_close_buttonBoolean

Returns whether the widget will display a standard close button.

Returns:

  • (Boolean)

    true if the widget displays standard close button

#show_close_button=(show_close_button) ⇒ Boolean

Whether to include a standard close button.

Parameters:

  • show_close_button (Boolean)

Returns:

  • (Boolean)

    show-close-button

  • (Boolean)

    show-close-button

#show_close_button?Boolean

Whether to include a standard close button.

Returns:

  • (Boolean)

    show-close-button