diff --git a/gramps/src/DrawDoc.py b/gramps/src/DrawDoc.py
index 120eda929..62c986ba6 100644
--- a/gramps/src/DrawDoc.py
+++ b/gramps/src/DrawDoc.py
@@ -20,7 +20,32 @@
from TextDoc import *
+import string
+import os
+import sys
+import xml.sax
+import xml.sax.saxutils
+import utils
+#-------------------------------------------------------------------------
+#
+# Try to abstract SAX1 from SAX2
+#
+#-------------------------------------------------------------------------
+if sys.version[0] != '1':
+ sax = 2
+else:
+ try:
+ import xml.sax.saxexts
+ sax = 1
+ except:
+ sax = 2
+
+#------------------------------------------------------------------------
+#
+#
+#
+#------------------------------------------------------------------------
class GraphicsStyle:
def __init__(self,obj=None):
if obj:
@@ -72,7 +97,7 @@ class GraphicsStyle:
#
#------------------------------------------------------------------------
class DrawDoc:
- def __init__(self,type,orientation=PAPER_PORTRAIT):
+ def __init__(self,styles,type,orientation=PAPER_PORTRAIT):
self.orientation = orientation
if orientation == PAPER_PORTRAIT:
self.width = type.get_width()
@@ -85,9 +110,7 @@ class DrawDoc:
self.lmargin = 2.54
self.rmargin = 2.54
- self.font = FontStyle()
- self.actfont = self.font
- self.paragraph_styles = {}
+ self.style_list = styles.get_styles()
self.draw_styles = {}
self.name = ""
diff --git a/gramps/src/OpenDrawDoc.py b/gramps/src/OpenDrawDoc.py
index b6dd3ce21..61db7c5bd 100644
--- a/gramps/src/OpenDrawDoc.py
+++ b/gramps/src/OpenDrawDoc.py
@@ -37,8 +37,8 @@ except:
class OpenDrawDoc(DrawDoc):
- def __init__(self,type,orientation):
- DrawDoc.__init__(self,type,orientation)
+ def __init__(self,styles,type,orientation):
+ DrawDoc.__init__(self,styles,type,orientation)
self.f = None
self.filename = None
self.level = 0
@@ -99,8 +99,8 @@ class OpenDrawDoc(DrawDoc):
self.f.write('\n')
self.f.write('\n')
- for key in self.paragraph_styles.keys():
- style = self.paragraph_styles[key]
+ for key in self.style_list.keys():
+ style = self.style_list[key]
self.f.write('\n')
self.f.write('\n')
- for key in self.paragraph_styles.keys():
- style = self.paragraph_styles[key]
+ for key in self.style_list.keys():
+ style = self.style_list[key]
self.f.write('= 2**self.max_generations:
return
self.map[index] = person
-
+ self.text[index] = [ person.getPrimaryName().getName() ]
+
+ birth = person.getBirth()
+ if birth.getDate() != "":
+ self.text[index].append("b. %s" % birth.getDate())
+ death = person.getDeath()
+ if death.getDate() != "":
+ self.text[index].append("d. %s" % death.getDate())
+ if Config.status_bar == 1:
+ self.text[index].append("id: %s" % person.getId())
+ elif Config.status_bar == 2:
+ for attr in active_person.getAttributeList():
+ if attr.getType() == Config.attr_name:
+ txt = "%s: %s" % (Config.attr_name,attr.getValue())
+ self.text[index].append(txt)
+ break
+
+ self.font = self.doc.style_list["Normal"].get_font()
+ for line in self.text[index]:
+ self.box_width = max(self.box_width,string_width(self.font,line))
+
+ self.lines = max(self.lines,len(self.text[index]))
+
family = person.getMainFamily()
if family != None:
self.filter(family.getFather(),index*2)
self.filter(family.getMother(),(index*2)+1)
+ #--------------------------------------------------------------------
+ #
+ # filter - Generate the actual report
+ #
+ #--------------------------------------------------------------------
def write_report(self):
- self.filter(self.start,1)
-
- generation = 0
- need_header = 1
+ self.calc()
+ try:
+ self.doc.open(self.output)
+ except:
+ print "Document write failure"
generation = 1
done = 0
@@ -139,7 +149,56 @@ class AncestorReport:
self.print_page(index, generation, page)
page = page + 1
generation = generation + 3
-
+ try:
+ self.doc.close()
+ except:
+ print "Document write failure"
+
+ #--------------------------------------------------------------------
+ #
+ # calc - calculate the maximum width that a box needs to be. From
+ # that and the page dimensions, calculate the proper place to put
+ # the elements on a page.
+ #
+ #--------------------------------------------------------------------
+ def calc(self):
+ width = 0
+ self.filter(self.start,1)
+
+ print self.lines
+ self.height = self.lines*pt2cm(1.2*self.font.get_size())
+ self.box_width = pt2cm(self.box_width+20)
+
+ start = self.doc.get_right_margin()
+ delta = (self.doc.get_usable_width() - (self.box_width + 0.5))/3.0
+ uh = self.doc.get_usable_height()
+
+ ystart = self.doc.get_top_margin() - ((self.height+0.3)/2.0)
+ self.x = [start, start + delta, start + (2*delta), start + (3*delta)]
+ self.y = [ ystart + (uh/2.0), ystart + (uh/4.0),
+ ystart + 3*(uh/4.0), ystart + (uh/8.0),
+ ystart + 3*(uh/8.0), ystart + 5*(uh/8.0),
+ ystart + 7*(uh/8.0),
+ ystart + (uh/16.0), ystart + 3*(uh/16.0),
+ ystart + 5*(uh/16.0), ystart + 7*(uh/16.0),
+ ystart + 9*(uh/16.0), ystart + 11*(uh/16.0),
+ ystart + 13*(uh/16.0), ystart + 15*(uh/16.0)]
+
+ g = GraphicsStyle()
+ g.set_height(self.height)
+ g.set_width(self.box_width)
+ g.set_paragraph_style("Normal")
+ g.set_shadow(1)
+ self.doc.add_draw_style("box",g)
+
+ g = GraphicsStyle()
+ self.doc.add_draw_style("line",g)
+
+ #--------------------------------------------------------------------
+ #
+ #
+ #
+ #--------------------------------------------------------------------
def get_numbers(self,start,index,vals):
if index > 4:
return
@@ -148,30 +207,33 @@ class AncestorReport:
self.get_numbers(start*2,index+1,vals)
self.get_numbers((start*2)+1,index+1,vals)
+ #--------------------------------------------------------------------
+ #
+ #
+ #
+ #--------------------------------------------------------------------
def print_page(self,start,generation, page):
self.doc.start_page()
self.draw_graph(1,start,0)
self.doc.end_page()
+ #--------------------------------------------------------------------
+ #
+ #
+ #
+ #--------------------------------------------------------------------
def draw_graph(self,index,start,level):
if self.map.has_key(start) and index <= 15:
person = self.map[start]
- name = person.getPrimaryName().getRegularName()
-
- birth = person.getBirth()
- if birth and birth.getDate() != "":
- name = name + "\nb. " + birth.getDate()
-
- death = person.getDeath()
- if death and death.getDate() != "":
- name = name + "\nd. " + death.getDate()
+ text = self.text[start]
+ name = string.join(text,"\n")
self.doc.draw_box("box",name,self.x[level],self.y[index-1])
if index > 1:
old_index = int(index/2)-1
- x1 = self.x[level-1]+(self.width/2.0)
x2 = self.x[level]
+ x1 = self.x[level-1]+(self.x[level]-self.x[level-1])/2.0
if index % 2 == 1:
y1 = self.y[old_index]+self.height
else:
@@ -191,6 +253,7 @@ class AncestorReport:
def report(database,person):
import PaperMenu
+ global style_sheet_list
global active_person
global topDialog
global glade_file
@@ -207,17 +270,59 @@ def report(database,person):
PaperMenu.make_paper_menu(topDialog.get_widget("papersize"))
PaperMenu.make_orientation_menu(topDialog.get_widget("orientation"))
+ FindDoc.get_draw_doc_menu(topDialog.get_widget("format"),0,option_switch)
- if no_pdf == 1:
- topDialog.get_widget("pdf").set_sensitive(0)
+ styles.clear()
+ f = FontStyle()
+ f.set_size(9)
+ f.set_type_face(FONT_SANS_SERIF)
+ p = ParagraphStyle()
+ p.set_font(f)
+ styles.add_style("Normal",p)
+
+ style_sheet_list = StyleSheetList("ancestor_chart.xml",styles)
+ build_menu(None)
title = _("Ancestor Chart for %s") % name
topDialog.get_widget("labelTitle").set_text(title)
topDialog.signal_autoconnect({
"destroy_passed_object" : utils.destroy_passed_object,
+ "on_style_edit_clicked" : on_style_edit_clicked,
"on_save_clicked" : on_save_clicked
})
+#------------------------------------------------------------------------
+#
+#
+#
+#------------------------------------------------------------------------
+def build_menu(object):
+ menu = topDialog.get_widget("style_menu")
+
+ myMenu = GtkMenu()
+ for style in style_sheet_list.get_style_names():
+ menuitem = GtkMenuItem(style)
+ menuitem.set_data("d",style_sheet_list.get_style_sheet(style))
+ menuitem.show()
+ myMenu.append(menuitem)
+ menu.set_menu(myMenu)
+
+#------------------------------------------------------------------------
+#
+#
+#
+#------------------------------------------------------------------------
+def option_switch(obj):
+ pass
+
+#------------------------------------------------------------------------
+#
+#
+#
+#------------------------------------------------------------------------
+def on_style_edit_clicked(obj):
+ StyleListDisplay(style_sheet_list,build_menu,None)
+
#------------------------------------------------------------------------
#
#
@@ -238,16 +343,13 @@ def on_save_clicked(obj):
max_gen = topDialog.get_widget("generations").get_value_as_int()
- if topDialog.get_widget("openoffice").get_active():
- document = OpenDrawDoc(paper,orien)
- else:
- document = PdfDrawDoc(paper,orien)
+ item = topDialog.get_widget("format").get_menu().get_active()
+ format = item.get_data("name")
+ doc = FindDoc.make_draw_doc(styles,format,paper,orien)
- MyReport = AncestorReport(db,active_person,outputName,document,max_gen)
+ MyReport = AncestorReport(db,active_person,outputName,doc,max_gen)
- MyReport.setup()
MyReport.write_report()
- MyReport.end()
utils.destroy_passed_object(obj)
@@ -257,8 +359,7 @@ def on_save_clicked(obj):
#
#------------------------------------------------------------------------
def get_description():
- return _("Produces a graphical ancestral tree")
-
+ return _("Produces a graphical ancestral tree graph")
#------------------------------------------------------------------------
#
diff --git a/gramps/src/plugins/ancestorchart.glade b/gramps/src/plugins/ancestorchart.glade
index ace3688bf..4520894e1 100644
--- a/gramps/src/plugins/ancestorchart.glade
+++ b/gramps/src/plugins/ancestorchart.glade
@@ -180,6 +180,7 @@
GtkFrame
frame1
+ 5
0
GTK_SHADOW_ETCHED_IN
@@ -190,36 +191,65 @@
- GtkVBox
- vbox4
+ GtkOptionMenu
+ format
+ 5
+ True
+ OpenOffice
+
+ 0
+
+
+
+
+ GtkFrame
+ style_frame
+ 5
+
+ 0
+ GTK_SHADOW_ETCHED_IN
+
+ 0
+ True
+ True
+
+
+
+ GtkHBox
+ hbox3
False
0
- GtkRadioButton
- openoffice
+ GtkOptionMenu
+ style_menu
+ 10
True
-
- True
- True
- format
+ default
+
+ 0
0
- False
- False
+ True
+ True
- GtkRadioButton
- pdf
+ GtkButton
+ button17
+ 10
True
-
- False
- True
- format
+
+ clicked
+ on_style_edit_clicked
+
+ Tue, 05 Jun 2001 14:39:29 GMT
+
+
+ GTK_RELIEF_NORMAL
- 0
+ 5
False
False
@@ -230,6 +260,7 @@
GtkFrame
frame2
+ 5
0
GTK_SHADOW_ETCHED_IN
@@ -330,7 +361,7 @@
GtkOptionMenu
papersize
True
-
+ Letter
0
@@ -353,7 +384,7 @@
GtkOptionMenu
orientation
True
-
+ Portrait
0