[pybliographer] ui: Migrate error dialog from gnome to gtk
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pybliographer] ui: Migrate error dialog from gnome to gtk
- Date: Sun, 25 Mar 2018 22:55:58 +0000 (UTC)
commit 8f9163919d10019776196d87d436eb0ed4800a96
Author: Germán Poo-Caamaño <gpoo gnome org>
Date: Sat Mar 24 17:48:38 2018 -0300
ui: Migrate error dialog from gnome to gtk
Pyblio/GnomeUI/Editor.py | 39 ++++++++++++++++++++-------------------
Pyblio/GnomeUI/Utils.py | 10 ++++++++++
2 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/Pyblio/GnomeUI/Editor.py b/Pyblio/GnomeUI/Editor.py
index 8f3e7c3..bc12e5c 100644
--- a/Pyblio/GnomeUI/Editor.py
+++ b/Pyblio/GnomeUI/Editor.py
@@ -28,7 +28,7 @@ import copy, gobject, gtk, re, string
from gnome import ui
from Pyblio import Base, Config, Connector, Exceptions, Fields, Key, Types
-from Pyblio.GnomeUI import Common, Compat, FieldsInfo, FileSelector, Mime, Utils
+from Pyblio.GnomeUI import Common, FieldsInfo, FileSelector, Mime, Utils
key_re = re.compile("^[\w:_+-.()/]+$")
@@ -353,24 +353,24 @@ class Date (BaseField):
if text != '':
try: day = int (text)
except ValueError:
- Compat.error_dialog_parented (_("Invalid day field in date"),
- self.day.get_toplevel ())
+ Utils.error_dialog_s(self.day.get_toplevel(),
+ ("Invalid day field in date"))
return -1
text = string.strip (self.month.get_chars (0, -1)).encode ('latin-1')
if text != '':
try: month = int (text)
except ValueError, err:
- Compat.error_dialog_parented (_("Invalid month field in date"),
- self.day.get_toplevel ())
+ Utils.error_dialog_s(self.day.get_toplevel(),
+ ("Invalid day field in date"))
return -1
text = string.strip (self.year.get_chars (0, -1)).encode ('latin-1')
if text != '':
try: year = int (text)
except ValueError:
- Compat.error_dialog_parented (_("Invalid year field in date"),
- self.day.get_toplevel ())
+ Utils.error_dialog_s(self.day.get_toplevel(),
+ ("Invalid day field in date"))
return -1
if self.initial == (day, month, year): return 0
@@ -382,8 +382,8 @@ class Date (BaseField):
try:
entry [self.field] = Fields.Date ((year, month, day))
except Exceptions.DateError, error:
- Compat.error_dialog_parented (str (error),
- self.day.get_toplevel ())
+ Utils.error_dialog_s(self.day.get_toplevel(),
+ str(error))
return -1
return 1
@@ -906,17 +906,17 @@ class RealEditor (Connector.Publisher):
modified = True
else:
if not key_re.match (key):
- Compat.error_dialog_parented (
- _("Invalid key format"), self.w.get_toplevel ())
+ Utils.error_dialog_s(self.w.get_toplevel(),
+ _("Invalid key format"))
return None
key = Key.Key (database, key)
if key != self.entry.key:
if database.has_key (key):
- Compat.error_dialog_parented (
- _("Key “%s” already exists") % str (key.key),
- self.w.get_toplevel ())
+ Utils.error_dialog_s(
+ self.w.get_toplevel(),
+ _("Key “%s” already exists") % str (key.key))
return None
self.entry.key = key
@@ -931,9 +931,10 @@ class RealEditor (Connector.Publisher):
except UnicodeError:
f = Types.get_field(item.field)
- Compat.error_dialog_parented(
+ Utils.error_dialog_s(
+ self.w.get_toplevel(),
_("The “%s” field contains a non Latin-1 symbol") %
- f.name, self.w.get_toplevel())
+ f.name)
return None
if result == -1: return None
@@ -993,9 +994,9 @@ class NativeEditor(Connector.Publisher):
try:
text = text.encode('latin-1')
except UnicodeError:
- Compat.error_dialog_parented(
- _("Your text contains non Latin-1 symbols"),
- self.w.get_toplevel())
+ Utils.error_dialog_s(
+ self.w.get_toplevel(),
+ _("Your text contains non Latin-1 symbols"))
return None
try:
new = self.database.create_native(text)
diff --git a/Pyblio/GnomeUI/Utils.py b/Pyblio/GnomeUI/Utils.py
index bf0a78c..ff52231 100644
--- a/Pyblio/GnomeUI/Utils.py
+++ b/Pyblio/GnomeUI/Utils.py
@@ -218,3 +218,13 @@ def error_dialog (title, err, parent = None):
return
+
+def error_dialog_s(parent, primary, secondary=None):
+ dialog = gtk.MessageDialog(parent,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_ERROR,
+ gtk.BUTTONS_CANCEL, primary)
+ if secondary:
+ dialog.format_secondary_text(secondary)
+ dialog.run()
+ dialog.destroy()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]