Updated to allow photo positioning

svn: r567
This commit is contained in:
Don Allingham 2001-11-13 23:34:29 +00:00
parent 0ee5d8eaa3
commit 3fb88a7aa2
12 changed files with 111 additions and 114 deletions

View File

@ -103,15 +103,15 @@ class AbiWordDoc(TextDoc):
self.f.write('</abiword>\n') self.f.write('</abiword>\n')
self.f.close() self.f.close()
def add_photo(self,name,x,y): def add_photo(self,pos,name,x_cm,y_cm):
import GdkImlib import GdkImlib
image = GdkImlib.Image(name) image = GdkImlib.Image(name)
scale = float(image.rgb_width)/float(image.rgb_height) scale = float(image.rgb_width)/float(image.rgb_height)
act_width = x * scale act_width = int(((x_cm * scale)*2.54)*72)
act_height = y * scale 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) base = "/tmp/%s.png" % os.path.basename(name)
tag = string.replace(base,'.','_') tag = string.replace(base,'.','_')

View File

@ -22,20 +22,7 @@ from RelLib import *
import string import string
import utils import utils
import xml.parsers.expat
#-------------------------------------------------------------------------
#
# 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
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -62,7 +49,7 @@ def fix_spaces(text_list):
# Gramps database parsing class. Derived from SAX XML parser # 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_index = 0
self.func = None self.func = None
handler.ContentHandler.__init__(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)
#---------------------------------------------------------------------
def setDocumentLocator(self,locator):
self.locator = locator
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def endDocument(self):
self.db.setResearcher(self.owner) self.db.setResearcher(self.owner)
if self.tempDefault != None: if self.tempDefault != None:
id = self.tempDefault id = self.tempDefault
@ -145,32 +122,17 @@ class GrampsParser(handler.ContentHandler):
person = self.db.personMap[id] person = self.db.personMap[id]
self.db.setDefaultPerson(person) self.db.setDefaultPerson(person)
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_place(self,attrs): def start_place(self,attrs):
if attrs.has_key('ref'): if attrs.has_key('ref'):
self.placeobj = self.db.findPlaceNoMap(u2l(attrs['ref'])) self.placeobj = self.db.findPlaceNoMap(u2l(attrs['ref']))
else: else:
self.placeobj = None self.placeobj = None
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_placeobj(self,attrs): def start_placeobj(self,attrs):
self.placeobj = self.db.findPlaceNoMap(u2l(attrs['id'])) self.placeobj = self.db.findPlaceNoMap(u2l(attrs['id']))
self.placeobj.set_title(u2l(attrs['title'])) self.placeobj.set_title(u2l(attrs['title']))
self.locations = 0 self.locations = 0
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def start_location(self,attrs): def start_location(self,attrs):
loc = Location() loc = Location()
if attrs.has_key('city'): if attrs.has_key('city'):

View File

@ -258,7 +258,7 @@ class HtmlDoc(TextDoc):
self.f.write(line) self.f.write(line)
self.f.close() self.f.close()
def add_photo(self,name,x,y): def add_photo(self,name,pos,x,y):
if no_pil: if no_pil:
return return
@ -293,8 +293,15 @@ class HtmlDoc(TextDoc):
except: except:
return return
self.f.write('<img src="images/%s" border="0" width="%d" height="%d">\n' % \ if pos == "right":
(refname,pixx,pixy)) xtra = ' align="right"'
elif pos == "left" :
xtra = ' align="left"'
else:
xtra = ''
self.f.write('<img src="images/%s" border="0" width="%d" height="%d"%s>\n' % \
(refname,pixx,pixy,xtra))
def start_table(self,name,style): def start_table(self,name,style):
self.tbl = self.table_styles[style] self.tbl = self.table_styles[style]

View File

@ -352,7 +352,7 @@ class KwordDoc(TextDoc):
def end_cell(self): def end_cell(self):
pass pass
def add_photo(self,name,x,y): def add_photo(self,name,pos,x,y):
if no_pil: if no_pil:
return return

View File

