From 7ce0cc4eefec2723b9491231bb867f3a0e1db66e Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Wed, 18 Jul 2007 21:39:56 +0000 Subject: [PATCH] 2007-07-18 Zsolt Foldvari * src/MarkupText.py: improved xml generator * src/docgen/GtkPrint.py: fix svn proplist svn: r8740 --- ChangeLog | 4 ++ src/MarkupText.py | 85 +++++++++++++++++++++++------------------- src/docgen/GtkPrint.py | 33 ++++++++-------- 3 files changed, 68 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2818e524c..f27ca603a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-07-18 Zsolt Foldvari + * src/MarkupText.py: improved xml generator + * src/docgen/GtkPrint.py: fix svn proplist + 2007-07-18 Alex Roitman * configure.in: Revert checks for pycairo. diff --git a/src/MarkupText.py b/src/MarkupText.py index 398e4ed6d..b0483c1a4 100644 --- a/src/MarkupText.py +++ b/src/MarkupText.py @@ -184,31 +184,45 @@ class MarkupWriter: indices = eventdict.keys() indices.sort() for index in indices: - modified_tags = [] - for (name, attrs, type, pair_idx) in eventdict[index]: - if attrs.getLength(): - # remove this event, we will insert new ones instead - eventdict[index].remove((name, attrs, type, pair_idx)) - - # if the tag is already open first we need to close it - if active_tags.has_key(name): - tmp_attrs = xmlreader.AttributesImpl({}) - tmp_attrs._attrs.update(active_tags[name]) - eventdict[index].insert(0, (name, tmp_attrs, - self.EVENT_END, - active_idx[name])) - # update pair index in tag opening event - # FIXME this is ugly - for event in eventdict[active_idx[name]]: - if (event[0] == name and - event[2] == self.EVENT_START): - new_event = (event[0], event[1], event[2], index) - eventdict[active_idx[name]].remove(event) - eventdict[active_idx[name]].append(new_event) + # separate the events by tag names + tagdict = {} + for event in eventdict[index]: + # we care only about tags having attributes + if event[1].getLength(): + if tagdict.has_key(event[0]): + tagdict[event[0]].append(event) else: - active_tags[name] = xmlreader.AttributesImpl({}) + tagdict[event[0]] = [event] + + # let's handle each tag + for tag_name in tagdict.keys(): + + # first we close the tag if it's already open + if active_tags.has_key(tag_name): + tmp_attrs = xmlreader.AttributesImpl({}) + tmp_attrs._attrs.update(active_tags[tag_name]) + eventdict[index].insert(0, (name, tmp_attrs, + self.EVENT_END, + active_idx[tag_name])) + # go back where the tag was opened and update the pair_idx, + # i.e. with the current index. + # FIXME this is ugly + for event in eventdict[active_idx[tag_name]]: + if (event[0] == tag_name and + event[2] == self.EVENT_START): + new_event = (event[0], event[1], event[2], index) + eventdict[active_idx[tag_name]].remove(event) + eventdict[active_idx[tag_name]].append(new_event) + else: + active_tags[tag_name] = xmlreader.AttributesImpl({}) + + # update + for event in tagdict[tag_name]: + # remove this event, we will insert new ones instead + eventdict[index].remove(event) # update the active attribute object for the tag + (name, attrs, type, pair_idx) = event if type == self.EVENT_START: active_tags[name]._attrs.update(attrs) elif type == self.EVENT_END: @@ -220,25 +234,20 @@ class MarkupWriter: else: pass # error - # if the tag's attr list is empty after the updates - # delete the tag completely from the list of active tags - if not active_tags[name].getLength(): - del active_tags[name] - ##del active_idx[name] + # if the tag's attr list is empty after the updates + # delete the tag completely from the list of active tags + if not active_tags[name].getLength(): + del active_tags[name] + ##del active_idx[name] - # remember this tag has changes - if name not in modified_tags: - modified_tags.append(name) - - # re-open all tags with updated attrs - for name in modified_tags: - if active_tags.has_key(name): + # re-open all tags with updated attrs + if active_tags.has_key(tag_name): tmp_attrs = xmlreader.AttributesImpl({}) - tmp_attrs._attrs.update(active_tags[name]) - eventdict[index].append((name, tmp_attrs, - self.EVENT_START, pair_idx)) + tmp_attrs._attrs.update(active_tags[tag_name]) + eventdict[index].append((tag_name, tmp_attrs, + self.EVENT_START, 0)) # also save the index of tag opening - active_idx[name] = index + active_idx[tag_name] = index # sort events at the same index indices = eventdict.keys() diff --git a/src/docgen/GtkPrint.py b/src/docgen/GtkPrint.py index d79cc9485..6004a5b7c 100644 --- a/src/docgen/GtkPrint.py +++ b/src/docgen/GtkPrint.py @@ -18,7 +18,11 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: PdfDoc.py 7855 2006-12-29 03:58:26Z dallingham $ +# $Id$ + +"Printing interface based on gtk.Print*" + +__revision__ = "$Revision$" #------------------------------------------------------------------------ # @@ -29,7 +33,7 @@ from gettext import gettext as _ #------------------------------------------------------------------------ # -# gramps modules +# Gramps modules # #------------------------------------------------------------------------ import BaseDoc @@ -44,22 +48,20 @@ import Errors import logging log = logging.getLogger(".GtkDoc") -#------------------------------------------------------------------------ +#------------------------------------------------------------------------- # -# GtkPrint +# GTK modules # -#------------------------------------------------------------------------ - -import pygtk +#------------------------------------------------------------------------- +##import pygtk import gtk - -if not hasattr(gtk, "PrintOperation"): - raise Errors.UnavailableError( - _("Cannot be loaded because PyGtk 2.10 or later is not installed")) - import cairo import pango +##if not hasattr(gtk, "PrintOperation"): +if gtk.pygtk_version < (2,10,0): + raise Errors.UnavailableError( + _("Cannot be loaded because PyGtk 2.10 or later is not installed")) #------------------------------------------------------------------------ # @@ -445,7 +447,6 @@ class GtkDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc,BaseDoc.DrawDoc): # Register the document generator with the GRAMPS plugin system # #------------------------------------------------------------------------ -register_text_doc(_('GtkPrint'), GtkDoc,1, 1, 1,"", None) -register_draw_doc(_('GtkPrint'), GtkDoc,1, 1, "", None) -register_book_doc(name=_("GtkPrint"),classref=GtkDoc, - table=1,paper=1,style=1,ext="") +register_text_doc(_('GtkPrint'), GtkDoc, 1, 1, 1, "", None) +register_draw_doc(_('GtkPrint'), GtkDoc, 1, 1, "", None) +register_book_doc(_("GtkPrint"), GtkDoc, 1, 1, 1, "", None)