From 6325153e0269d1ee8fe9d89374df0bcd87c6bd9e Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 19 Jul 2006 23:42:50 +0000 Subject: [PATCH] 2006-07-19 Alex Roitman * src/plugins/GraphViz.py (GraphViz.__init__): Take care of the encoding errors. svn: r7046 --- gramps2/ChangeLog | 4 ++++ gramps2/src/plugins/GraphViz.py | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index de9e647d5..2d1cc3af4 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2006-07-19 Alex Roitman + * src/plugins/GraphViz.py (GraphViz.__init__): Take care of the + encoding errors. + 2006-07-19 Zsolt Foldvari * src/GrampsCfg.py: UI improvements. * src/Config/_GrampsIniKeys.py: Proper key retrieval. diff --git a/gramps2/src/plugins/GraphViz.py b/gramps2/src/plugins/GraphViz.py index 851d90b8d..6f74ca8da 100644 --- a/gramps2/src/plugins/GraphViz.py +++ b/gramps2/src/plugins/GraphViz.py @@ -63,6 +63,7 @@ import DateHandler import const from BaseDoc import PAPER_LANDSCAPE from QuestionDialog import ErrorDialog +import Errors #------------------------------------------------------------------------ # @@ -243,13 +244,30 @@ class GraphViz: self.filter = filters[filter_num] the_buffer = self.get_report() - self.f = open(options_class.get_output(),'w') - if self.latin: - self.f.write(the_buffer.encode('iso-8859-1', 'replace')) - else: + + encoding_problem = False + try: + self.f = open(options_class.get_output(),'w') self.f.write(the_buffer) + except UnicodeEncodeError: + if self.latin: + self.f = open(options_class.get_output(),'w') + self.f.write(the_buffer.encode('iso-8859-1', 'replace')) + encoding_problem = True + else: + raise Errors.ReporError( + _("Your data contains characters that cannot " + "be displayed. Most likely this is caused " + "by the incorrect character encoding.")) self.f.close() + if encoding_problem: + ErrorDialog( + _("Your data contains characters that cannot be converted " + "to latin-1. These characters were replaced with the " + "question marks in the output. To get these characters " + "properly displayed, unselect latin-1 option and try again.")) + def get_report(self): "return string of the .dot file contents" self.person_handles = self.filter.apply(self.database,