* src/plugins/DesGraph.py: Change from TextDoc and DrawDoc to BaseDoc.

* src/plugins/FanChart.py: Likewise. Enable Book item functionality.
* src/plugins/TimeLine.py: Likewise.


svn: r2059
This commit is contained in:
Alex Roitman 2003-08-29 22:47:06 +00:00
parent cf8a5ad12f
commit f7a50210b2
4 changed files with 441 additions and 159 deletions

View File

@ -1,3 +1,8 @@
2003-08-29 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/DesGraph.py: Change from TextDoc and DrawDoc to BaseDoc.
* src/plugins/FanChart.py: Likewise. Enable Book item functionality.
* src/plugins/TimeLine.py: Likewise.
2003-08-28 Alex Roitman <shura@alex.neuro.umn.edu> 2003-08-28 Alex Roitman <shura@alex.neuro.umn.edu>
* src/docgen/LaTeXDoc.py: Do not register as a book format (have to * src/docgen/LaTeXDoc.py: Do not register as a book format (have to
support both text and graphics). support both text and graphics).

View File

@ -41,9 +41,8 @@ import gtk
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import GraphLayout import GraphLayout
import FontScale import FontScale
import DrawDoc
import Report import Report
import TextDoc import BaseDoc
import Errors import Errors
from SubstKeywords import SubstKeywords from SubstKeywords import SubstKeywords
@ -233,14 +232,14 @@ class DescendantReport:
self.maxx = int(self.doc.get_usable_width()/(self.box_width+_sep)) self.maxx = int(self.doc.get_usable_width()/(self.box_width+_sep))
self.maxy = int(self.doc.get_usable_height()/(self.height+_sep)) self.maxy = int(self.doc.get_usable_height()/(self.height+_sep))
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_height(self.height) g.set_height(self.height)
g.set_width(self.box_width) g.set_width(self.box_width)
g.set_paragraph_style("DG-Normal") g.set_paragraph_style("DG-Normal")
g.set_shadow(1) g.set_shadow(1)
self.doc.add_draw_style("box",g) self.doc.add_draw_style("box",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
self.doc.add_draw_style("line",g) self.doc.add_draw_style("line",g)
def print_page(self, plist,elist,r,c): def print_page(self, plist,elist,r,c):
@ -306,10 +305,10 @@ class DescendantReport:
#------------------------------------------------------------------------ #------------------------------------------------------------------------
def _make_default_style(default_style): def _make_default_style(default_style):
"""Make the default output style for the Descendant Graph report.""" """Make the default output style for the Descendant Graph report."""
f = TextDoc.FontStyle() f = BaseDoc.FontStyle()
f.set_size(9) f.set_size(9)
f.set_type_face(TextDoc.FONT_SANS_SERIF) f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle() p = BaseDoc.ParagraphStyle()
p.set_font(f) p.set_font(f)
p.set_description(_('The basic style used for the text display.')) p.set_description(_('The basic style used for the text display.'))
default_style.add_style("DG-Normal",p) default_style.add_style("DG-Normal",p)

View File

@ -31,10 +31,9 @@ import gtk
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import GrampsCfg import GrampsCfg
import DrawDoc import BaseDoc
import Report import Report
import Errors import Errors
import TextDoc
import Calendar import Calendar
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
@ -57,7 +56,7 @@ def pt2cm(pt):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class FanChart: class FanChart:
def __init__(self,database,person,output,doc,display): def __init__(self,database,person,display,doc,output,newpage=0):
self.doc = doc self.doc = doc
self.doc.creator(database.getResearcher().getName()) self.doc.creator(database.getResearcher().getName())
self.map = {} self.map = {}
@ -68,65 +67,71 @@ class FanChart:
self.height = 0 self.height = 0
self.lines = 0 self.lines = 0
self.display = display self.display = display
self.newpage = newpage
if output:
self.standalone = 1
self.doc.open(output)
else:
self.standalone = 0
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_paragraph_style('Title') g.set_paragraph_style('FC-Title')
self.doc.add_draw_style("t",g) self.doc.add_draw_style("t",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,212,210)) g.set_fill_color((255,212,210))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("c1",g) self.doc.add_draw_style("FC-c1",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,212,210)) g.set_fill_color((255,212,210))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
g.set_line_width(0) g.set_line_width(0)
self.doc.add_draw_style("c1n",g) self.doc.add_draw_style("FC-c1n",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((251,204,158)) g.set_fill_color((251,204,158))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("c2",g) self.doc.add_draw_style("FC-c2",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((251,204,158)) g.set_fill_color((251,204,158))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
g.set_line_width(0) g.set_line_width(0)
self.doc.add_draw_style("c2n",g) self.doc.add_draw_style("FC-c2n",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,255,111)) g.set_fill_color((255,255,111))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("c3",g) self.doc.add_draw_style("FC-c3",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,255,111)) g.set_fill_color((255,255,111))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
g.set_line_width(0) g.set_line_width(0)
self.doc.add_draw_style("c3n",g) self.doc.add_draw_style("FC-c3n",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((158,255,158)) g.set_fill_color((158,255,158))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("c4",g) self.doc.add_draw_style("FC-c4",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((158,255,158)) g.set_fill_color((158,255,158))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
g.set_line_width(0) g.set_line_width(0)
self.doc.add_draw_style("c4n",g) self.doc.add_draw_style("FC-c4n",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((156,205,255)) g.set_fill_color((156,205,255))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("c5",g) self.doc.add_draw_style("FC-c5",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_fill_color((156,205,255)) g.set_fill_color((156,205,255))
g.set_paragraph_style('Normal') g.set_paragraph_style('FC-Normal')
g.set_line_width(0) g.set_line_width(0)
self.doc.add_draw_style("c5n",g) self.doc.add_draw_style("FC-c5n",g)
self.map = [None] * 32 self.map = [None] * 32
self.text= {} self.text= {}
@ -148,7 +153,7 @@ class FanChart:
for line in self.display: for line in self.display:
self.text[index-1].append(subst.replace(line)) self.text[index-1].append(subst.replace(line))
self.font = self.doc.style_list["Normal"].get_font() self.font = self.doc.style_list["FC-Normal"].get_font()
for line in self.text[index-1]: for line in self.text[index-1]:
self.box_width = max(self.box_width,string_width(self.font,line)) self.box_width = max(self.box_width,string_width(self.font,line))
@ -164,11 +169,9 @@ class FanChart:
self.filter(self.start,1) self.filter(self.start,1)
block_size = self.doc.get_usable_width()/14.0 block_size = self.doc.get_usable_width()/14.0
try:
self.doc.open(self.output) if self.newpage:
except Errors.ReportError, val: self.doc.page_break()
(m1,m2) = val.messages()
ErrorDialog(m1,m2)
size = min(self.doc.get_usable_width(),self.doc.get_usable_height()*2.0)/2.0 size = min(self.doc.get_usable_width(),self.doc.get_usable_height()*2.0)/2.0
y = self.doc.get_usable_height() y = self.doc.get_usable_height()
@ -187,11 +190,8 @@ class FanChart:
self.circle_1(center,y,block_size) self.circle_1(center,y,block_size)
self.doc.end_page() self.doc.end_page()
try: if self.standalone:
self.doc.close() self.doc.close()
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
def get_info(self,person): def get_info(self,person):
pn = person.getPrimaryName() pn = person.getPrimaryName()
@ -210,17 +210,17 @@ class FanChart:
return [ pn.getFirstName(), pn.getSurname(), val ] return [ pn.getFirstName(), pn.getSurname(), val ]
def circle_1(self,center,y,size): def circle_1(self,center,y,size):
(xc,yc) = self.doc.draw_wedge("c1", center, y, size, 180, 360) (xc,yc) = self.doc.draw_wedge("FC-c1", center, y, size, 180, 360)
self.doc.rotate_text("c1n", self.get_info(self.map[0]), xc, yc ,0) self.doc.rotate_text("FC-c1n", self.get_info(self.map[0]), xc, yc ,0)
def circle_2(self,center,y,size): def circle_2(self,center,y,size):
(xc,yc) = self.doc.draw_wedge("c2", center, y, size*2, 180, 270, size) (xc,yc) = self.doc.draw_wedge("FC-c2", center, y, size*2, 180, 270, size)
if self.map[1]: if self.map[1]:
self.doc.rotate_text("c2n", self.get_info(self.map[1]), xc, yc, -45) self.doc.rotate_text("FC-c2n", self.get_info(self.map[1]), xc, yc, -45)
(xc,yc) = self.doc.draw_wedge("c2", center, y, size*2, 270, 360, size) (xc,yc) = self.doc.draw_wedge("FC-c2", center, y, size*2, 270, 360, size)
if self.map[2]: if self.map[2]:
self.doc.rotate_text("c2n", self.get_info(self.map[2]), xc,yc ,45) self.doc.rotate_text("FC-c2n", self.get_info(self.map[2]), xc,yc ,45)
def circle_3(self,center,y,size): def circle_3(self,center,y,size):
delta = 45 delta = 45
@ -228,9 +228,9 @@ class FanChart:
for index in range(3,7): for index in range(3,7):
start = 180+(index-3)*45 start = 180+(index-3)*45
stop = start+45 stop = start+45
(xc,yc) = self.doc.draw_wedge("c3", center, y, size*3, start, stop, size*2) (xc,yc) = self.doc.draw_wedge("FC-c3", center, y, size*3, start, stop, size*2)
if self.map[index]: if self.map[index]:
self.doc.rotate_text("c3n", self.get_info(self.map[index]), self.doc.rotate_text("FC-c3n", self.get_info(self.map[index]),
xc,yc ,sangle) xc,yc ,sangle)
sangle += 45 sangle += 45
@ -240,12 +240,12 @@ class FanChart:
for i in range(0,8): for i in range(0,8):
start_angle = 180 + (i * delta) start_angle = 180 + (i * delta)
end_angle = 180 + ((i+1) * delta) end_angle = 180 + ((i+1) * delta)
(xc,yc) = self.doc.draw_wedge("c4", center, y, size*5, start_angle, (xc,yc) = self.doc.draw_wedge("FC-c4", center, y, size*5, start_angle,
end_angle, size*3) end_angle, size*3)
if i == 4: if i == 4:
sangle += 180 sangle += 180
if self.map[i+7]: if self.map[i+7]:
self.doc.rotate_text("c4n", self.get_info(self.map[i+7]), self.doc.rotate_text("FC-c4n", self.get_info(self.map[i+7]),
xc,yc ,sangle) xc,yc ,sangle)
sangle += 22.5 sangle += 22.5
@ -255,15 +255,41 @@ class FanChart:
for i in range(0,16): for i in range(0,16):
start_angle = 180 + (i * delta) start_angle = 180 + (i * delta)
end_angle = 180 + ((i+1) * delta) end_angle = 180 + ((i+1) * delta)
(xc,yc) = self.doc.draw_wedge("c5", center, y, size*7, start_angle, (xc,yc) = self.doc.draw_wedge("FC-c5", center, y, size*7, start_angle,
end_angle, size*5) end_angle, size*5)
if i == 8: if i == 8:
sangle += 180 sangle += 180
if self.map[i+15]: if self.map[i+15]:
self.doc.rotate_text("c5n", self.get_info(self.map[i+15]), self.doc.rotate_text("FC-c5n", self.get_info(self.map[i+15]),
xc,yc ,sangle) xc,yc ,sangle)
sangle += 11.25 sangle += 11.25
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
def _make_default_style(default_style):
"""Make the default output style for the Fan Chart report."""
f = BaseDoc.FontStyle()
f.set_size(8)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_description(_('The basic style used for the text display.'))
default_style.add_style("FC-Normal",p)
f = BaseDoc.FontStyle()
f.set_size(20)
f.set_bold(1)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_description(_('The style used for the title.'))
default_style.add_style("FC-Title",p)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# FanChartDialog # FanChartDialog
@ -289,30 +315,14 @@ class FanChartDialog(Report.DrawReportDialog):
def get_stylesheet_savefile(self): def get_stylesheet_savefile(self):
"""Where to save user defined styles for this report.""" """Where to save user defined styles for this report."""
return "fan_chart.xml" return _style_file
def get_report_generations(self): def get_report_generations(self):
"""Default to 10 generations, no page breaks.""" """Default to 10 generations, no page breaks."""
return (0, 0) return (0, 0)
def make_default_style(self): def make_default_style(self):
"""Make the default output style for the Ancestor Chart report.""" _make_default_style(self.default_style)
f = TextDoc.FontStyle()
f.set_size(8)
f.set_type_face(TextDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(TextDoc.PARA_ALIGN_CENTER)
self.default_style.add_style("Normal",p)
f = TextDoc.FontStyle()
f.set_size(20)
f.set_bold(1)
f.set_type_face(TextDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(TextDoc.PARA_ALIGN_CENTER)
self.default_style.add_style("Title",p)
def make_report(self): def make_report(self):
"""Create the object that will produce the Ancestor Chart. """Create the object that will produce the Ancestor Chart.
@ -320,7 +330,8 @@ class FanChartDialog(Report.DrawReportDialog):
opened.""" opened."""
try: try:
MyReport = FanChart(self.db, self.person, self.target_path,self.doc,"%n") MyReport = FanChart(self.db, self.person,
"%n", self.doc, self.target_path)
MyReport.write_report() MyReport.write_report()
except Errors.FilterError, msg: except Errors.FilterError, msg:
(m1,m2) = msg.messages() (m1,m2) = msg.messages()
@ -338,13 +349,109 @@ class FanChartDialog(Report.DrawReportDialog):
def report(database,person): def report(database,person):
FanChartDialog(database,person) FanChartDialog(database,person)
#------------------------------------------------------------------------
#
# Set up sane defaults for the book_item
#
#------------------------------------------------------------------------
_style_file = "fan_chart.xml"
_style_name = "default"
_person_id = ""
_options = ( _person_id, )
#------------------------------------------------------------------------
#
# Book Item Options dialog
#
#------------------------------------------------------------------------
class FanChartBareDialog(Report.BareReportDialog):
def __init__(self,database,person,opt,stl):
self.options = opt
self.db = database
if self.options[0]:
self.person = self.db.getPerson(self.options[0])
else:
self.person = person
self.style_name = stl
Report.BareReportDialog.__init__(self,database,self.person)
self.new_person = None
self.window.run()
#------------------------------------------------------------------------
#
# Customization hooks
#
#------------------------------------------------------------------------
def get_title(self):
"""The window title for this dialog"""
return "%s - GRAMPS Book" % (_("Fan Chart"))
def get_header(self, name):
"""The header line at the top of the dialog contents"""
return _("Fan Chart for GRAMPS Book")
def get_stylesheet_savefile(self):
"""Where to save styles for this report."""
return _style_file
def get_report_generations(self):
"""No generations, no page breaks."""
return (0, 0)
def make_default_style(self):
_make_default_style(self.default_style)
def on_cancel(self, obj):
pass
def on_ok_clicked(self, obj):
"""The user is satisfied with the dialog choices. Parse all options
and close the window."""
# Preparation
self.parse_style_frame()
if self.new_person:
self.person = self.new_person
self.options = ( self.person.getId(), )
self.style_name = self.selected_style.get_name()
#------------------------------------------------------------------------
#
# Function to write Book Item
#
#------------------------------------------------------------------------
def write_book_item(database,person,doc,options,newpage=0):
"""Write the Fan Chart using options set.
All user dialog has already been handled and the output file opened."""
try:
if options[0]:
person = database.getPerson(options[0])
return FanChart(database, person,
"%n", doc, None, newpage )
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Register the report with the plugin system. If this is not done, then # Register the report with the plugin system. If this is not done, then
# GRAMPS will not know that the report exists. # GRAMPS will not know that the report exists.
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from Plugins import register_report from Plugins import register_report, register_book_item
register_report( register_report(
report, report,
@ -354,3 +461,14 @@ register_report(
description=_("Produces a five generation fan chart") description=_("Produces a five generation fan chart")
) )
# (name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style)
register_book_item(
_("Fan Chart"),
_("Graphics"),
FanChartBareDialog,
write_book_item,
_options,
_style_name,
_style_file,
_make_default_style
)

View File

@ -43,8 +43,8 @@ import gtk
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import Utils import Utils
import Report import Report
import TextDoc import BaseDoc
import DrawDoc import BaseDoc
import GenericFilter import GenericFilter
import Errors import Errors
import Date import Date
@ -61,7 +61,7 @@ from gettext import gettext as _
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class TimeLine: class TimeLine:
def __init__(self,database,person,output,document,filter,title,sort_func): def __init__(self,database,person,filter,title,sort_func,document,output,newpage=0):
""" """
Creates the Timeline object that produces the report. This class Creates the Timeline object that produces the report. This class
is used by the TimelineDialog class. The arguments are: is used by the TimelineDialog class. The arguments are:
@ -69,8 +69,8 @@ class TimeLine:
database - the GRAMPS database database - the GRAMPS database
person - currently selected person person - currently selected person
output - name of the output file output - name of the output file
document - DrawDoc instance for the output file. Any class derived document - BaseDoc instance for the output file. Any class derived
from DrawDoc may be used. from BaseDoc may be used.
filter - filtering function selected by the TimeLineDialog filter - filtering function selected by the TimeLineDialog
class. class.
""" """
@ -81,6 +81,12 @@ class TimeLine:
self.output = output self.output = output
self.title = title self.title = title
self.sort_func = sort_func self.sort_func = sort_func
self.newpage = newpage
if output:
self.standalone = 1
self.d.open(output)
else:
self.standalone = 0
def setup(self): def setup(self):
""" """
@ -100,44 +106,44 @@ class TimeLine:
label - Contains the Label paragraph style used for the year label's label - Contains the Label paragraph style used for the year label's
in the document. in the document.
""" """
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_line_width(0.5) g.set_line_width(0.5)
g.set_color((0,0,0)) g.set_color((0,0,0))
self.d.add_draw_style("line",g) self.d.add_draw_style("line",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_line_width(0.5) g.set_line_width(0.5)
g.set_color((0,0,0)) g.set_color((0,0,0))
g.set_fill_color((0,0,0)) g.set_fill_color((0,0,0))
self.d.add_draw_style("solid",g) self.d.add_draw_style("solid",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_line_width(0.5) g.set_line_width(0.5)
g.set_color((0,0,0)) g.set_color((0,0,0))
g.set_fill_color((255,255,255)) g.set_fill_color((255,255,255))
self.d.add_draw_style("open",g) self.d.add_draw_style("open",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_line_width(0.5) g.set_line_width(0.5)
g.set_line_style(DrawDoc.DASHED) g.set_line_style(BaseDoc.DASHED)
g.set_color((0,0,0)) g.set_color((0,0,0))
self.d.add_draw_style("grid",g) self.d.add_draw_style("grid",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_paragraph_style("Name") g.set_paragraph_style("Name")
g.set_color((255,255,255)) g.set_color((255,255,255))
g.set_fill_color((255,255,255)) g.set_fill_color((255,255,255))
g.set_line_width(0) g.set_line_width(0)
self.d.add_draw_style("text",g) self.d.add_draw_style("text",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_paragraph_style("Title") g.set_paragraph_style("Title")
g.set_color((255,255,255)) g.set_color((255,255,255))
g.set_fill_color((255,255,255)) g.set_fill_color((255,255,255))
g.set_line_width(0) g.set_line_width(0)
self.d.add_draw_style("title",g) self.d.add_draw_style("title",g)
g = DrawDoc.GraphicsStyle() g = BaseDoc.GraphicsStyle()
g.set_paragraph_style("Label") g.set_paragraph_style("Label")
g.set_color((255,255,255)) g.set_color((255,255,255))
g.set_fill_color((255,255,255)) g.set_fill_color((255,255,255))
@ -162,7 +168,9 @@ class TimeLine:
size = (stop-start) size = (stop-start)
self.header = 2.0 self.header = 2.0
self.d.open(self.output) #self.d.open(self.output)
if self.newpage:
self.doc.page_break()
self.d.start_page() self.d.start_page()
self.build_grid(low,high,start,stop) self.build_grid(low,high,start,stop)
@ -217,7 +225,9 @@ class TimeLine:
current += 1 current += 1
self.d.end_page() self.d.end_page()
self.d.close() if self.standalone:
self.d.close()
#self.d.close()
def build_grid(self,year_low,year_high,start_pos,stop_pos): def build_grid(self,year_low,year_high,start_pos,stop_pos):
""" """
@ -300,6 +310,65 @@ class TimeLine:
return pt2cm(size) return pt2cm(size)
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
def _make_default_style(default_style):
"""Make the default output style for the Timeline report."""
f = BaseDoc.FontStyle()
f.set_size(10)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the person's name."))
default_style.add_style("Name",p)
f = BaseDoc.FontStyle()
f.set_size(8)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the year labels."))
default_style.add_style("Label",p)
f = BaseDoc.FontStyle()
f.set_size(14)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the title of the page."))
default_style.add_style("Title",p)
#------------------------------------------------------------------------
#
# Builds filter list for this report
#
#------------------------------------------------------------------------
def _get_report_filters(person):
"""Set up the list of possible content filters."""
name = person.getPrimaryName().getName()
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
des = GenericFilter.GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(GenericFilter.IsDescendantOf([person.getId()]))
ans = GenericFilter.GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(GenericFilter.IsAncestorOf([person.getId()]))
com = GenericFilter.GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()]))
return [all,des,ans,com]
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# TimeLineDialog # TimeLineDialog
@ -317,7 +386,7 @@ class TimeLineDialog(Report.DrawReportDialog):
def get_stylesheet_savefile(self): def get_stylesheet_savefile(self):
"""Where to save user defined styles for this report.""" """Where to save user defined styles for this report."""
return "timeline.xml" return _style_file
def get_target_browser_title(self): def get_target_browser_title(self):
"""The title of the window created when the 'browse' button is """The title of the window created when the 'browse' button is
@ -351,53 +420,10 @@ class TimeLineDialog(Report.DrawReportDialog):
self.add_option(_('Title'),self.title_box) self.add_option(_('Title'),self.title_box)
def get_report_filters(self): def get_report_filters(self):
"""Set up the list of possible content filters.""" return _get_report_filters(self.person)
name = self.person.getPrimaryName().getName()
all = GenericFilter.GenericFilter()
all.set_name(_("Entire Database"))
all.add_rule(GenericFilter.Everyone([]))
des = GenericFilter.GenericFilter()
des.set_name(_("Descendants of %s") % name)
des.add_rule(GenericFilter.IsDescendantOf([self.person.getId()]))
ans = GenericFilter.GenericFilter()
ans.set_name(_("Ancestors of %s") % name)
ans.add_rule(GenericFilter.IsAncestorOf([self.person.getId()]))
com = GenericFilter.GenericFilter()
com.set_name(_("People with common ancestor with %s") % name)
com.add_rule(GenericFilter.HasCommonAncestorWith([self.person.getId()]))
return [all,des,ans,com]
def make_default_style(self): def make_default_style(self):
"""Make the default output style for the Timeline report.""" _make_default_style(self.default_style)
f = TextDoc.FontStyle()
f.set_size(10)
f.set_type_face(TextDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the person's name."))
self.default_style.add_style("Name",p)
f = TextDoc.FontStyle()
f.set_size(8)
f.set_type_face(TextDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the year labels."))
self.default_style.add_style("Label",p)
f = TextDoc.FontStyle()
f.set_size(14)
f.set_type_face(TextDoc.FONT_SANS_SERIF)
p = TextDoc.ParagraphStyle()
p.set_font(f)
p.set_description(_("The style used for the title of the page."))
self.default_style.add_style("Title",p)
def make_report(self): def make_report(self):
@ -405,8 +431,8 @@ class TimeLineDialog(Report.DrawReportDialog):
sort_func = self.sort_menu.get_active().get_data('sort') sort_func = self.sort_menu.get_active().get_data('sort')
try: try:
MyReport = TimeLine(self.db, self.person, self.target_path, MyReport = TimeLine(self.db, self.person,
self.doc, self.filter, title, sort_func) self.filter, title, sort_func, self.doc, self.target_path)
MyReport.setup() MyReport.setup()
MyReport.write_report() MyReport.write_report()
except Errors.FilterError, msg: except Errors.FilterError, msg:
@ -429,20 +455,9 @@ def pt2cm(val):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Register the TimeLine report with the plugin system. The register_report # entry point
# task of the Plugins module takes the following arguments.
#
# task - function that starts the task
# name - Name of the report
# status - alpha/beta/production
# category - Category entry in the menu system.
# author_name - Name of the author
# author_email - Author's email address
# description - function that returns the description of the report
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from Plugins import register_report
def report(database,person): def report(database,person):
""" """
report - task starts the report. The plugin system requires that the report - task starts the report. The plugin system requires that the
@ -458,6 +473,140 @@ def get_description():
""" """
return _("Generates a timeline graph.") return _("Generates a timeline graph.")
#------------------------------------------------------------------------
#
# Set up sane defaults for the book_item
#
#------------------------------------------------------------------------
_style_file = "timeline.xml"
_style_name = "default"
_person_id = ""
_filter_num = 0
_sort = ""
_title = ""
_options = ( _person_id, _filter_num, _sort, _title )
#------------------------------------------------------------------------
#
# Book Item Options dialog
#
#------------------------------------------------------------------------
class TimelineGraphBareDialog(Report.BareReportDialog):
def __init__(self,database,person,opt,stl):
self.options = opt
self.db = database
if self.options[0]:
self.person = self.db.getPerson(self.options[0])
else:
self.person = person
self.style_name = stl
Report.BareReportDialog.__init__(self,database,self.person)
self.filter_num = int(self.options[1])
self.sort = self.options[2]
self.title = self.options[3]
self.new_person = None
self.filter_combo.set_history(self.filter_num)
self.sort_style.set_history(self.filter_num)
self.title_box.get_buffer.set_text(self.title)
self.window.run()
#------------------------------------------------------------------------
#
# Customization hooks
#
#------------------------------------------------------------------------
def get_title(self):
"""The window title for this dialog"""
return "%s - GRAMPS Book" % (_("Ancestor Chart"))
def get_header(self, name):
"""The header line at the top of the dialog contents"""
return _("Ancestor Chart for GRAMPS Book")
def get_stylesheet_savefile(self):
"""Where to save styles for this report."""
return _style_file
def get_report_generations(self):
"""No generations, no page breaks."""
return (0, 0)
def get_report_extra_textbox_info(self):
"""Label the textbox and provide the default contents."""
return (_("Display Format"), "$n\n%s $b\n%s $d" % (_BORN,_DIED),
_("Allows you to customize the data in the boxes in the report"))
def make_default_style(self):
_make_default_style(self.default_style)
def get_report_filters(self):
return _get_report_filters(self.person)
def on_cancel(self, obj):
pass
def on_ok_clicked(self, obj):
"""The user is satisfied with the dialog choices. Parse all options
and close the window."""
# Preparation
self.parse_style_frame()
self.parse_report_options_frame()
if self.new_person:
self.person = self.new_person
self.options = ( self.person.getId(), self.max_gen, self.report_text )
self.style_name = self.selected_style.get_name()
#------------------------------------------------------------------------
#
# Function to write Book Item
#
#------------------------------------------------------------------------
def write_book_item(database,person,doc,options,newpage=0):
"""Write the Ancestor Chart using options set.
All user dialog has already been handled and the output file opened."""
try:
if options[0]:
person = database.getPerson(options[0])
max_gen = int(options[1])
disp_format = options[2]
return TimeLine(database, person,
afilter, title, sort_func, doc, None, newpage )
except Errors.ReportError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except Errors.FilterError, msg:
(m1,m2) = msg.messages()
ErrorDialog(m1,m2)
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
#------------------------------------------------------------------------
#
# Register the TimeLine report with the plugin system. The register_report
# task of the Plugins module takes the following arguments.
#
# task - function that starts the task
# name - Name of the report
# status - alpha/beta/production
# category - Category entry in the menu system.
# author_name - Name of the author
# author_email - Author's email address
# description - function that returns the description of the report
#
#------------------------------------------------------------------------
from Plugins import register_report, register_book_item
register_report( register_report(
task=report, task=report,
name=_("Timeline Graph"), name=_("Timeline Graph"),
@ -468,3 +617,14 @@ register_report(
description=get_description() description=get_description()
) )
# (name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style)
register_book_item(
_("Timeline Graph"),
_("Graphics"),
TimelineGraphBareDialog,
write_book_item,
_options,
_style_name,
_style_file,
_make_default_style
)