From 3fb88a7aa24092389cc9593afda27bd78f863e30 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 13 Nov 2001 23:34:29 +0000 Subject: [PATCH] Updated to allow photo positioning svn: r567 --- gramps/src/AbiWordDoc.py | 8 +-- gramps/src/GrampsParser.py | 54 +++----------------- gramps/src/HtmlDoc.py | 13 +++-- gramps/src/KwordDoc.py | 2 +- gramps/src/LaTeXDoc.py | 2 +- gramps/src/OpenOfficeDoc.py | 80 +++++++++++++++++++++++++++--- gramps/src/PdfDoc.py | 2 +- gramps/src/RTFDoc.py | 9 ++-- gramps/src/ReadXML.py | 46 ++--------------- gramps/src/TextDoc.py | 3 +- gramps/src/plugins/IndivSummary.py | 2 +- gramps/src/plugins/WebPage.py | 4 +- 12 files changed, 111 insertions(+), 114 deletions(-) diff --git a/gramps/src/AbiWordDoc.py b/gramps/src/AbiWordDoc.py index e4d3ac846..ee027e36b 100644 --- a/gramps/src/AbiWordDoc.py +++ b/gramps/src/AbiWordDoc.py @@ -103,15 +103,15 @@ class AbiWordDoc(TextDoc): self.f.write('\n') self.f.close() - def add_photo(self,name,x,y): + def add_photo(self,pos,name,x_cm,y_cm): import GdkImlib image = GdkImlib.Image(name) scale = float(image.rgb_width)/float(image.rgb_height) - act_width = x * scale - act_height = y * scale + act_width = int(((x_cm * scale)*2.54)*72) + act_height = int(((y_cm * scale)*2.54)*72) - self.photo_list.append((name,act_width*40,act_height*40)) + self.photo_list.append((name,act_width,act_height)) base = "/tmp/%s.png" % os.path.basename(name) tag = string.replace(base,'.','_') diff --git a/gramps/src/GrampsParser.py b/gramps/src/GrampsParser.py index d26a448bf..d2da91e10 100644 --- a/gramps/src/GrampsParser.py +++ b/gramps/src/GrampsParser.py @@ -22,20 +22,7 @@ from RelLib import * import string import utils - -#------------------------------------------------------------------------- -# -# Find a parser. xml.sax should be available, but it is possible that -# someone has removed it in favor of the PyXML distribution, which -# defined a _xmlplux.sax -# -#------------------------------------------------------------------------- -try: - from xml.sax import handler - from xml.sax import make_parser -except: - from _xmlplus.sax import handler - from _xmlplus.sax import make_parser +import xml.parsers.expat #------------------------------------------------------------------------- # @@ -62,7 +49,7 @@ def fix_spaces(text_list): # Gramps database parsing class. Derived from SAX XML parser # #------------------------------------------------------------------------- -class GrampsParser(handler.ContentHandler): +class GrampsParser: #--------------------------------------------------------------------- # @@ -122,22 +109,12 @@ class GrampsParser(handler.ContentHandler): self.func_index = 0 self.func = None - handler.ContentHandler.__init__(self) - - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- - def setDocumentLocator(self,locator): - self.locator = locator - - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- - def endDocument(self): + def parse(self,file): + p = xml.parsers.expat.ParserCreate() + p.StartElementHandler = self.startElement + p.EndElementHandler = self.endElement + p.CharacterDataHandler = self.characters + p.ParseFile(file) self.db.setResearcher(self.owner) if self.tempDefault != None: id = self.tempDefault @@ -145,32 +122,17 @@ class GrampsParser(handler.ContentHandler): person = self.db.personMap[id] self.db.setDefaultPerson(person) - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- def start_place(self,attrs): if attrs.has_key('ref'): self.placeobj = self.db.findPlaceNoMap(u2l(attrs['ref'])) else: self.placeobj = None - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- def start_placeobj(self,attrs): self.placeobj = self.db.findPlaceNoMap(u2l(attrs['id'])) self.placeobj.set_title(u2l(attrs['title'])) self.locations = 0 - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- def start_location(self,attrs): loc = Location() if attrs.has_key('city'): diff --git a/gramps/src/HtmlDoc.py b/gramps/src/HtmlDoc.py index 35418dd08..99a0f6c1a 100644 --- a/gramps/src/HtmlDoc.py +++ b/gramps/src/HtmlDoc.py @@ -258,7 +258,7 @@ class HtmlDoc(TextDoc): self.f.write(line) self.f.close() - def add_photo(self,name,x,y): + def add_photo(self,name,pos,x,y): if no_pil: return @@ -293,8 +293,15 @@ class HtmlDoc(TextDoc): except: return - self.f.write('\n' % \ - (refname,pixx,pixy)) + if pos == "right": + xtra = ' align="right"' + elif pos == "left" : + xtra = ' align="left"' + else: + xtra = '' + + self.f.write('\n' % \ + (refname,pixx,pixy,xtra)) def start_table(self,name,style): self.tbl = self.table_styles[style] diff --git a/gramps/src/KwordDoc.py b/gramps/src/KwordDoc.py index a446b7df8..c0e33a60a 100644 --- a/gramps/src/KwordDoc.py +++ b/gramps/src/KwordDoc.py @@ -352,7 +352,7 @@ class KwordDoc(TextDoc): def end_cell(self): pass - def add_photo(self,name,x,y): + def add_photo(self,name,pos,x,y): if no_pil: return diff --git a/gramps/src/LaTeXDoc.py b/gramps/src/LaTeXDoc.py index 734b441ca..f07b878c1 100644 --- a/gramps/src/LaTeXDoc.py +++ b/gramps/src/LaTeXDoc.py @@ -121,7 +121,7 @@ class LaTeXDoc(TextDoc): def end_cell(self): pass - def add_photo(self,name,x,y): + def add_photo(self,name,pos,x,y): pass def horizontal_line(self): diff --git a/gramps/src/OpenOfficeDoc.py b/gramps/src/OpenOfficeDoc.py index 1a53a6a80..b55d54f71 100644 --- a/gramps/src/OpenOfficeDoc.py +++ b/gramps/src/OpenOfficeDoc.py @@ -158,6 +158,64 @@ class OpenOfficeDoc(TextDoc): self.f.write('\n') self.f.write('\n') self.f.write('\n') + + #Begin photo style + self.f.write('') + self.f.write('') + self.f.write('\n') + + self.f.write('') + self.f.write('') + self.f.write('\n') + + self.f.write('') + self.f.write('') + self.f.write('\n') + + self.f.write('') + self.f.write('') + self.f.write('\n') + + #end of Photo style edits + self.f.write('\n') self.f.write('\n') @@ -171,25 +229,33 @@ class OpenOfficeDoc(TextDoc): self._write_photos() self._write_zip() - def add_photo(self,name,x,y): + def add_photo(self,name,pos,x_cm,y_cm): import GdkImlib image = GdkImlib.Image(name) scale = float(image.rgb_width)/float(image.rgb_height) - act_width = x * scale - act_height = y * scale + act_width = int(((x_cm * scale)*2.54)*72) + act_height = int(((y_cm * scale)*2.54)*72) - self.photo_list.append((name,int(act_width)*40,int(act_height)*40)) + self.photo_list.append((name,act_width,act_height)) base = os.path.basename(name) tag = string.replace(base,'.','_') - self.f.write('