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.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,'.','_')

View File

@ -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'):

View File

@ -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('<img src="images/%s" border="0" width="%d" height="%d">\n' % \
(refname,pixx,pixy))
if pos == "right":
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):
self.tbl = self.table_styles[style]

View File

@ -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

View File

@ -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):

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:properties fo:font-weight="bold"/>\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:body>\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('<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(tag)
self.f.write('" text:anchor-type="paragraph" ')
self.f.write('svg:width="%scm" ' % cnv("%.3f",act_width))
self.f.write('svg:height="%scm" ' % cnv("%.3f",act_height))
self.f.write('svg:width="%scm" ' % cnv("%.3f",x_cm*scale))
self.f.write('svg:height="%scm" ' % cnv("%.3f",y_cm*scale))
self.f.write('draw:z-index="0" ')
self.f.write('xlink:href="#Pictures/')
self.f.write(base)

View File

@ -257,7 +257,7 @@ class PdfDoc(TextDoc):
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:
im = PIL.Image.open(name)

View File

@ -325,7 +325,7 @@ class RTFDoc(TextDoc):
# photo.
#
#--------------------------------------------------------------------
def add_photo(self,name,x,y):
def add_photo(self,name,pos,x_cm,y_cm):
if no_pil:
return
@ -336,11 +336,12 @@ class RTFDoc(TextDoc):
scale = float(ny)/float(nx)
if scale > 1:
scale = 1.0/scale
act_width = twips(x * scale)
act_height = twips(y * scale)
act_width = twips(x_cm * scale)
act_height = twips(y_cm * scale)
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
for i in buf:
self.f.write('%02x' % ord(i))

View File

@ -54,17 +54,6 @@ try:
except:
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
@ -78,15 +67,7 @@ def importData(database, filename, callback):
database.pmap = {}
database.fmap = {}
try:
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))
parser = GrampsImportParser(database,callback,basefile)
if gzip_ok:
use_gzip = 1
@ -114,11 +95,6 @@ def importData(database, filename, callback):
try:
parser.parse(xml_file)
except SAXParseException:
GnomeErrorDialog(_("%s is a corrupt file") % filename)
import traceback
traceback.print_exc()
return 0
except IOError,msg:
GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg))
import traceback
@ -147,8 +123,7 @@ def loadData(database, filename, callback=None):
filename = os.path.normpath(filename)
parser = make_parser()
parser.setContentHandler(GrampsParser(database,callback,basefile))
parser = GrampsParser(database,callback,basefile)
if gzip_ok:
use_gzip = 1
@ -177,13 +152,6 @@ def loadData(database, filename, callback=None):
try:
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:
errmsg = "%s\n%s" % (_("Error reading %s") % filename,str(msg))
GnomeErrorDialog(errmsg)
@ -212,20 +180,12 @@ def loadRevision(database, file, filename, revision, callback=None):
database.pmap = {}
database.fmap = {}
parser = make_parser()
parser.setContentHandler(GrampsParser(database,callback,basefile))
parser = GrampsParser(database,callback,basefile)
filename = _("%s (revision %s)") % (filename,revision)
try:
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:
errmsg = "%s\n%s" % (_("Error reading %s") % filename, str(msg))
GnomeErrorDialog(errmsg)

View File

@ -576,7 +576,8 @@ class TextDoc:
self.name = ""
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
def get_usable_width(self):

View File

@ -222,7 +222,7 @@ class IndivSummary:
if object.getMimeType()[0:5] == "image":
file = object.getPath()
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.start_table("one","IndTable")

View File

@ -257,7 +257,7 @@ class IndividualPage:
if object.getMimeType()[0:5] == "image":
file = object.getPath()
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()
# Start the first table, which consists of basic information, including
@ -346,7 +346,7 @@ class IndividualPage:
src = obj.getReference().getPath()
base = os.path.basename(src)
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))
self.doc.end_link()