diff --git a/gramps/src/GraphLayout.py b/gramps/src/GraphLayout.py index d95984a7b..5b15db81e 100644 --- a/gramps/src/GraphLayout.py +++ b/gramps/src/GraphLayout.py @@ -43,9 +43,9 @@ class DescendLine(GraphLayout): def space_for(self,person,level=1.0,pos=1.0): last = self.elist[-1] - self.elist.append(level,pos) - self.e.append(last[0],last[1],level,pos) - self.v.append(person,level,pos) + self.elist.append((level,pos)) + self.e.append((last[0],last[1],level,pos)) + self.v.append((person,level,pos)) if level > self.maxx: self.maxx = level if pos > self.maxy: diff --git a/gramps/src/ImgManip.py b/gramps/src/ImgManip.py index 1b10fbf0f..1af364413 100644 --- a/gramps/src/ImgManip.py +++ b/gramps/src/ImgManip.py @@ -20,6 +20,7 @@ import os import const +import string #------------------------------------------------------------------------- # @@ -29,6 +30,7 @@ import const try: import PIL.Image import StringIO + PIL.Image.init() no_pil = 0 except: import popen2 @@ -91,21 +93,26 @@ class ImgManip: if im.mode != 'RGB': im.draft('RGB',im.size) im = im.convert("RGB") - im.save(dest,pil) + im.save(dest,string.upper(pil)) def fmt_convert(self,dest,pil): im = PIL.Image.open(self.src) if im.mode != 'RGB': im.draft('RGB',im.size) im = im.convert("RGB") - im.save(dest,pil) + im.save(dest,string.upper(pil)) def fmt_data(self,pil): + g = StringIO.StringIO() im = PIL.Image.open(self.src) if im.mode != 'RGB': im.draft('RGB',im.size) im = im.convert("RGB") - return im.tostring(pil,"RGB") + im.save(g,string.upper(pil)) + g.seek(0) + buf = g.read() + g.close() + return buf def fmt_scale_data(self,x,y,pil): im = PIL.Image.open(self.src) @@ -113,7 +120,7 @@ class ImgManip: if im.mode != 'RGB': im.draft('RGB',im.size) im = im.convert("RGB") - return im.tostring(pil,"RGB") + return im.tostring(string.upper(pil),"RGB") def eps_data(self): g = StringIO.StringIO() @@ -168,10 +175,10 @@ class ImgManip: return self.fmt_data("png") def jpg_scale_data(self,x,y): - return self.fmt(x,y,"jpeg") + return self.fmt_scale_data(x,y,"jpeg") def png_scale_data(self,x,y): - return self.fmt(x,y,"png") + return self.fmt_scale_data(x,y,"png") if __name__ == "__main__": diff --git a/gramps/src/RelLib.py b/gramps/src/RelLib.py index 9ce4325f4..d3cfc8e91 100644 --- a/gramps/src/RelLib.py +++ b/gramps/src/RelLib.py @@ -223,7 +223,7 @@ class Place(SourceNote): self.long = "" self.lat = "" self.title = "" - self.main_loc = Location() + self.main_loc = None self.alt_loc = [] self.id = "" self.urls = [] @@ -275,6 +275,8 @@ class Place(SourceNote): def get_main_location(self): """Returns the Location object representing the primary information""" + if not self.main_loc: + self.main_loc = Location() return self.main_loc def set_main_location(self,loc): @@ -1868,16 +1870,16 @@ class RelDataBase: self.pmapIndex = self.pmapIndex+1 return id - def findPersonNoMap(self,idVal): + def findPersonNoMap(self,val): """finds a Person in the database from the passed gramps' ID. If no such Person exists, a new Person is added to the database.""" - val = str(idVal) - if self.personMap.has_key(val): - person = self.personMap[val] - else: + person = self.personMap.get(val) + if not person: person = Person() - self.addPersonNoMap(person,val) + person.id = val + self.personMap[val] = person + self.pmapIndex = self.pmapIndex+1 return person def addSource(self,source): @@ -1902,7 +1904,6 @@ class RelDataBase: idVal - external ID number map - map build by findSource of external to gramp's IDs""" - idVal = str(idVal) if map.has_key(idVal): source = self.sourceMap[map[idVal]] else: @@ -1912,17 +1913,15 @@ class RelDataBase: def addSourceNoMap(self,source,index): """adds a Source to the database if the gramps' ID is known""" - index = str(index) source.setId(index) self.sourceMap[index] = source self.smapIndex = self.smapIndex + 1 return index - def findSourceNoMap(self,idVal): + def findSourceNoMap(self,val): """finds a Source in the database from the passed gramps' ID. If no such Source exists, a new Source is added to the database.""" - val = str(idVal) if self.sourceMap.has_key(val): source = self.sourceMap[val] else: @@ -2019,16 +2018,16 @@ class RelDataBase: self.lmapIndex = self.lmapIndex + 1 return index - def findPlaceNoMap(self,idVal): + def findPlaceNoMap(self,val): """finds a Place in the database from the passed gramps' ID. If no such Place exists, a new Place is added to the database.""" - val = str(idVal) - if self.placeMap.has_key(val): - place = self.placeMap[val] - else: + place = self.placeMap.get(val) + if not place: place = Place() - self.addPlaceNoMap(place,val) + place.id = val + self.placeMap[val] = place + self.lmapIndex = self.lmapIndex + 1 return place def newFamily(self): @@ -2063,7 +2062,6 @@ class RelDataBase: idVal - external ID number map - map build by findFamily of external to gramp's IDs""" - idVal = str(idVal) if map.has_key(idVal): family = self.familyMap[map[idVal]] else: @@ -2071,14 +2069,16 @@ class RelDataBase: map[idVal] = family.getId() return family - def findFamilyNoMap(self,idVal): + def findFamilyNoMap(self,val): """finds a Family in the database from the passed gramps' ID. If no such Family exists, a new Family is added to the database.""" - val = str(idVal) - if self.familyMap.has_key(val): - family = self.familyMap[val] - else: - family = self.newFamilyNoMap(val) + + family = self.familyMap.get(val) + if not family: + family = Family() + family.id = val + self.familyMap[val] = family + self.fmapIndex = self.fmapIndex + 1 return family def deleteFamily(self,family): diff --git a/gramps/src/docgen/AbiWordDoc.py b/gramps/src/docgen/AbiWordDoc.py index 90ba8268c..ebc78ed96 100644 --- a/gramps/src/docgen/AbiWordDoc.py +++ b/gramps/src/docgen/AbiWordDoc.py @@ -47,13 +47,14 @@ class AbiWordDoc(TextDoc): """AbiWord document generator. Inherits from the TextDoc generic document interface class.""" - def __init__(self,styles,type,orientation): + def __init__(self,styles,type,template,orientation): """Initializes the AbiWordDoc class, calling the __init__ routine of the parent TextDoc class""" - TextDoc.__init__(self,styles,type,orientation) + TextDoc.__init__(self,styles,type,template,orientation) self.f = None self.level = 0 self.new_page = 0 + self.in_table = 0 def open(self,filename): """Opens the document, writing the necessary header information. @@ -66,15 +67,18 @@ class AbiWordDoc(TextDoc): self.f = open(self.filename,"w") self.f.write('\n') - self.f.write('\n') + self.f.write('\n') + self.f.write('\n') self.f.write('\n') self.f.write('
\n') self.f.write(base64.encodestring(buf)) - os.unlink(base) self.f.write('\n') self.f.write('\n') self.f.write('\n') self.f.close() - def add_photo(self,pos,name,x_cm,y_cm): - import gtk - import GdkImlib + def add_photo(self,name,pos,x_cm,y_cm): + + image = ImgManip.ImgManip(name) + (x,y) = image.size() + aspect_ratio = float(x)/float(y) - image = GdkImlib.Image(name) - scale = float(image.rgb_width)/float(image.rgb_height) - act_width = int(((x_cm * scale)*2.54)*72) - act_height = int(((y_cm * scale)*2.54)*72) + if aspect_ratio > x_cm/y_cm: + act_width = x_cm + act_height = y_cm/aspect_ratio + else: + act_height = y_cm + act_width = x_cm*aspect_ratio self.photo_list.append((name,act_width,act_height)) @@ -129,6 +136,12 @@ class AbiWordDoc(TextDoc): self.f.write('height:%.3fin"/>' % act_height) def start_paragraph(self,style_name,leader=None): + if self.in_table: + self.start_paragraph_intable(style_name,leader) + else: + self.start_paragraph_notable(style_name,leader) + + def start_paragraph_notable(self,style_name,leader=None): style = self.style_list[style_name] self.current_style = style self.f.write('

