コード例 #1
0
def error_dialog(primary,
                 secondary,
                 parent=None,
                 messagetype=Gtk.MessageType.ERROR):
    """A common error dialog handler for Meld

    This should only ever be used as a last resort, and for errors that
    a user is unlikely to encounter. If you're tempted to use this,
    think twice.

    Primary must be plain text. Secondary must be valid markup.
    """
    if not parent:
        from meld.meldapp import app
        parent = app.get_active_window()

    dialog = Gtk.MessageDialog(parent=parent,
                               flags=Gtk.DialogFlags.MODAL
                               | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                               type=messagetype,
                               buttons=Gtk.ButtonsType.CLOSE,
                               message_format=primary)
    dialog.format_secondary_markup(secondary)
    dialog.run()
    dialog.destroy()
コード例 #2
0
ファイル: misc.py プロジェクト: syagev/meld
def get_modal_parent(widget: Gtk.Widget = None) -> Gtk.Window:
    if not widget:
        from meld.meldapp import app
        parent = app.get_active_window()
    elif not isinstance(widget, Gtk.Window):
        parent = widget.get_toplevel()
    else:
        parent = widget
    return parent
コード例 #3
0
ファイル: misc.py プロジェクト: GNOME/meld
def get_modal_parent(widget: Optional[Gtk.Widget] = None) -> Gtk.Window:
    parent: Gtk.Window
    if not widget:
        from meld.meldapp import app
        parent = app.get_active_window()
    elif not isinstance(widget, Gtk.Window):
        parent = widget.get_toplevel()
    else:
        parent = widget
    return parent
コード例 #4
0
def modal_dialog(primary,
                 secondary,
                 buttons,
                 parent=None,
                 messagetype=Gtk.MessageType.WARNING):
    """A common message dialog handler for Meld

    This should only ever be used for interactions that must be resolved
    before the application flow can continue.

    Primary must be plain text. Secondary must be valid markup.
    """

    if not parent:
        from meld.meldapp import app
        parent = app.get_active_window()
    elif not isinstance(parent, Gtk.Window):
        parent = parent.get_toplevel()

    if isinstance(buttons, Gtk.ButtonsType):
        custom_buttons = []
    else:
        custom_buttons, buttons = buttons, Gtk.ButtonsType.NONE

    dialog = Gtk.MessageDialog(transient_for=parent,
                               modal=True,
                               destroy_with_parent=True,
                               message_type=messagetype,
                               buttons=buttons,
                               text=primary)
    dialog.format_secondary_markup(secondary)

    for label, response_id in custom_buttons:
        dialog.add_button(label, response_id)

    response = dialog.run()
    dialog.destroy()
    return response
コード例 #5
0
ファイル: misc.py プロジェクト: albfan/PatienceMeld
def error_dialog(
        primary, secondary, parent=None, messagetype=Gtk.MessageType.ERROR):
    """A common error dialog handler for Meld

    This should only ever be used as a last resort, and for errors that
    a user is unlikely to encounter. If you're tempted to use this,
    think twice.

    Primary must be plain text. Secondary must be valid markup.
    """
    if not parent:
        from meld.meldapp import app
        parent = app.get_active_window()

    dialog = Gtk.MessageDialog(
        parent=parent,
        flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
        type=messagetype,
        buttons=Gtk.ButtonsType.CLOSE,
        message_format=primary)
    dialog.format_secondary_markup(secondary)
    dialog.run()
    dialog.destroy()
コード例 #6
0
ファイル: misc.py プロジェクト: surjit/meld-3.14.2
def modal_dialog(
        primary, secondary, buttons, parent=None,
        messagetype=Gtk.MessageType.WARNING):
    """A common message dialog handler for Meld

    This should only ever be used for interactions that must be resolved
    before the application flow can continue.

    Primary must be plain text. Secondary must be valid markup.
    """

    if not parent:
        from meld.meldapp import app
        parent = app.get_active_window()
    elif not isinstance(parent, Gtk.Window):
        parent = parent.get_toplevel()

    if isinstance(buttons, Gtk.ButtonsType):
        custom_buttons = []
    else:
        custom_buttons, buttons = buttons, Gtk.ButtonsType.NONE

    dialog = Gtk.MessageDialog(
        transient_for=parent,
        modal=True,
        destroy_with_parent=True,
        message_type=messagetype,
        buttons=buttons,
        text=primary)
    dialog.format_secondary_markup(secondary)

    for label, response_id in custom_buttons:
        dialog.add_button(label, response_id)

    response = dialog.run()
    dialog.destroy()
    return response