@ -121,7 +121,7 @@ class LaTeXDoc(TextDoc):
def end_cell(self): def end_cell(self):
pass pass
def add_photo(self,name,x,y): def add_photo(self,name,pos,x,y):
pass pass
def horizontal_line(self): def horizontal_line(self):

View File

@ -158,6 +158,64 @@ class OpenOfficeDoc(TextDoc):
self.f.write('<style:style style:name="Tbold" style:family="text">\n') self.f.write('<style:style style:name="Tbold" style:family="text">\n')
self.f.write('<style:properties fo:font-weight="bold"/>\n') self.f.write('<style:properties fo:font-weight="bold"/>\n')
self.f.write('</style:style>\n') self.f.write('</style:style>\n')
#Begin photo style
self.f.write('<style:style style:name="Left" style:family="graphics"')
self.f.write(' style:parent-name="photo">')
self.f.write('<style:properties style:run-through="foreground"')
self.f.write(' style:wrap="parallel"')
self.f.write(' style:numer-wrapped-paragraphs="no-limit"')
self.f.write(' style:wrap-contour="false" style:vertical-pos="from-top"')
self.f.write(' style:vertical-rel="paragraph-content"')
self.f.write(' style:horizontal-pos="left"')
self.f.write(' style:horizontal-rel="paragraph-contnet"')
self.f.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
self.f.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
self.f.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
self.f.write(' draw:color-inversion="false" draw:transparency="-100%"')
self.f.write(' draw:color-mode="standard"/>')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="Right" style:family="graphics"')
self.f.write(' style:parent-name="photo">')
self.f.write('<style:properties style:run-through="foreground"')
self.f.write(' style:wrap="parallel"')
self.f.write(' style:numer-wrapped-paragraphs="no-limit"')
self.f.write(' style:wrap-contour="false" style:vertical-pos="from-top"')
self.f.write(' style:vertical-rel="paragraph-content"')
self.f.write(' style:horizontal-pos="right"')
self.f.write(' style:horizontal-rel="paragraph-contnet"')
self.f.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
self.f.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
self.f.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
self.f.write(' draw:color-inversion="false" draw:transparency="-100%"')
self.f.write(' draw:color-mode="standard"/>')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="Single" style:family="graphics"')
self.f.write(' style:parent-name="Graphics">')
self.f.write('<style:properties style:vertical-pos="from-top"')
self.f.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
self.f.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
self.f.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
self.f.write(' draw:color-inversion="false" draw:transparency="-100%"')
self.f.write(' draw:color-mode="standard"/>')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="Row" style:family="graphics"')
self.f.write(' style:parent-name="Graphics">')
self.f.write('<style:properties style:vertical-pos="from-top"')
self.f.write(' style:vertical-rel="paragraph"')
self.f.write(' style:horizontal-pos="from-left" syle:horizontal-rel="paragraph"')
self.f.write(' style:mirror="none" fo:clip="rect(0cm 0cm 0cm 0cm)"')
self.f.write(' draw:luminance="0%" draw:contrast="0" draw:red="0%"')
self.f.write(' draw:green="0%" draw:blue="0%" draw:gamma="1"')
self.f.write(' draw:color-inversion="false" draw:transparency="-100%"')
self.f.write(' draw:color-mode="standard"/>')
self.f.write('</style:style>\n')
#end of Photo style edits
self.f.write('</office:automatic-styles>\n') self.f.write('</office:automatic-styles>\n')
self.f.write('<office:body>\n') self.f.write('<office:body>\n')
@ -171,25 +229,33 @@ class OpenOfficeDoc(TextDoc):
self._write_photos() self._write_photos()
self._write_zip() self._write_zip()
def add_photo(self,name,x,y): def add_photo(self,name,pos,x_cm,y_cm):
import GdkImlib import GdkImlib
image = GdkImlib.Image(name) image = GdkImlib.Image(name)
scale = float(image.rgb_width)/float(image.rgb_height) scale = float(image.rgb_width)/float(image.rgb_height)
act_width = x * scale act_width = int(((x_cm * scale)*2.54)*72)
act_height = y * scale 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) base = os.path.basename(name)
tag = string.replace(base,'.','_') tag = string.replace(base,'.','_')
self.f.write('<draw:image draw:style-name="photo" ') if pos == "left":
self.f.write('<draw:image draw:style-name="Left" ')
elif pos == "right":
self.f.write('<draw:image draw:style-name="Right" ')
elif pos == "single":
self.f.write('<draw:image draw:style-name="Single" ')
else:
self.f.write('<draw:image draw:style-name="Row" ')
self.f.write('draw:name="') self.f.write('draw:name="')
self.f.write(tag) self.f.write(tag)
self.f.write('" text:anchor-type="paragraph" ') self.f.write('" text:anchor-type="paragraph" ')
self.f.write('svg:width="%scm" ' % cnv("%.3f",act_width)) self.f.write('svg:width="%scm" ' % cnv("%.3f",x_cm*scale))
self.f.write('svg:height="%scm" ' % cnv("%.3f",act_height)) self.f.write('svg:height="%scm" ' % cnv("%.3f",y_cm*scale))
self.f.write('draw:z-index="0" ') self.f.write('draw:z-index="0" ')
self.f.write('xlink:href="#Pictures/') self.f.write('xlink:href="#Pictures/')
self.f.write(base) self.f.write(base)

