* src/Report.py: Add support for a semi-common 'dispf'.
* src/ReportOptions.py: Add support for a semi-common 'dispf'. * src/Utils.py (cm2pt): Add function. * src/plugins/AncestorChart.py: Convert to new scheme. * src/plugins/AncestorChart2.py: Convert to new scheme. * src/plugins/DesGraph.py: Convert to new scheme. svn: r3858
This commit is contained in:
@ -27,8 +27,7 @@
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import os
|
||||
import string
|
||||
from gettext import gettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -44,51 +43,58 @@ import gtk
|
||||
#------------------------------------------------------------------------
|
||||
import BaseDoc
|
||||
import Report
|
||||
import Errors
|
||||
from QuestionDialog import ErrorDialog
|
||||
from SubstKeywords import SubstKeywords
|
||||
from gettext import gettext as _
|
||||
from Utils import pt2cm
|
||||
import const
|
||||
import ReportOptions
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
_BORN = _('b.')
|
||||
_DIED = _('d.')
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# pt2cm - convert points to centimeters
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
def pt2cm(pt):
|
||||
return (float(pt)/72.0)*(254.0/100.0)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# AncestorChart
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class AncestorChart:
|
||||
class AncestorChart(Report.Report):
|
||||
|
||||
def __init__(self,database,person,options_class):
|
||||
"""
|
||||
Creates AncestorChart object that produces the report.
|
||||
|
||||
The arguments are:
|
||||
|
||||
database - the GRAMPS database instance
|
||||
person - currently selected person
|
||||
options_class - instance of the Options class for this report
|
||||
|
||||
This report needs the following parameters (class variables)
|
||||
that come in the options class.
|
||||
|
||||
gen - Maximum number of generations to include.
|
||||
pagebbg - Whether to include page breaks between generations.
|
||||
dispf - Display format for the output box.
|
||||
"""
|
||||
Report.Report.__init__(self,database,person,options_class)
|
||||
|
||||
(self.max_generations,self.pgbrk) \
|
||||
= options_class.get_report_generations()
|
||||
self.display = options_class.handler.options_dict['dispf']
|
||||
|
||||
def __init__(self,database,person,max,display,doc,output,newpage=0):
|
||||
self.database = database
|
||||
self.doc = doc
|
||||
self.doc.creator(database.get_researcher().get_name())
|
||||
self.map = {}
|
||||
self.text = {}
|
||||
self.start = person
|
||||
self.max_generations = max
|
||||
self.output = output
|
||||
|
||||
self.box_width = 0
|
||||
self.height = 0
|
||||
self.lines = 0
|
||||
self.display = display
|
||||
self.newpage = newpage
|
||||
if output:
|
||||
self.standalone = 1
|
||||
self.doc.open(output)
|
||||
else:
|
||||
self.standalone = 0
|
||||
self.calc()
|
||||
|
||||
def filter(self,person_handle,index):
|
||||
def apply_filter(self,person_handle,index):
|
||||
"""traverse the ancestors recursively until either the end
|
||||
of a line is found, or until we reach the maximum number of
|
||||
generations that we want to deal with"""
|
||||
@ -115,14 +121,11 @@ class AncestorChart:
|
||||
family_handle = person.get_main_parents_family_handle()
|
||||
if family_handle:
|
||||
family = self.database.get_family_from_handle(family_handle)
|
||||
self.filter(family.get_father_handle(),index*2)
|
||||
self.filter(family.get_mother_handle(),(index*2)+1)
|
||||
self.apply_filter(family.get_father_handle(),index*2)
|
||||
self.apply_filter(family.get_mother_handle(),(index*2)+1)
|
||||
|
||||
def write_report(self):
|
||||
|
||||
if self.newpage:
|
||||
self.doc.page_break()
|
||||
|
||||
generation = 1
|
||||
done = 0
|
||||
page = 1
|
||||
@ -137,8 +140,6 @@ class AncestorChart:
|
||||
self.print_page(index, generation, page)
|
||||
page = page + 1
|
||||
generation = generation + 3
|
||||
if self.standalone:
|
||||
self.doc.close()
|
||||
|
||||
def calc(self):
|
||||
"""
|
||||
@ -146,7 +147,7 @@ class AncestorChart:
|
||||
that and the page dimensions, calculate the proper place to put
|
||||
the elements on a page.
|
||||
"""
|
||||
self.filter(self.start.get_handle(),1)
|
||||
self.apply_filter(self.start_person.get_handle(),1)
|
||||
|
||||
self.height = self.lines*pt2cm((125.0*self.font.get_size())/100.0)
|
||||
self.box_width = pt2cm(self.box_width+20)
|
||||
@ -196,7 +197,7 @@ class AncestorChart:
|
||||
if self.map.has_key(start) and index <= 15:
|
||||
text = self.text[start]
|
||||
|
||||
name = string.join(text,"\n")
|
||||
name = "\n".join(text)
|
||||
self.doc.draw_box("AC-box",name,self.x[level],self.y[index-1])
|
||||
|
||||
if index > 1:
|
||||
@ -219,222 +220,60 @@ class AncestorChart:
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
def _make_default_style(default_style):
|
||||
"""Make the default output style for the Ancestor Chart report."""
|
||||
f = BaseDoc.FontStyle()
|
||||
f.set_size(9)
|
||||
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
|
||||
p = BaseDoc.ParagraphStyle()
|
||||
p.set_font(f)
|
||||
p.set_description(_('The basic style used for the text display.'))
|
||||
default_style.add_style("AC-Normal",p)
|
||||
class AncestorChartOptions(ReportOptions.ReportOptions):
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# AncestorChartDialog
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class AncestorChartDialog(Report.DrawReportDialog):
|
||||
"""
|
||||
Defines options and provides handling interface.
|
||||
"""
|
||||
|
||||
report_options = {}
|
||||
|
||||
def __init__(self,database,person):
|
||||
Report.DrawReportDialog.__init__(self,database,person,self.report_options)
|
||||
def __init__(self,name,person_id=None):
|
||||
ReportOptions.ReportOptions.__init__(self,name,person_id)
|
||||
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return "%s - %s - GRAMPS" % (_("Ancestor Chart"),_("Graphical Reports"))
|
||||
def enable_options(self):
|
||||
# Semi-common options that should be enabled for this report
|
||||
self.enable_dict = {
|
||||
'gen' : 10,
|
||||
'pagebbg' : 0,
|
||||
'dispf' : [ "$n", "%s $b" % _BORN, "%s $d" % _DIED ],
|
||||
}
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents."""
|
||||
return _("Ancestor Chart for %s") % name
|
||||
def make_default_style(self,default_style):
|
||||
"""Make the default output style for the Ancestor Chart report."""
|
||||
f = BaseDoc.FontStyle()
|
||||
f.set_size(9)
|
||||
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
|
||||
p = BaseDoc.ParagraphStyle()
|
||||
p.set_font(f)
|
||||
p.set_description(_('The basic style used for the text display.'))
|
||||
default_style.add_style("AC-Normal",p)
|
||||
|
||||
def get_target_browser_title(self):
|
||||
"""The title of the window created when the 'browse' button is
|
||||
clicked in the 'Save As' frame."""
|
||||
return _("Save Ancestor Chart")
|
||||
|
||||
def get_stylesheet_savefile(self):
|
||||
"""Where to save user defined styles for this report."""
|
||||
return _style_file
|
||||
|
||||
def get_report_generations(self):
|
||||
"""Default to 10 generations, no page breaks."""
|
||||
return (10, 0)
|
||||
|
||||
def get_report_extra_textbox_info(self):
|
||||
def get_textbox_info(self):
|
||||
"""Label the textbox and provide the default contents."""
|
||||
return (_("Display Format"), "$n\n%s $b\n%s $d" % (_BORN,_DIED),
|
||||
return (_("Display Format"), self.options_dict['dispf'],
|
||||
_("Allows you to customize the data in the boxes in the report"))
|
||||
|
||||
def make_default_style(self):
|
||||
_make_default_style(self.default_style)
|
||||
|
||||
def make_report(self):
|
||||
"""Create the object that will produce the Ancestor Chart.
|
||||
All user dialog has already been handled and the output file
|
||||
opened."""
|
||||
|
||||
try:
|
||||
MyReport = AncestorChart(self.db, self.person,
|
||||
self.max_gen, self.report_text, self.doc,self.target_path)
|
||||
MyReport.write_report()
|
||||
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()
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# entry point
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
def report(database,person):
|
||||
AncestorChartDialog(database,person)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Set up sane defaults for the book_item
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
_style_file = "ancestor_chart.xml"
|
||||
_style_name = "default"
|
||||
|
||||
_person_handle = ""
|
||||
_max_gen = 10
|
||||
_disp_format = [ "$n", "%s $b" % _BORN, "%s $d" % _DIED ]
|
||||
_options = ( _person_handle, _max_gen, _disp_format )
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Book Item Options dialog
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class AncestorChartBareDialog(Report.BareReportDialog):
|
||||
|
||||
def __init__(self,database,person,opt,stl):
|
||||
|
||||
self.options = opt
|
||||
self.db = database
|
||||
if self.options[0]:
|
||||
self.person = self.db.get_person_from_handle(self.options[0])
|
||||
else:
|
||||
self.person = person
|
||||
self.style_name = stl
|
||||
|
||||
Report.BareReportDialog.__init__(self,database,self.person)
|
||||
|
||||
self.max_gen = int(self.options[1])
|
||||
self.disp_format = string.join(self.options[2],'\n')
|
||||
self.new_person = None
|
||||
|
||||
self.generations_spinbox.set_value(self.max_gen)
|
||||
self.extra_textbox.get_buffer().set_text(
|
||||
self.disp_format,len(self.disp_format))
|
||||
|
||||
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):
|
||||
"""Default to 10 generations, no page breaks."""
|
||||
return (10, 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 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.get_handle(), 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.get_person_from_handle(options[0])
|
||||
max_gen = int(options[1])
|
||||
disp_format = options[2]
|
||||
return AncestorChart(database, person, max_gen,
|
||||
disp_format, 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()
|
||||
def add_user_options(self,dialog):
|
||||
"""
|
||||
Override the base class add_user_options task to add a menu that allows
|
||||
the user to select the sort method.
|
||||
"""
|
||||
dialog.get_report_extra_textbox_info = self.get_textbox_info
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from Plugins import register_report, register_book_item
|
||||
|
||||
from Plugins import register_report
|
||||
register_report(
|
||||
report,
|
||||
_("Ancestor Chart"),
|
||||
category=_("Graphical Reports"),
|
||||
status=(_("Beta")),
|
||||
description=_("Produces a graphical ancestral tree graph"),
|
||||
author_name="Donald N. Allingham",
|
||||
author_email="dallingham@users.sourceforge.net"
|
||||
name = 'ancestor_chart',
|
||||
category = const.CATEGORY_DRAW,
|
||||
report_class = AncestorChart,
|
||||
options_class = AncestorChartOptions,
|
||||
modes = Report.MODE_GUI | Report.MODE_BKI | Report.MODE_CLI,
|
||||
translated_name = _("Ancestor Chart"),
|
||||
status = _("Beta"),
|
||||
author_name = "Donald N. Allingham",
|
||||
author_email = "dallingham@users.sourceforge.net",
|
||||
description = _("Produces a graphical ancestral tree graph"),
|
||||
)
|
||||
|
||||
# (name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style)
|
||||
register_book_item(
|
||||
_("Ancestor Chart"),
|
||||
_("Graphics"),
|
||||
AncestorChartBareDialog,
|
||||
write_book_item,
|
||||
_options,
|
||||
_style_name,
|
||||
_style_file,
|
||||
_make_default_style
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user