InfoBar#

Deprecated since version 4.10: There is no replacement in GTK for an “info bar” widget; you can use Revealer with a Box containing a Label and an optional Button, according to your application’s design.

class InfoBar(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

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

https://docs.gtk.org/gtk4/info-bar.png

It is often temporarily shown at the top or bottom of a document. In contrast to 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 add_button or new_with_buttons. The sensitivity of action widgets can be controlled with set_response_sensitive.

To add widgets to the main content area of a GtkInfoBar, use add_child.

Similar to MessageDialog, the contents of a GtkInfoBar can by classified as error message, warning, informational message, etc, by using 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.

Constructors#

class InfoBar
classmethod new() Widget#

Creates a new GtkInfoBar object.

Deprecated since version 4.10: Please do not use it in newly written code

Methods#

class InfoBar
add_action_widget(child: Widget, response_id: int) None#

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

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

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:
  • child – an activatable widget

  • response_id – response ID for child

add_button(button_text: str, response_id: int) Button#

Adds a button with the given text.

Clicking the button will emit the 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.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:
  • button_text – text of button

  • response_id – response ID for the button

add_child(widget: Widget) None#

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

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

widget – the child to be added

get_message_type() MessageType#

Returns the message type of the message area.

Deprecated since version 4.10: Please do not use it in newly written code

get_revealed() bool#

Returns whether the info bar is currently revealed.

Deprecated since version 4.10: Please do not use it in newly written code

get_show_close_button() bool#

Returns whether the widget will display a standard close button.

Deprecated since version 4.10: Please do not use it in newly written code

remove_action_widget(widget: Widget) None#

Removes a widget from the action area of info_bar.

The widget must have been put there by a call to add_action_widget or add_button.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

widget – an action widget to remove

remove_child(widget: Widget) None#

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

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

widget – a child that has been added to the content area

response(response_id: int) None#

Emits the “response” signal with the given response_id.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

response_id – a response ID

set_default_response(response_id: int) None#

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.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

response_id – a response ID

set_message_type(message_type: MessageType) None#

Sets the message type of the message area.

GTK uses this type to determine how the message is displayed.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

message_type – a GtkMessageType

set_response_sensitive(response_id: int, setting: bool) None#

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.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:
  • response_id – a response ID

  • setting – TRUE for sensitive

set_revealed(revealed: bool) None#

Sets whether the GtkInfoBar is revealed.

Changing this will make info_bar reveal or conceal itself via a sliding transition.

Note: this does not show or hide info_bar in the visible sense, so revealing has no effect if visible is False.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

revealed – The new value of the property

set_show_close_button(setting: bool) None#

If true, a standard close button is shown.

When clicked it emits the response CLOSE.

Deprecated since version 4.10: Please do not use it in newly written code

Parameters:

settingTrue to include a close button

Properties#

class InfoBar
props.message_type: MessageType#

The type of the None singleton.

props.revealed: bool#

The type of the None singleton.

props.show_close_button: bool#

The type of the None singleton.

Signals#

class InfoBar.signals
close() None#

The type of the None singleton.

response(response_id: int) None#

Emitted when an action widget is clicked.

The signal is also emitted when the application programmer calls response. The response_id depends on which action widget was clicked.

Parameters:

response_id – the response ID