View File

@ -257,7 +257,7 @@ class PdfDoc(TextDoc):
self.col = self.col + self.span self.col = self.col + self.span
def add_photo(self,name,x,y): def add_photo(self,name,pos,x,y):
if no_pil == 0: if no_pil == 0:
im = PIL.Image.open(name) im = PIL.Image.open(name)

View File

@ -325,7 +325,7 @@ class RTFDoc(TextDoc):
# photo. # photo.
# #
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def add_photo(self,name,x,y): def add_photo(self,name,pos,x_cm,y_cm):
if no_pil: if no_pil:
return return
@ -336,11 +336,12 @@ class RTFDoc(TextDoc):
scale = float(ny)/float(nx) scale = float(ny)/float(nx)
if scale > 1: if scale > 1:
scale = 1.0/scale scale = 1.0/scale
act_width = twips(x * scale) act_width = twips(x_cm * scale)
act_height = twips(y * scale) act_height = twips(y_cm * scale)
im.thumbnail((int(act_width*40),int(act_height*40))) im.thumbnail((int(act_width*40),int(act_height*40)))
self.f.write('{\*\shppict{\\pict\\jpegblip\\picwgoal%d\\pichgoal%d\n' % (x,y)) self.f.write('{\*\shppict{\\pict\\jpegblip')
self.f.write('\\picwgoal%d\\pichgoal%d\n' % (act_width,act_height))
index = 1 index = 1
for i in buf: for i in buf:
self.f.write('%02x' % ord(i)) self.f.write('%02x' % ord(i))

View File

