Gtk.MessageDialog


Gtk.MessageDialog — A convenient message window

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Bin
                    ╰── Gtk.Window
                        ╰── Gtk.Dialog
                            ╰── Gtk.MessageDialog

See also:

Gtk.Dialog


Functions:

Description:

Gtk.MessageDialog presents a dialog with some message text. It’s simply a convenience widget; you could construct the equivalent of Gtk.MessageDialog from Gtk.Dialog without too much effort, but Gtk.MessageDialog saves typing.

One difference from Gtk.Dialog is that Gtk.MessageDialog sets the from the taskbar by default.

The easiest way to do a modal message dialog is to use Gtk.Dialog::run(), though you can also pass in the Gtk.DialogFlags.MODAL flag, Gtk.Dialog::run() automatically makes the dialog modal and waits for the user to respond to it. Gtk.Dialog::run() returns when any dialog button is clicked.

  • An example for using a modal dialog:
    dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
        Gtk.ButtonsType.OK, "This is an INFO MessageDialog")
    dialog.format_secondary_text(
        "And this is the secondary text that explains things.")
    dialog.run()
    print("INFO dialog closed")

    dialog.destroy()

Gtk.MessageDialog as Gtk.Buildable:

The Gtk.MessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name message_area.


Function Details:

new()

new () -> Gtk.Widget

Creates a new message dialog, which is a simple dialog with some textthe user may want to see. When the user clicks a button a “response”signal is emitted with response IDs from Gtk.ResponseType. SeeGtk.Dialog for more details.

  • Returns: a new Gtk.MessageDialog.

set_markup()

set_markup (self, str:str)

Sets the text of the message dialog to be str, which is markedup with the Pango text markup language.

  • Since: 2.4

set_image()

set_image (self, image:Gtk.Widget)

Gtk.MessageDialog:set_image has been deprecated since version 3.12 and should not be used in newly-written code. Use Gtk.Dialog to create dialogs with images Sets the dialog’s image to image.

  • Since: 2.10

get_image()

get_image (self) -> Gtk.Widget

Gtk.MessageDialog:get_image has been deprecated since version 3.12 and should not be used in newly-written code. Use Gtk.Dialog for dialogs with images Gets the dialog’s image.

  • Returns: the dialog’s image.

  • Since: 2.14


get_message_area()

get_message_area (self) -> Gtk.Widget

Returns the message area of the dialog. This is the box where thedialog’s primary and secondary labels are packed. You can add yourown extra content to that box and it will appear below those labels.See `Gtk.Dialog:get_content_area()for the correspondingfunction in the parentGtk.Dialog`.

  • Returns: A Gtk.VBox corresponding to the“message area” in the message_dialog.

  • Since: 2.22


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MessageDialog(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("MessageDialog")
        self.connect("destroy", Gtk.main_quit)

        buttonbox = Gtk.ButtonBox()
        self.add(buttonbox)

        buttonInformation = Gtk.Button(label="Information")
        buttonInformation.message_type = Gtk.MessageType.INFO
        buttonInformation.connect("clicked", self.on_message_clicked)
        buttonbox.add(buttonInformation)
        buttonWarning = Gtk.Button(label="Warning")
        buttonWarning.message_type = Gtk.MessageType.WARNING
        buttonWarning.connect("clicked", self.on_message_clicked)
        buttonbox.add(buttonWarning)
        buttonQuestion = Gtk.Button(label="Question")
        buttonQuestion.message_type = Gtk.MessageType.QUESTION
        buttonQuestion.connect("clicked", self.on_message_clicked)
        buttonbox.add(buttonQuestion)
        buttonError = Gtk.Button(label="Error")
        buttonError.message_type = Gtk.MessageType.ERROR
        buttonError.connect("clicked", self.on_message_clicked)
        buttonbox.add(buttonError)
        buttonOther = Gtk.Button(label="Other")
        buttonOther.message_type = Gtk.MessageType.OTHER
        buttonOther.connect("clicked", self.on_message_clicked)
        buttonbox.add(buttonOther)

        self.messagedialog = Gtk.MessageDialog(message_format="MessageDialog")
        self.messagedialog.set_transient_for(self)
        self.messagedialog.set_title("MessageDialog")
        self.messagedialog.set_markup("<span size='12000'><b>This is a MessageDialog widget.</b></span>")
        self.messagedialog.format_secondary_text("The MessageDialog can display a main message, and further secondary content.")
        self.messagedialog.add_button("_Close", Gtk.ResponseType.CLOSE)

    def on_message_clicked(self, button):
        self.messagedialog.set_property("message-type", button.message_type)

        self.messagedialog.run()
        self.messagedialog.hide()

window = MessageDialog()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""