' + if self.new_page == 1: + self.new_page = 0 + self.f.write('') def page_break(self): self.new_page = 1 def end_paragraph(self): - self.f.write('

\n') + if self.in_table: + self.cdata = self.cdata + '\t' + else: + self.f.write('

\n') def write_text(self,text): text = string.replace(text,'&','&'); # Must be first text = string.replace(text,'<','<'); text = string.replace(text,'>','>'); - self.f.write(text) + if self.in_table: + self.cdata = self.cdata + text + else: + self.f.write(text) def start_bold(self): font = self.current_style.get_font() @@ -221,4 +264,62 @@ class AbiWordDoc(TextDoc): self.f.write('; text-decoration:underline') self.f.write('">') -Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,0,1,1) + def start_table(self,name,style_name): + self.in_table = 1 + self.tblstyle = self.table_styles[style_name] + + def end_table(self): + self.in_table = 0 + + def start_row(self): + self.tabs = [] + self.ledge = 0.0 + self.col = 0 + self.cdatalist = [] + + def end_row(self): + first = 0 + self.f.write(' 0: + self.f.write(' props="tabstops:') + for val,t in self.tabs: + if val == oldv: + if t == 'B0': + useb = 1 + continue + oldv = val + if not first: + first = 1 + else: + self.f.write(',') + edge = (val * self.get_usable_width()) + + if val == 1.0: + edge = edge-0.1 + elif val == 0.0: + edge = edge+0.1 + if useb: + t = 'B0' + self.f.write("%6.4fin/%s" % (edge/2.54,t)) + self.f.write('"') + self.f.write('>') + last = len(self.cdatalist) + for data in self.cdatalist: + self.f.write(data) + self.f.write('