@ -54,17 +54,6 @@ try:
except: except:
gzip_ok = 0 gzip_ok = 0
#-------------------------------------------------------------------------
#
# Try to abstract SAX1 from SAX2
#
#-------------------------------------------------------------------------
try:
from xml.sax import make_parser, SAXParseException, SAXReaderNotAvailable
except:
from _xmlplus.sax import make_parser, SAXParseException, SAXReaderNotAvailable
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Initialization function for the module. Called to start the reading # Initialization function for the module. Called to start the reading
@ -78,15 +67,7 @@ def importData(database, filename, callback):
database.pmap = {} database.pmap = {}
database.fmap = {} database.fmap = {}
try: parser = GrampsImportParser(database,callback,basefile)
parser = make_parser()
except SAXReaderNotAvailable:
msg1 = _("GRAMPS is not able to find an XML parser on your system.")
msg2 = _("This is probably due to an incomplete python or PyXML installation")
GnomeErrorDialog("%s\n%s" % (msg1,msg2))
return
parser.setContentHandler(GrampsImportParser(database,callback,basefile))
if gzip_ok: if gzip_ok:
use_gzip = 1 use_gzip = 1
@ -114,11 +95,6 @@ def importData(database, filename, callback):
try: try:
parser.parse(xml_file) parser.parse(xml_file)
except SAXParseException:
GnomeErrorDialog(_("%s is a corrupt file") % filename)
import traceback
traceback.print_exc()
return 0
except IOError,msg: except IOError,msg:
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg)) GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
import traceback import traceback
@ -147,8 +123,7 @@ def loadData(database, filename, callback=None):
filename = os.path.normpath(filename) filename = os.path.normpath(filename)
parser = make_parser() parser = GrampsParser(database,callback,basefile)
parser.setContentHandler(GrampsParser(database,callback,basefile))
if gzip_ok: if gzip_ok:
use_gzip = 1 use_gzip = 1
@ -177,13 +152,6 @@ def loadData(database, filename, callback=None):
try: try:
parser.parse(xml_file) parser.parse(xml_file)
except SAXParseException,msg:
line = string.split(str(msg),':')
filemsg = _("%s is a corrupt file.") % filename
errtype = string.strip(line[3])
errmsg = _('A "%s" error on line %s was detected.') % (errtype,line[1])
GnomeErrorDialog("%s\n%s" % (filemsg,errmsg))
return 0
except IOError,msg: except IOError,msg:
errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg)) errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg))
GnomeErrorDialog(errmsg) GnomeErrorDialog(errmsg)
@ -212,20 +180,12 @@ def loadRevision(database, file, filename, revision, callback=None):
database.pmap = {} database.pmap = {}
database.fmap = {} database.fmap = {}
parser = make_parser() parser = GrampsParser(database,callback,basefile)
parser.setContentHandler(GrampsParser(database,callback,basefile))
filename = _("%s (revision %s)") % (filename,revision) filename = _("%s (revision %s)") % (filename,revision)
try: try:
parser.parse(file) parser.parse(file)
except SAXParseException,msg:
line = string.split(str(msg),':')
filemsg = _("%s is a corrupt file.") % filename
errtype = string.strip(line[3])
errmsg = _('A "%s" error on line %s was detected.') % (errtype,line[1])
GnomeErrorDialog("%s\n%s" % (filemsg,errmsg))
return 0
except IOError,msg: except IOError,msg:
errmsg = "%s\n%s" % (_("Error reading %s") % filename, str(msg)) errmsg = "%s\n%s" % (_("Error reading %s") % filename, str(msg))
GnomeErrorDialog(errmsg) GnomeErrorDialog(errmsg)

View File

@ -576,7 +576,8 @@ class TextDoc:
self.name = "" self.name = ""
self.photo_list = [] self.photo_list = []
def add_photo(self,name,x,y): def add_photo(self,name,align,w_cm,h_cm):
"""adds a photo of the specified width (in centimeters)"""
pass pass
def get_usable_width(self): def get_usable_width(self):

View File

@ -222,7 +222,7 @@ class IndivSummary:
if object.getMimeType()[0:5] == "image": if object.getMimeType()[0:5] == "image":
file = object.getPath() file = object.getPath()
self.d.start_paragraph("Normal") self.d.start_paragraph("Normal")
self.d.add_photo(file,4.0,4.0) self.d.add_photo(file,"row",4.0,4.0)
self.d.end_paragraph() self.d.end_paragraph()
self.d.start_table("one","IndTable") self.d.start_table("one","IndTable")

View File

@ -257,7 +257,7 @@ class IndividualPage:
if object.getMimeType()[0:5] == "image": if object.getMimeType()[0:5] == "image":
file = object.getPath() file = object.getPath()
self.doc.start_paragraph("Data") self.doc.start_paragraph("Data")
self.doc.add_photo(file,4.0,4.0) self.doc.add_photo(file,"row",4.0,4.0)
self.doc.end_paragraph() self.doc.end_paragraph()
# Start the first table, which consists of basic information, including # Start the first table, which consists of basic information, including
@ -346,7 +346,7 @@ class IndividualPage:
src = obj.getReference().getPath() src = obj.getReference().getPath()
base = os.path.basename(src) base = os.path.basename(src)
self.doc.start_link("images/%s" % base) self.doc.start_link("images/%s" % base)
self.doc.add_photo(src,1.5,1.5) self.doc.add_photo(src,"row",1.5,1.5)
shutil.copy(src,"%s/images/%s" % (self.dir,base)) shutil.copy(src,"%s/images/%s" % (self.dir,base))
self.doc.end_link() self.doc.end_link()