From eeaaac060e9d96bb666c6a5104e6971ae83b41c9 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Mon, 1 Aug 2016 16:30:46 -0700 Subject: [PATCH] better handle an unlikely error in the Complete Individual report --- gramps/cli/user.py | 25 +++++++++++++++++++++- gramps/gen/user.py | 10 +++++++++ gramps/gui/dialog.py | 7 ++++-- gramps/gui/user.py | 15 ++++++++++++- gramps/plugins/textreport/indivcomplete.py | 6 ++++-- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/gramps/cli/user.py b/gramps/cli/user.py index 9e6e89833..355e58713 100644 --- a/gramps/cli/user.py +++ b/gramps/cli/user.py @@ -29,6 +29,7 @@ The User class provides basic interaction with the user. #------------------------------------------------------------------------ from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext +from gramps.gen.const import URL_BUGHOME from gramps.gen import user #------------------------------------------------------------------------ @@ -182,7 +183,7 @@ class User(user.User): if self.error_function: self.error_function(title, error) else: - self._fileout.write("%s %s" % (title, error)) + self._fileout.write("%s\n%s\n" % (title, error)) def notify_db_error(self, error): """ @@ -191,6 +192,8 @@ class User(user.User): :param error: the error message :type error: str :returns: none + + These exact strings are also in gui/dialog.py -- keep them in sync """ self.notify_error( _("Low level database corruption detected"), @@ -199,6 +202,26 @@ class User(user.User): "the Family Tree Manager. Select the database and " 'click on the Repair button') + '\n\n' + error) + def notify_db_repair(self, error): + """ + Notify the user their DB might need repair. + + :param error: the error message + :type error: str + :returns: none + + These exact strings are also in gui/dialog.py -- keep them in sync + """ + self.notify_error( + _('Error detected in database'), + _('Gramps has detected an error in the database. This can ' + 'usually be resolved by running the "Check and Repair Database" ' + 'tool.\n\nIf this problem continues to exist after running this ' + 'tool, please file a bug report at ' + '%(gramps_bugtracker_url)s\n\n' + ) % {'gramps_bugtracker_url' : URL_BUGHOME} + + error + '\n\n') + def info(self, msg1, infotext, parent=None, monospaced=False): """ Displays information to the CLI diff --git a/gramps/gen/user.py b/gramps/gen/user.py index c582ec4e7..6d9a9116c 100644 --- a/gramps/gen/user.py +++ b/gramps/gen/user.py @@ -172,6 +172,16 @@ class User(metaclass=ABCMeta): :returns: none """ + @abstractmethod + def notify_db_repair(self, error): + """ + Notify the user their DB might need repair. + + :param error: the error message + :type error: str + :returns: none + """ + @abstractmethod def info(self, msg1, infotext, parent=None, monospaced=False): """ diff --git a/gramps/gui/dialog.py b/gramps/gui/dialog.py index f6e182df3..96ec2fea8 100644 --- a/gramps/gui/dialog.py +++ b/gramps/gui/dialog.py @@ -198,18 +198,21 @@ class ErrorDialog(Gtk.MessageDialog): # parent-OK class RunDatabaseRepair(ErrorDialog): # parent-OK def __init__(self, msg, parent=None): ErrorDialog.__init__( + # These exact strings are also in cli/user.py -- keep them in sync self, _('Error detected in database'), _('Gramps has detected an error in the database. This can ' 'usually be resolved by running the "Check and Repair Database" ' 'tool.\n\nIf this problem continues to exist after running this ' 'tool, please file a bug report at ' - '%(gramps_bugtracker_url)s\n\n') - % {'gramps_bugtracker_url' : URL_BUGHOME} + msg, parent) + '%(gramps_bugtracker_url)s\n\n' + ) % {'gramps_bugtracker_url' : URL_BUGHOME} + + msg, parent) class DBErrorDialog(ErrorDialog): # parent-OK def __init__(self, msg, parent=None): ErrorDialog.__init__( + # These exact strings are also in cli/user.py -- keep them in sync self, _("Low level database corruption detected"), _("Gramps has detected a problem in the underlying " diff --git a/gramps/gui/user.py b/gramps/gui/user.py index 2e86505f5..a870b626c 100644 --- a/gramps/gui/user.py +++ b/gramps/gui/user.py @@ -37,7 +37,7 @@ import sys from gramps.gen import user from .utils import ProgressMeter from .dialog import (WarningDialog, ErrorDialog, DBErrorDialog, - InfoDialog, QuestionDialog2) + RunDatabaseRepair, InfoDialog, QuestionDialog2) #------------------------------------------------------------------------- # # User class @@ -162,6 +162,19 @@ class User(user.User): else: DBErrorDialog(error, parent=None) # parent-OK + def notify_db_repair(self, error): + """ + Notify the user their DB might need repair. + + :param error: the DB error message + :type error: str + :returns: none + """ + if self.uistate: + RunDatabaseRepair(error, parent=self.uistate.window) # parent-OK + else: + RunDatabaseRepair(error, parent=None) # parent-OK + def info(self, msg1, infotext, parent=None, monospaced=False): """ Calls the GUI InfoDialog diff --git a/gramps/plugins/textreport/indivcomplete.py b/gramps/plugins/textreport/indivcomplete.py index c00d69d7a..f0c9fda50 100644 --- a/gramps/plugins/textreport/indivcomplete.py +++ b/gramps/plugins/textreport/indivcomplete.py @@ -548,9 +548,11 @@ class IndivCompleteReport(Report): media_handle = media_ref.get_reference_handle() media = self._db.get_media_from_handle(media_handle) if media is None: - from gramps.gui.dialog import RunDatabaseRepair - RunDatabaseRepair( # no-parent + self._user.notify_db_repair( _('Non existing media found in the Gallery')) + self.doc.end_table() + self.doc.start_paragraph('IDS-Normal') + self.doc.end_paragraph() return mime_type = media.get_mime_type() if not mime_type or not mime_type.startswith("image"):