\n') + + def start_cell(self,style_name,span=1): + self.cstyle = self.cell_styles[style_name] + for i in range(self.col,self.col+span): + self.col = self.col + 1 + self.ledge = self.ledge + self.tblstyle.get_column_width(i) + self.tabs.append((self.ledge/100.0,"L")) + + def end_cell(self): + self.cdata = self.cdata + "" + self.cdatalist.append(self.cdata) + +Plugins.register_text_doc(_("AbiWord"),AbiWordDoc,1,1,1) diff --git a/gramps/src/docgen/PdfDoc.py b/gramps/src/docgen/PdfDoc.py index e046ca158..085990b02 100644 --- a/gramps/src/docgen/PdfDoc.py +++ b/gramps/src/docgen/PdfDoc.py @@ -238,21 +238,21 @@ class PdfDoc(TextDoc): self.tblstyle.append(('FONT', loc, loc, fn, f.get_size())) if self.span == 1 or inc == self.col + self.span - 1: if self.my_table_style.get_right_border(): - self.tblstyle.append('LINEAFTER', loc, loc, 1, black) + self.tblstyle.append(('LINEAFTER', loc, loc, 1, black)) if self.span == 1 or inc == self.col: if self.my_table_style.get_left_border(): - self.tblstyle.append('LINEBEFORE', loc, loc, 1, black) + self.tblstyle.append(('LINEBEFORE', loc, loc, 1, black)) if self.my_table_style.get_top_border(): - self.tblstyle.append('LINEABOVE', loc, loc, 1, black) + self.tblstyle.append(('LINEABOVE', loc, loc, 1, black)) if self.my_table_style.get_bottom_border(): - self.tblstyle.append('LINEBELOW', loc, loc, 1, black) + self.tblstyle.append(('LINEBELOW', loc, loc, 1, black)) if p.get_alignment() == PARA_ALIGN_LEFT: - self.tblstyle.append('ALIGN', loc, loc, 'LEFT') + self.tblstyle.append(('ALIGN', loc, loc, 'LEFT')) elif p.get_alignment() == PARA_ALIGN_RIGHT: - self.tblstyle.append('ALIGN', loc, loc, 'RIGHT') + self.tblstyle.append(('ALIGN', loc, loc, 'RIGHT')) else: - self.tblstyle.append('ALIGN', loc, loc, 'CENTER') - self.tblstyle.append('VALIGN', loc, loc, 'TOP') + self.tblstyle.append(('ALIGN', loc, loc, 'CENTER')) + self.tblstyle.append(('VALIGN', loc, loc, 'TOP')) self.col = self.col + self.span @@ -273,6 +273,9 @@ class PdfDoc(TextDoc): self.image = 1 def write_text(self,text): + text = string.replace(text,'&','&'); # Must be first + text = string.replace(text,'<','<'); + text = string.replace(text,'>','>'); self.text = self.text + text #------------------------------------------------------------------------