[meld] misc: Add modal_dialog helper, to accompany the error_dialog one
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] misc: Add modal_dialog helper, to accompany the error_dialog one
- Date: Mon, 21 Apr 2014 21:54:38 +0000 (UTC)
commit 97f368c72e13b1a19fd937763a6a57dbb4115be0
Author: Kai Willadsen <kai willadsen gmail com>
Date: Tue Apr 22 07:36:15 2014 +1000
misc: Add modal_dialog helper, to accompany the error_dialog one
This should rarely be needed, but there are some places where modal
interaction really is the only sane option.
meld/misc.py | 36 +++++++++++++++++++++++++++++++++++-
1 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index cc6e8c3..4a353a7 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -40,7 +40,8 @@ else:
return rlist, wlist, xlist
-def error_dialog(primary, secondary, parent=None, messagetype=Gtk.MessageType.ERROR):
+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
@@ -64,6 +65,39 @@ def error_dialog(primary, secondary, parent=None, messagetype=Gtk.MessageType.ER
dialog.destroy()
+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.window.widget
+ elif not isinstance(parent, Gtk.Window):
+ parent = parent.get_toplevel()
+
+ dialog = Gtk.MessageDialog(
+ parent=parent,
+ flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ type=messagetype,
+ buttons=Gtk.ButtonsType.NONE,
+ message_format=primary)
+ dialog.format_secondary_markup(secondary)
+
+ for label, response_id in buttons:
+ dialog.add_button(label, response_id)
+
+ response = dialog.run()
+ dialog.destroy()
+ return response
+
+
def run_dialog( text, parent=None, messagetype=Gtk.MessageType.WARNING, buttonstype=Gtk.ButtonsType.OK,
extrabuttons=()):
"""Run a dialog with text 'text'.
Extra buttons are passed as tuples of (button label, response id).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]