Gtk.InfoBar
Gtk.InfoBar — Report important messages to the user
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Box
╰── Gtk.InfoBar
See also:
Gtk.Statusbar, Gtk.MessageDialog
Functions:
- new
() -> Gtk.Widget
- add_action_widget
(self, child:Gtk.Widget, response_id:int)
- add_button
(self, button_text:str, response_id:int) -> Gtk.Button
- set_response_sensitive
(self, response_id:int, setting:bool)
- set_default_response
(self, response_id:int)
- response
(self, response_id:int)
- set_message_type
(self, message_type:Gtk.MessageType)
- get_message_type
(self) -> Gtk.MessageType
- get_action_area
(self) -> Gtk.Widget
- get_content_area
(self) -> Gtk.Widget
- get_show_close_button
(self) -> bool
- set_show_close_button
(self, setting:bool)
Signals:
- “close”
(user_data)
Description:
Gtk.InfoBar
is a widget that can be used to show messages to the user without showing a dialog. It is often temporarily shown at the top or bottom of a document. In contrast to Gtk.Dialog, which has a action area at the bottom, Gtk.InfoBar
has an action area at the side.
The API of Gtk.InfoBar
is very similar to GtkDialog, allowing you to add buttons to the action area with Gtk.InfoBar::add_button()
or Gtk.InfoBar::new_with_buttons()
. The sensitivity of action widgets can be controlled with Gtk.InfoBar::set_response_sensitive()
.
To add widgets to the main content area of a Gtk.InfoBar
, use Gtk.InfoBar::get_content_area()
and add your widgets to the container.
Similar to Gtk.MessageDialog, the contents of a GtkInfoBar can by classified as error message, warning, informational message, etc, by using Gtk.InfoBar::set_message_type()
. GTK+ may use the message type to determine how the message is displayed.
A simple example for using a Gtk.InfoBar
:
self.infobar = Gtk.InfoBar()
self.infobar.set_show_close_button(True)
self.infobar.connect("response", self.on_infobar_response)
grid.attach(self.infobar, 0, 0, 1, 1)
def on_button_clicked(self, button):
self.infobar.set_message_type(button.message_type)
self.infobar.show()
def on_infobar_response(self, infobar, respose_id):
self.infobar.hide()
Gtk.InfoBar as Gtk.Buildable:
The Gtk.InfoBar
implementation of the Gtk.Buildable interface exposes the content area and action area as internal children with the names content_area
and action_area
.
Gtk.InfoBar
supports a custom \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).
Function Details:
new()
new () -> Gtk.Widget
Creates a new Gtk.InfoBar
object.
Returns: a new
Gtk.InfoBar
objectSince: 2.18
add_action_widget()
add_action_widget (self, child:Gtk.Widget, response_id:int)
Add an activatable widget to the action area of a Gtk.InfoBar
,connecting a signal handler that will emit the “response”signal on the message area when the widget is activated. The widgetis appended to the end of the message areas action area.
- Since: 2.18
add_button()
add_button (self, button_text:str, response_id:int) -> Gtk.Button
Adds a button with the given text and sets things up so thatclicking the button will emit the “response” signal with the givenresponse_id. The button is appended to the end of the info bars'saction area. The button widget is returned, but usually you don'tneed it.
Returns: the
Gtk.Button
widgetthat was added.Since: 2.18
set_response_sensitive()
set_response_sensitive (self, response_id:int, setting:bool)
Calls Gtk.Widget:set_sensitive
(widget, setting) for eachwidget in the info bars’s action area with the given response_id.A convenient way to sensitize/desensitize dialog buttons.
- Since: 2.18
set_default_response()
set_default_response (self, response_id:int)
Sets the last widget in the info bar’s action area withthe 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
tobe added to a widget hierarchy.
- Since: 2.18
response()
response (self, response_id:int)
Emits the “response” signal with the given response_id
.
- Since: 2.18
set_message_type()
set_message_type (self, message_type:Gtk.MessageType)
Sets the message type of the message area.GTK+ uses this type to determine what color to usewhen drawing the message area.
- Since: 2.18
get_message_type()
get_message_type (self) -> Gtk.MessageType
Returns the message type of the message area.
Returns: the message type of the message area.
Since: 2.18
get_action_area()
get_action_area (self) -> Gtk.Widget
Returns the action area of info_bar
.
Returns: the action area.
Since: 2.18
get_content_area()
get_content_area (self) -> Gtk.Widget
Returns the content area of info_bar
.
Returns: the content area.
Since: 2.18
get_show_close_button()
get_show_close_button (self) -> bool
Returns whether the widget will display a standard close button.
Returns:
True
if the widget displays standard close buttonSince: 3.10
set_show_close_button()
set_show_close_button (self, setting:bool)
If true, a standard close button is shown. When clicked it emitsthe response GTK_RESPONSE_CLOSE
.
- Since: 3.10
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class InfoBar(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("InfoBar")
self.connect("destroy", Gtk.main_quit)
grid = Gtk.Grid()
grid.set_row_spacing(5)
self.add(grid)
self.infobar = Gtk.InfoBar()
self.infobar.set_show_close_button(True)
self.infobar.connect("response", self.on_infobar_response)
grid.attach(self.infobar, 0, 0, 1, 1)
label = Gtk.Label("InfoBar content string.")
content = self.infobar.get_content_area()
content.add(label)
buttonbox = Gtk.ButtonBox()
grid.attach(buttonbox, 0, 1, 1, 1)
buttonInformation = Gtk.Button(label="Information")
buttonInformation.message_type = Gtk.MessageType.INFO
buttonInformation.connect("clicked", self.on_button_clicked)
buttonbox.add(buttonInformation)
buttonQuestion = Gtk.Button(label="Question")
buttonQuestion.message_type = Gtk.MessageType.QUESTION
buttonQuestion.connect("clicked", self.on_button_clicked)
buttonbox.add(buttonQuestion)
buttonWarning = Gtk.Button(label="Warning")
buttonWarning.message_type = Gtk.MessageType.WARNING
buttonWarning.connect("clicked", self.on_button_clicked)
buttonbox.add(buttonWarning)
buttonError = Gtk.Button(label="Error")
buttonError.message_type = Gtk.MessageType.ERROR
buttonError.connect("clicked", self.on_button_clicked)
buttonbox.add(buttonError)
buttonOther = Gtk.Button(label="Other")
buttonOther.message_type = Gtk.MessageType.OTHER
buttonOther.connect("clicked", self.on_button_clicked)
buttonbox.add(buttonOther)
def on_button_clicked(self, button):
self.infobar.set_message_type(button.message_type)
self.infobar.show()
def on_infobar_response(self, infobar, respose_id):
self.infobar.hide()
window = InfoBar()
window.show_all()
Gtk.main()