2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-10 02:19:29 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2005-01-05 11:26:33 +05:30
|
|
|
# Contributions by Lorenzo Cappelletti <lorenzo.cappelletti@email.it>
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2004-03-17 07:20:50 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Generate files/Relationship graph"
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2005-01-05 11:26:33 +05:30
|
|
|
from time import asctime
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".GraphViz")
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/gtk
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Report, ReportOptions, register_report
|
2003-01-15 10:55:50 +05:30
|
|
|
import GenericFilter
|
2005-07-09 01:54:54 +05:30
|
|
|
import RelLib
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2006-03-31 06:53:48 +05:30
|
|
|
import const
|
2005-01-06 10:17:57 +05:30
|
|
|
from BaseDoc import PAPER_LANDSCAPE
|
2005-01-05 11:26:33 +05:30
|
|
|
from QuestionDialog import ErrorDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-15 10:55:50 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-19 02:30:58 +05:30
|
|
|
# Constant options items
|
2003-01-15 10:55:50 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-19 02:30:58 +05:30
|
|
|
|
|
|
|
class _options:
|
|
|
|
# internal ID, english option name (for cli), localized option name (for gui)
|
|
|
|
formats = (
|
2006-04-13 08:31:12 +05:30
|
|
|
("ps", "Postscript", _("Postscript"), "application/postscript"),
|
|
|
|
("svg", "Structured Vector Graphics (SVG)", _("Structured Vector Graphics (SVG)"), "image/svg"),
|
|
|
|
("svgz", "Compressed Structured Vector Graphics (SVG)", _("Compressed Structured Vector Graphs (SVG)"), "image/svgz"),
|
|
|
|
("png", "PNG image", _("PNG image"), "image/png"),
|
|
|
|
("jpg", "JPEG image", _("JPEG image"), "image/jpeg"),
|
|
|
|
("gif", "GIF image", _("GIF image"), "image/gif"),
|
2005-01-19 02:30:58 +05:30
|
|
|
)
|
|
|
|
fonts = (
|
|
|
|
# Last items tells whether strings need to be converted to Latin1
|
|
|
|
("", "Default", _("Default"), 1),
|
|
|
|
("Helvetica", "Postscript / Helvetica", _("Postscript / Helvetica"), 1),
|
|
|
|
("FreeSans", "Truetype / FreeSans", _("Truetype / FreeSans"), 0),
|
|
|
|
)
|
|
|
|
colors = (
|
|
|
|
("outline", "B&W Outline", _("B&W outline")),
|
|
|
|
("colored", "Colored outline", _("Colored outline")),
|
|
|
|
("filled", "Color fill", _("Color fill")),
|
|
|
|
)
|
|
|
|
rankdir = (
|
|
|
|
("LR", "Horizontal", _("Horizontal")),
|
|
|
|
("RL", "Vertical", _("Vertical")),
|
|
|
|
)
|
|
|
|
arrowstyles = (
|
|
|
|
('d', "Descendants <- Ancestors", _("Descendants <- Ancestors")),
|
|
|
|
('a', "Descendants -> Ancestors", _("Descendants -> Ancestors")),
|
|
|
|
('da',"Descendants <-> Ancestors", _("Descendants <-> Ancestors")),
|
|
|
|
('', "Descendants - Ancestors", _("Descendants - Ancestors")),
|
|
|
|
)
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
dot_found = os.system("dot -V 2>/dev/null") == 0
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-05 11:26:33 +05:30
|
|
|
# Report class
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-05 11:26:33 +05:30
|
|
|
class GraphViz:
|
2003-01-15 10:55:50 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def __init__(self,database,person,options_class):
|
|
|
|
"""
|
|
|
|
Creates ComprehensiveAncestorsReport object that produces the report.
|
|
|
|
|
|
|
|
The arguments are:
|
2003-10-31 06:50:58 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
database - the GRAMPS database instance
|
|
|
|
person - currently selected person
|
|
|
|
options_class - instance of the Options class for this report
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
This report needs the following parameters (class variables)
|
|
|
|
that come in the options class.
|
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
filter - Filter to be applied to the people of the database.
|
|
|
|
The option class carries its number, and the function
|
|
|
|
returning the list of filters.
|
|
|
|
font - Font to use.
|
|
|
|
latin - Set if font supports only Latin1
|
|
|
|
arrow - Arrow styles for heads and tails.
|
|
|
|
showfamily - Whether to show family nodes.
|
|
|
|
incid - Whether to include IDs.
|
|
|
|
incdate - Whether to include dates.
|
|
|
|
justyears - Use years only.
|
|
|
|
placecause - Whether to replace missing dates with place or cause
|
|
|
|
url - Whether to include URLs.
|
|
|
|
rankdir - Graph direction
|
|
|
|
color - Whether to use outline, colored outline or filled color in graph
|
|
|
|
dashedl - Whether to use dashed lines for non-birth relationships.
|
2005-08-18 11:28:28 +05:30
|
|
|
margin - Margins, in cm.
|
2005-01-19 02:30:58 +05:30
|
|
|
pagesh - Number of pages in horizontal direction.
|
|
|
|
pagesv - Number of pages in vertical direction.
|
2005-01-05 11:26:33 +05:30
|
|
|
"""
|
2005-01-19 02:30:58 +05:30
|
|
|
colored = {
|
|
|
|
'male': 'dodgerblue4',
|
|
|
|
'female': 'deeppink',
|
|
|
|
'unknown': 'black',
|
|
|
|
'family': 'darkgreen'
|
|
|
|
}
|
|
|
|
filled = {
|
|
|
|
'male': 'lightblue',
|
|
|
|
'female': 'lightpink',
|
|
|
|
'unknown': 'lightgray',
|
|
|
|
'family': 'lightyellow'
|
|
|
|
}
|
2005-01-05 11:26:33 +05:30
|
|
|
self.database = database
|
|
|
|
self.start_person = person
|
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
self.paper = options_class.handler.get_paper()
|
|
|
|
self.orient = options_class.handler.get_orientation()
|
2005-01-05 11:26:33 +05:30
|
|
|
self.width = self.paper.get_width_inches()
|
|
|
|
self.height = self.paper.get_height_inches()
|
2005-01-19 02:30:58 +05:30
|
|
|
|
|
|
|
options = options_class.handler.options_dict
|
|
|
|
self.hpages = options['pagesh']
|
|
|
|
self.vpages = options['pagesv']
|
2005-08-18 11:28:28 +05:30
|
|
|
margin_cm = options['margin']
|
|
|
|
self.margin = round(margin_cm/2.54,2)
|
|
|
|
if margin_cm > 0.1:
|
|
|
|
self.margin_small = round((margin_cm-0.1)/2.54,2)
|
|
|
|
else:
|
|
|
|
self.margin_small = 0
|
2005-01-19 02:30:58 +05:30
|
|
|
self.includeid = options['incid']
|
|
|
|
self.includedates = options['incdate']
|
|
|
|
self.includeurl = options['url']
|
|
|
|
self.adoptionsdashed = options['dashedl']
|
|
|
|
self.show_families = options['showfamily']
|
|
|
|
self.just_years = options['justyears']
|
|
|
|
self.placecause = options['placecause']
|
|
|
|
self.rankdir = options['rankdir']
|
|
|
|
self.fontname = options['font']
|
|
|
|
self.latin = options['latin']
|
|
|
|
self.colorize = options['color']
|
|
|
|
if self.colorize == 'colored':
|
|
|
|
self.colors = colored
|
|
|
|
elif self.colorize == 'filled':
|
|
|
|
self.colors = filled
|
|
|
|
arrow_str = options['arrow']
|
2005-01-05 11:26:33 +05:30
|
|
|
if arrow_str.find('a') + 1:
|
2005-01-18 02:20:41 +05:30
|
|
|
self.arrowheadstyle = 'normal'
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
2005-01-18 02:20:41 +05:30
|
|
|
self.arrowheadstyle = 'none'
|
2005-01-05 11:26:33 +05:30
|
|
|
if arrow_str.find('d') + 1:
|
2005-01-18 02:20:41 +05:30
|
|
|
self.arrowtailstyle = 'normal'
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
2005-01-18 02:20:41 +05:30
|
|
|
self.arrowtailstyle = 'none'
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
filter_num = options_class.get_filter_number()
|
|
|
|
filters = options_class.get_report_filters(person)
|
|
|
|
filters.extend(GenericFilter.CustomFilters.get_filters())
|
|
|
|
self.filter = filters[filter_num]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f = open(options_class.get_output(),'w')
|
|
|
|
self.write_report()
|
|
|
|
self.f.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def write_report(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
self.ind_list = self.filter.apply(self.database,
|
|
|
|
self.database.get_person_handles(sort_handles=False))
|
|
|
|
|
|
|
|
self.write_header()
|
|
|
|
self.f.write("digraph GRAMPS_relationship_graph {\n")
|
|
|
|
self.f.write("bgcolor=white;\n")
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write("rankdir=%s;\n" % self.rankdir)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write("center=1;\n")
|
2005-08-18 11:28:28 +05:30
|
|
|
self.f.write("margin=%3.2f;\n" % self.margin_small)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write("ratio=fill;\n")
|
2005-08-18 11:28:28 +05:30
|
|
|
if self.orient == PAPER_LANDSCAPE:
|
|
|
|
self.f.write("size=\"%3.2f,%3.2f\";\n" % (
|
|
|
|
(self.height-self.margin*2)*self.hpages,
|
|
|
|
(self.width-self.margin*2)*self.vpages
|
|
|
|
))
|
|
|
|
else:
|
|
|
|
self.f.write("size=\"%3.2f,%3.2f\";\n" % (
|
|
|
|
(self.width-self.margin*2)*self.hpages,
|
|
|
|
(self.height-self.margin*2)*self.vpages
|
|
|
|
))
|
|
|
|
self.f.write("page=\"%3.2f,%3.2f\";\n" % (self.width,self.height))
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
if self.orient == PAPER_LANDSCAPE:
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write("rotate=90;\n")
|
|
|
|
|
|
|
|
if len(self.ind_list) > 1:
|
|
|
|
self.dump_index()
|
|
|
|
self.dump_person()
|
|
|
|
|
|
|
|
self.f.write("}\n")
|
|
|
|
|
|
|
|
def dump_person(self):
|
|
|
|
# Hash people in a dictionary for faster inclusion checking.
|
|
|
|
person_dict = {}
|
2005-01-18 02:20:41 +05:30
|
|
|
for p_id in self.ind_list:
|
2005-01-05 11:26:33 +05:30
|
|
|
person_dict[p_id] = 1
|
|
|
|
|
|
|
|
for person_handle in self.ind_list:
|
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
|
|
|
pid = person.get_gramps_id().replace('-','_')
|
|
|
|
for family_handle, mrel, frel in person.get_parent_family_handle_list():
|
|
|
|
family = self.database.get_family_from_handle(family_handle)
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
2006-04-14 10:06:25 +05:30
|
|
|
fadopted = frel != RelLib.ChildRefType.BIRTH
|
|
|
|
madopted = mrel != RelLib.ChildRefType.BIRTH
|
2005-01-05 11:26:33 +05:30
|
|
|
famid = family.get_gramps_id().replace('-','_')
|
|
|
|
if (self.show_families and
|
|
|
|
(father_handle and person_dict.has_key(father_handle) or
|
|
|
|
mother_handle and person_dict.has_key(mother_handle))):
|
|
|
|
# Link to the family node.
|
|
|
|
self.f.write('p%s -> f%s [' % (pid, famid))
|
|
|
|
self.f.write('arrowhead=%s, arrowtail=%s, ' %
|
|
|
|
(self.arrowheadstyle, self.arrowtailstyle))
|
|
|
|
if self.adoptionsdashed and (fadopted or madopted):
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('style=dotted')
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
self.f.write('style=solid')
|
|
|
|
self.f.write('];\n')
|
|
|
|
else:
|
|
|
|
# Link to the parents' nodes directly.
|
|
|
|
if father_handle and person_dict.has_key(father_handle):
|
|
|
|
father = self.database.get_person_from_handle(father_handle)
|
|
|
|
fid = father.get_gramps_id().replace('-','_')
|
|
|
|
self.f.write('p%s -> p%s [' % (pid, fid))
|
|
|
|
self.f.write('arrowhead=%s, arrowtail=%s, ' %
|
|
|
|
(self.arrowheadstyle, self.arrowtailstyle))
|
|
|
|
if self.adoptionsdashed and fadopted:
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('style=dotted')
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
self.f.write('style=solid')
|
|
|
|
self.f.write('];\n')
|
|
|
|
if mother_handle and person_dict.has_key(mother_handle):
|
|
|
|
mother = self.database.get_person_from_handle(mother_handle)
|
|
|
|
mid = mother.get_gramps_id().replace('-','_')
|
|
|
|
self.f.write('p%s -> p%s [' % (pid, mid))
|
|
|
|
self.f.write('arrowhead=%s, arrowtail=%s, ' %
|
|
|
|
(self.arrowheadstyle, self.arrowtailstyle))
|
|
|
|
if self.adoptionsdashed and madopted:
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('style=dotted')
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
self.f.write('style=solid')
|
|
|
|
self.f.write('];\n')
|
|
|
|
|
|
|
|
def dump_index(self):
|
|
|
|
# The list of families for which we have output the node, so we
|
|
|
|
# don't do it twice.
|
|
|
|
families_done = []
|
|
|
|
for person_handle in self.ind_list:
|
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
|
|
|
# Output the person's node.
|
|
|
|
label = person.get_primary_name().get_name()
|
|
|
|
the_id = person.get_gramps_id().replace('-','_')
|
|
|
|
if self.includeid:
|
|
|
|
label = label + " (%s)" % the_id
|
|
|
|
if self.includedates:
|
2006-03-30 10:45:54 +05:30
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.database.get_event_from_handle(birth_ref.ref)
|
2005-01-15 11:21:48 +05:30
|
|
|
birth = self.dump_event(birth_event)
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
birth = ''
|
2006-03-30 10:45:54 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
death_event = self.database.get_event_from_handle(death_ref.ref)
|
2005-01-15 11:21:48 +05:30
|
|
|
death = self.dump_event(death_event)
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
death = ''
|
|
|
|
label = label + '\\n(%s - %s)' % (birth, death)
|
|
|
|
self.f.write('p%s [shape=box, ' % the_id)
|
|
|
|
if self.includeurl:
|
2006-03-01 01:24:35 +05:30
|
|
|
h = person.get_handle()
|
|
|
|
self.f.write('URL="ppl/%s/%s/%s.html", ' % (h[0],h[1],h))
|
2005-01-19 02:30:58 +05:30
|
|
|
if self.colorize != 'outline':
|
|
|
|
if self.colorize == 'filled':
|
|
|
|
style = 'style=filled, fillcolor'
|
|
|
|
else:
|
|
|
|
style = 'color'
|
2005-01-05 11:26:33 +05:30
|
|
|
gender = person.get_gender()
|
2005-02-01 09:16:29 +05:30
|
|
|
if gender == person.MALE:
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('%s=%s, ' % (style, self.colors['male']))
|
2005-02-03 06:02:20 +05:30
|
|
|
elif gender == person.FEMALE:
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('%s=%s, ' % (style, self.colors['female']))
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('%s=%s, ' % (style, self.colors['unknown']))
|
|
|
|
if self.latin:
|
2005-12-06 12:08:09 +05:30
|
|
|
label = label.encode('iso-8859-1')
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write('fontname="%s", label="%s"];\n' % (self.fontname,label))
|
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
# Output families's nodes.
|
|
|
|
if self.show_families:
|
|
|
|
family_list = person.get_family_handle_list()
|
|
|
|
for fam_handle in family_list:
|
|
|
|
fam = self.database.get_family_from_handle(fam_handle)
|
|
|
|
fid = fam.get_gramps_id().replace('-','_')
|
|
|
|
if fam_handle not in families_done:
|
|
|
|
families_done.append(fam_handle)
|
|
|
|
self.f.write('f%s [shape=ellipse, ' % fid)
|
2005-01-19 02:30:58 +05:30
|
|
|
if self.colorize == 'colored':
|
|
|
|
self.f.write('color=%s, ' % self.colors['family'])
|
|
|
|
elif self.colorize == 'filled':
|
|
|
|
self.f.write('style=filled fillcolor=%s, ' % self.colors['family'])
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
marriage = ""
|
2006-03-30 10:45:54 +05:30
|
|
|
for event_ref in fam.get_event_ref_list():
|
|
|
|
if event_ref:
|
|
|
|
event = self.database.get_event_from_handle(event_ref.ref)
|
2006-04-20 04:29:33 +05:30
|
|
|
if int(event.get_type()) == RelLib.EventType.MARRIAGE:
|
2005-01-05 11:26:33 +05:30
|
|
|
m = event
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
m = None
|
|
|
|
|
|
|
|
if m:
|
2005-01-15 11:21:48 +05:30
|
|
|
marriage = self.dump_event(m)
|
2005-01-05 11:26:33 +05:30
|
|
|
if self.includeid:
|
|
|
|
marriage = marriage + " (%s)" % fid
|
|
|
|
self.f.write('fontname="%s", label="%s"];\n'
|
|
|
|
% (self.fontname,marriage))
|
|
|
|
# Link this person to all his/her families.
|
|
|
|
self.f.write('f%s -> p%s [' % (fid, the_id))
|
|
|
|
self.f.write('arrowhead=%s, arrowtail=%s, ' %
|
|
|
|
(self.arrowheadstyle, self.arrowtailstyle))
|
|
|
|
self.f.write('style=solid];\n')
|
|
|
|
|
2005-01-15 11:21:48 +05:30
|
|
|
def dump_event(self,event):
|
|
|
|
"""
|
|
|
|
Compile an event label.
|
|
|
|
|
|
|
|
Based on the data availability and preferences, we select one
|
|
|
|
of the following for a given event:
|
|
|
|
year only
|
|
|
|
complete date
|
|
|
|
place name
|
|
|
|
cause
|
|
|
|
empty string
|
|
|
|
"""
|
|
|
|
if event.get_date_object().get_year_valid():
|
2005-01-19 02:30:58 +05:30
|
|
|
if self.just_years:
|
2005-01-15 11:21:48 +05:30
|
|
|
return '%i' % event.get_date_object().get_year()
|
|
|
|
else:
|
2005-08-06 08:27:37 +05:30
|
|
|
return DateHandler.get_date(event)
|
2005-01-15 11:21:48 +05:30
|
|
|
elif self.placecause:
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
place = self.database.get_place_from_handle(place_handle)
|
|
|
|
if place and place.get_title():
|
|
|
|
return place.get_title()
|
|
|
|
else:
|
|
|
|
return event.get_cause()
|
|
|
|
return ''
|
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def write_header(self):
|
|
|
|
"""
|
|
|
|
Write header listing the options used.
|
|
|
|
"""
|
|
|
|
self.f.write("/* GRAMPS - Relationship graph\n")
|
|
|
|
self.f.write(" *\n")
|
|
|
|
self.f.write(" * Report options:\n")
|
|
|
|
self.f.write(" * font style : %s\n" % self.fontname)
|
|
|
|
self.f.write(" * style arrow head : %s\n" % self.arrowheadstyle)
|
|
|
|
self.f.write(" * tail : %s\n" % self.arrowtailstyle)
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write(" * graph direction : %s\n" % self.rankdir)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write(" * include URLs : %s\n" % bool(self.includeurl))
|
|
|
|
self.f.write(" * IDs : %s\n" % bool(self.includeid))
|
|
|
|
self.f.write(" * dates : %s\n" % bool(self.includedates))
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write(" * just year : %s\n" % bool(self.just_years))
|
2005-01-15 11:21:48 +05:30
|
|
|
self.f.write(" * place or cause : %s\n" % bool(self.placecause))
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write(" * colorize : %s\n" % bool(self.colorize))
|
2005-01-19 02:30:58 +05:30
|
|
|
self.f.write(" * dotted adoptions : %s\n" % bool(self.adoptionsdashed))
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write(" * show family nodes : %s\n" % bool(self.show_families))
|
2005-08-18 11:28:28 +05:30
|
|
|
self.f.write(" * margin : %3.2fin\n" % self.margin_small)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write(" * pages horizontal : %s\n" % self.hpages)
|
|
|
|
self.f.write(" * vertical : %s\n" % self.vpages)
|
2005-08-18 11:28:28 +05:30
|
|
|
self.f.write(" * page width : %3.2fin\n" % self.width)
|
|
|
|
self.f.write(" * height : %3.2fin\n" % self.height)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.write(" *\n")
|
|
|
|
self.f.write(" * Generated on %s by GRAMPS\n" % asctime())
|
|
|
|
self.f.write(" */\n\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Options class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GraphVizOptions(ReportOptions.ReportOptions):
|
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
|
|
|
ReportOptions.ReportOptions.__init__(self,name,person_id)
|
|
|
|
|
|
|
|
def set_new_options(self):
|
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
2005-01-19 02:30:58 +05:30
|
|
|
'font' : "",
|
|
|
|
'latin' : 1,
|
|
|
|
'arrow' : 'd',
|
|
|
|
'showfamily' : 1,
|
|
|
|
'incdate' : 1,
|
|
|
|
'incid' : 0,
|
|
|
|
'justyears' : 0,
|
|
|
|
'placecause' : 1,
|
|
|
|
'url' : 1,
|
|
|
|
'rankdir' : "LR",
|
|
|
|
'color' : "filled",
|
|
|
|
'dashedl' : 1,
|
2005-08-18 11:28:28 +05:30
|
|
|
'margin' : 1.0,
|
2005-01-19 02:30:58 +05:30
|
|
|
'pagesh' : 1,
|
|
|
|
'pagesv' : 1,
|
|
|
|
'gvof' : 'ps',
|
2005-01-05 11:26:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
self.options_help = {
|
|
|
|
'font' : ("=str","Font to use in the report.",
|
2005-01-22 03:16:11 +05:30
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.fonts ],
|
2005-01-05 11:26:33 +05:30
|
|
|
False),
|
2005-01-19 02:30:58 +05:30
|
|
|
'latin' : ("=0/1","Needs to be set if font doesn't support unicode.",
|
|
|
|
["Supports unicode","Supports only Latin1"],
|
|
|
|
True),
|
2005-01-05 11:26:33 +05:30
|
|
|
'arrow' : ("=str","Arrow styles for heads and tails.",
|
2005-01-22 03:16:11 +05:30
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.arrowstyles ],
|
2005-01-05 11:26:33 +05:30
|
|
|
False),
|
2005-01-19 02:30:58 +05:30
|
|
|
'showfamily': ("=0/1","Whether to show family nodes.",
|
2005-01-05 11:26:33 +05:30
|
|
|
["Do not show family nodes","Show family nodes"],
|
|
|
|
True),
|
2005-01-19 02:30:58 +05:30
|
|
|
'incdate' : ("=0/1","Whether to include dates.",
|
2005-01-05 11:26:33 +05:30
|
|
|
["Do not include dates","Include dates"],
|
|
|
|
True),
|
2005-01-19 02:30:58 +05:30
|
|
|
'incid' : ("=0/1","Whether to include IDs.",
|
2005-01-05 11:26:33 +05:30
|
|
|
["Do not include IDs","Include IDs"],
|
|
|
|
True),
|
2005-01-19 02:30:58 +05:30
|
|
|
'justyears' : ("=0/1","Whether to use years only.",
|
2005-01-05 11:26:33 +05:30
|
|
|
["Do not use years only","Use years only"],
|
|
|
|
True),
|
2005-01-19 02:30:58 +05:30
|
|
|
'placecause': ("=0/1","Whether to replace missing dates with place/cause.",
|
2005-01-15 11:21:48 +05:30
|
|
|
["Do not replace blank dates","Replace blank dates"],
|
|
|
|
True),
|
2005-01-05 11:26:33 +05:30
|
|
|
'url' : ("=0/1","Whether to include URLs.",
|
|
|
|
["Do not include URLs","Include URLs"],
|
|
|
|
True),
|
2005-01-19 02:30:58 +05:30
|
|
|
'rankdir' : ("=str","Graph direction.",
|
2005-01-22 03:16:11 +05:30
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.rankdir ],
|
2005-01-19 02:30:58 +05:30
|
|
|
False),
|
|
|
|
'color' : ("=str","Whether and how to colorize graph.",
|
2005-01-22 03:16:11 +05:30
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.colors ],
|
2005-01-19 02:30:58 +05:30
|
|
|
False),
|
|
|
|
'dashedl' : ("=0/1","Whether to use dotted lines for non-birth relationships.",
|
|
|
|
["Do not use dotted lines","Use dotted lines"],
|
2005-01-05 11:26:33 +05:30
|
|
|
True),
|
2005-08-18 11:28:28 +05:30
|
|
|
'margin' : ("=num","Margin size.",
|
|
|
|
"Floating point value, in cm"),
|
2005-01-05 11:26:33 +05:30
|
|
|
'pagesh' : ("=num","Number of pages in horizontal direction.",
|
|
|
|
"Integer values"),
|
|
|
|
'pagesv' : ("=num","Number of pages in vertical direction.",
|
|
|
|
"Integer values"),
|
2005-01-14 10:32:20 +05:30
|
|
|
'gvof' : ("=str","Output format to convert dot file into.",
|
2005-01-22 03:16:11 +05:30
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.formats ],
|
2005-01-14 10:32:20 +05:30
|
|
|
False),
|
2005-01-05 11:26:33 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
def enable_options(self):
|
|
|
|
# Semi-common options that should be enabled for this report
|
|
|
|
self.enable_dict = {
|
|
|
|
'filter' : 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_report_filters(self,person):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Set up the list of possible content filters."""
|
2005-01-05 11:26:33 +05:30
|
|
|
if person:
|
|
|
|
name = person.get_primary_name().get_name()
|
2005-07-09 01:54:54 +05:30
|
|
|
gramps_id = person.get_gramps_id()
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
|
|
|
name = 'PERSON'
|
2005-07-09 01:54:54 +05:30
|
|
|
gramps_id = ''
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
all = GenericFilter.GenericFilter()
|
|
|
|
all.set_name(_("Entire Database"))
|
|
|
|
all.add_rule(GenericFilter.Everyone([]))
|
|
|
|
|
|
|
|
des = GenericFilter.GenericFilter()
|
|
|
|
des.set_name(_("Descendants of %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
des.add_rule(GenericFilter.IsDescendantOf([gramps_id,1]))
|
2003-01-10 10:51:32 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
ans = GenericFilter.GenericFilter()
|
|
|
|
ans.set_name(_("Ancestors of %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
ans.add_rule(GenericFilter.IsAncestorOf([gramps_id,1]))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
com = GenericFilter.GenericFilter()
|
|
|
|
com.set_name(_("People with common ancestor with %s") % name)
|
2005-07-09 01:54:54 +05:30
|
|
|
com.add_rule(GenericFilter.HasCommonAncestorWith([gramps_id]))
|
2003-01-10 10:51:32 +05:30
|
|
|
|
|
|
|
return [all,des,ans,com]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
def make_doc_menu(self,dialog,active=None):
|
|
|
|
pass
|
2005-01-12 06:18:42 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def add_user_options(self,dialog):
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.handler.module_name == "rel_graph2":
|
2005-01-12 06:18:42 +05:30
|
|
|
dialog.make_doc_menu = self.make_doc_menu
|
|
|
|
dialog.format_menu = GraphicsFormatComboBox()
|
2005-01-14 10:32:20 +05:30
|
|
|
dialog.format_menu.set(self.options_dict['gvof'])
|
2003-08-21 09:17:35 +05:30
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
# Content options tab
|
|
|
|
msg = _("Include Birth, Marriage and Death dates")
|
|
|
|
self.includedates_cb = gtk.CheckButton(msg)
|
|
|
|
self.includedates_cb.set_active(self.options_dict['incdate'])
|
|
|
|
dialog.add_option(None,
|
|
|
|
self.includedates_cb,
|
|
|
|
_("Include the dates that the individual "
|
|
|
|
"was born, got married and/or died "
|
|
|
|
"in the graph labels."))
|
|
|
|
|
|
|
|
self.just_years_cb = gtk.CheckButton(_("Limit dates to years only"))
|
|
|
|
self.just_years_cb.set_active(self.options_dict['justyears'])
|
|
|
|
dialog.add_option(None,
|
|
|
|
self.just_years_cb,
|
|
|
|
_("Prints just dates' year, neither "
|
|
|
|
"month or day nor date approximation "
|
|
|
|
"or interval are shown."))
|
|
|
|
|
|
|
|
self.place_cause_cb = gtk.CheckButton(_("Place/cause when no date"))
|
|
|
|
self.place_cause_cb.set_active(self.options_dict['placecause'])
|
|
|
|
dialog.add_option(None,
|
|
|
|
self.place_cause_cb,
|
|
|
|
_("When no birth, marriage, or death date "
|
|
|
|
"is available, the correspondent place field "
|
|
|
|
"(or cause field when blank place) will be used."))
|
|
|
|
|
|
|
|
# disable other date options if no dates
|
|
|
|
self.includedates_cb.connect('toggled',self.toggle_date)
|
|
|
|
self.toggle_date(self.includedates_cb)
|
|
|
|
|
|
|
|
self.includeurl_cb = gtk.CheckButton(_("Include URLs"))
|
|
|
|
self.includeurl_cb.set_active(self.options_dict['url'])
|
|
|
|
dialog.add_option(None,
|
|
|
|
self.includeurl_cb,
|
|
|
|
_("Include a URL in each graph node so "
|
|
|
|
"that PDF and imagemap files can be "
|
|
|
|
"generated that contain active links "
|
|
|
|
"to the files generated by the 'Generate "
|
|
|
|
"Web Site' report."))
|
|
|
|
|
|
|
|
self.includeid_cb = gtk.CheckButton(_("Include IDs"))
|
|
|
|
self.includeid_cb.set_active(self.options_dict['incid'])
|
|
|
|
dialog.add_option(None,
|
|
|
|
self.includeid_cb,
|
|
|
|
_("Include individual and family IDs."))
|
|
|
|
|
|
|
|
# GraphViz output options tab
|
|
|
|
self.rank_box = gtk.ComboBox()
|
|
|
|
store = gtk.ListStore(str)
|
|
|
|
self.rank_box.set_model(store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.rank_box.pack_start(cell,True)
|
|
|
|
self.rank_box.add_attribute(cell,'text',0)
|
|
|
|
index = 0
|
|
|
|
for item in _options.rankdir:
|
|
|
|
store.append(row=[item[2]])
|
|
|
|
if item[0] == self.options_dict['rankdir']:
|
|
|
|
self.rank_box.set_active(index)
|
|
|
|
index = index + 1
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"),
|
|
|
|
_("Graph direction"),
|
|
|
|
self.rank_box,
|
|
|
|
_("Whether generations go from top to bottom "
|
|
|
|
"or left to right."))
|
|
|
|
|
|
|
|
self.color_box = gtk.ComboBox()
|
|
|
|
store = gtk.ListStore(str)
|
|
|
|
self.color_box.set_model(store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.color_box.pack_start(cell,True)
|
|
|
|
self.color_box.add_attribute(cell,'text',0)
|
|
|
|
index = 0
|
|
|
|
for item in _options.colors:
|
|
|
|
store.append(row=[item[2]])
|
|
|
|
if item[0] == self.options_dict['color']:
|
|
|
|
self.color_box.set_active(index)
|
|
|
|
index = index + 1
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"),
|
|
|
|
_("Graph coloring"),
|
|
|
|
self.color_box,
|
|
|
|
_("Males will be shown with blue, females "
|
|
|
|
"with red. If the sex of an individual "
|
|
|
|
"is unknown it will be shown with gray."))
|
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
self.arrowstyle_box = gtk.ComboBox()
|
|
|
|
store = gtk.ListStore(str)
|
|
|
|
self.arrowstyle_box.set_model(store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.arrowstyle_box.pack_start(cell,True)
|
|
|
|
self.arrowstyle_box.add_attribute(cell,'text',0)
|
|
|
|
index = 0
|
2005-01-19 02:30:58 +05:30
|
|
|
for item in _options.arrowstyles:
|
|
|
|
store.append(row=[item[2]])
|
|
|
|
if item[0] == self.options_dict['arrow']:
|
|
|
|
self.arrowstyle_box.set_active(index)
|
2005-01-05 11:26:33 +05:30
|
|
|
index = index + 1
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"),
|
2005-01-19 02:30:58 +05:30
|
|
|
_("Arrowhead direction"),
|
|
|
|
self.arrowstyle_box,
|
|
|
|
_("Choose the direction that the arrows point."))
|
2003-08-21 09:17:35 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
self.font_box = gtk.ComboBox()
|
|
|
|
store = gtk.ListStore(str)
|
|
|
|
self.font_box.set_model(store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.font_box.pack_start(cell,True)
|
|
|
|
self.font_box.add_attribute(cell,'text',0)
|
|
|
|
index = 0
|
2005-01-19 02:30:58 +05:30
|
|
|
for item in _options.fonts:
|
|
|
|
if item[3]:
|
|
|
|
name = "%s (iso-latin1 font)" % item[2]
|
|
|
|
else:
|
|
|
|
name = item[2]
|
|
|
|
store.append(row=[name])
|
|
|
|
if item[0] == self.options_dict['font']:
|
|
|
|
self.font_box.set_active(index)
|
2005-01-05 11:26:33 +05:30
|
|
|
index = index + 1
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"),
|
2005-01-19 02:30:58 +05:30
|
|
|
_("Font family"),
|
2005-01-05 11:26:33 +05:30
|
|
|
self.font_box,
|
2005-01-19 02:30:58 +05:30
|
|
|
_("Choose the font family. If international "
|
|
|
|
"characters don't show, use FreeSans font. "
|
|
|
|
"FreeSans is available from: "
|
|
|
|
"http://www.nongnu.org/freefont/"))
|
2003-08-21 09:17:35 +05:30
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
self.adoptionsdashed_cb = gtk.CheckButton(_("Indicate non-birth relationships with dotted lines"))
|
2005-01-05 11:26:33 +05:30
|
|
|
self.adoptionsdashed_cb.set_active(self.options_dict['dashedl'])
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"), '',
|
2002-10-20 19:55:16 +05:30
|
|
|
self.adoptionsdashed_cb,
|
|
|
|
_("Non-birth relationships will show up "
|
2005-01-19 02:30:58 +05:30
|
|
|
"as dotted lines in the graph."))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
self.show_families_cb = gtk.CheckButton(_("Show family nodes"))
|
2005-01-19 02:30:58 +05:30
|
|
|
self.show_families_cb.set_active(self.options_dict['showfamily'])
|
2005-01-05 11:26:33 +05:30
|
|
|
dialog.add_frame_option(_("GraphViz Options"), '',
|
2003-01-10 10:51:32 +05:30
|
|
|
self.show_families_cb,
|
2003-08-02 08:49:28 +05:30
|
|
|
_("Families will show up as ellipses, linked "
|
2003-01-10 10:51:32 +05:30
|
|
|
"to parents and children."))
|
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
# Page options tab
|
2005-08-18 11:28:28 +05:30
|
|
|
margin_adj = gtk.Adjustment(value=self.options_dict['margin'],
|
|
|
|
lower=0.0, upper=10.0, step_incr=1.0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-08-18 11:28:28 +05:30
|
|
|
self.margin_sb = gtk.SpinButton(adjustment=margin_adj, digits=1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
dialog.add_frame_option(_("Page Options"),
|
2005-08-18 11:28:28 +05:30
|
|
|
_("Margin size"),
|
|
|
|
self.margin_sb)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
hpages_adj = gtk.Adjustment(value=self.options_dict['pagesh'],
|
|
|
|
lower=1, upper=25, step_incr=1)
|
|
|
|
vpages_adj = gtk.Adjustment(value=self.options_dict['pagesv'],
|
|
|
|
lower=1, upper=25, step_incr=1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
self.hpages_sb = gtk.SpinButton(adjustment=hpages_adj, digits=0)
|
|
|
|
self.vpages_sb = gtk.SpinButton(adjustment=vpages_adj, digits=0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
dialog.add_frame_option(_("Page Options"),
|
2002-10-20 19:55:16 +05:30
|
|
|
_("Number of Horizontal Pages"),
|
|
|
|
self.hpages_sb,
|
|
|
|
_("GraphViz can create very large graphs by "
|
|
|
|
"spreading the graph across a rectangular "
|
|
|
|
"array of pages. This controls the number "
|
|
|
|
"pages in the array horizontally."))
|
2005-01-05 11:26:33 +05:30
|
|
|
dialog.add_frame_option(_("Page Options"),
|
2002-10-20 19:55:16 +05:30
|
|
|
_("Number of Vertical Pages"),
|
|
|
|
self.vpages_sb,
|
|
|
|
_("GraphViz can create very large graphs "
|
|
|
|
"by spreading the graph across a "
|
|
|
|
"rectangular array of pages. This "
|
|
|
|
"controls the number pages in the array "
|
|
|
|
"vertically."))
|
|
|
|
|
2005-01-19 02:30:58 +05:30
|
|
|
def toggle_date(self, obj):
|
|
|
|
self.just_years_cb.set_sensitive(self.includedates_cb.get_active())
|
2005-01-15 11:21:48 +05:30
|
|
|
self.place_cause_cb.set_sensitive(self.includedates_cb.get_active())
|
2003-08-02 09:00:52 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def parse_user_options(self,dialog):
|
2005-01-19 02:30:58 +05:30
|
|
|
self.options_dict['incdate'] = int(self.includedates_cb.get_active())
|
2005-01-05 11:26:33 +05:30
|
|
|
self.options_dict['url'] = int(self.includeurl_cb.get_active())
|
2005-08-18 11:28:28 +05:30
|
|
|
self.options_dict['margin'] = self.margin_sb.get_value()
|
2005-01-05 11:26:33 +05:30
|
|
|
self.options_dict['dashedl'] = int(self.adoptionsdashed_cb.get_active())
|
|
|
|
self.options_dict['pagesh'] = self.hpages_sb.get_value_as_int()
|
2005-02-17 02:32:39 +05:30
|
|
|
self.options_dict['pagesv'] = self.vpages_sb.get_value_as_int()
|
2005-01-19 02:30:58 +05:30
|
|
|
self.options_dict['showfamily'] = int(self.show_families_cb.get_active())
|
2005-01-05 11:26:33 +05:30
|
|
|
self.options_dict['incid'] = int(self.includeid_cb.get_active())
|
2005-05-11 19:34:47 +05:30
|
|
|
self.options_dict['justyears'] = int(self.just_years_cb.get_active())
|
2005-01-19 02:30:58 +05:30
|
|
|
self.options_dict['placecause'] = int(self.place_cause_cb.get_active())
|
|
|
|
self.options_dict['rankdir'] = \
|
|
|
|
_options.rankdir[self.rank_box.get_active()][0]
|
|
|
|
self.options_dict['color'] = \
|
|
|
|
_options.colors[self.color_box.get_active()][0]
|
|
|
|
self.options_dict['arrow'] = \
|
|
|
|
_options.arrowstyles[self.arrowstyle_box.get_active()][0]
|
2005-01-05 11:26:33 +05:30
|
|
|
self.options_dict['font'] = \
|
2005-01-19 02:30:58 +05:30
|
|
|
_options.fonts[self.font_box.get_active()][0]
|
|
|
|
self.options_dict['latin'] = \
|
|
|
|
_options.fonts[self.font_box.get_active()][3]
|
2005-12-06 12:08:09 +05:30
|
|
|
if self.handler.module_name == "rel_graph2":
|
2005-01-14 10:32:20 +05:30
|
|
|
self.options_dict['gvof'] = dialog.format_menu.get_format_str()
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Dialog class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GraphVizDialog(Report.ReportDialog):
|
|
|
|
|
2005-01-07 10:23:43 +05:30
|
|
|
def __init__(self,database,person):
|
2005-01-05 11:26:33 +05:30
|
|
|
self.database = database
|
|
|
|
self.person = person
|
|
|
|
name = "rel_graph"
|
|
|
|
translated_name = _("Relationship Graph")
|
|
|
|
self.options_class = GraphVizOptions(name)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.category = Report.CATEGORY_CODE
|
2005-01-05 11:26:33 +05:30
|
|
|
Report.ReportDialog.__init__(self,database,person,self.options_class,
|
|
|
|
name,translated_name)
|
|
|
|
|
|
|
|
response = self.window.run()
|
2005-01-30 03:35:21 +05:30
|
|
|
if response == gtk.RESPONSE_OK:
|
2005-01-05 11:26:33 +05:30
|
|
|
try:
|
|
|
|
self.make_report()
|
|
|
|
except (IOError,OSError),msg:
|
|
|
|
ErrorDialog(str(msg))
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def make_doc_menu(self,active=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Build a one item menu of document types that are
|
|
|
|
appropriate for this report."""
|
2005-01-05 11:26:33 +05:30
|
|
|
self.format_menu = FormatComboBox()
|
|
|
|
self.format_menu.set()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def make_document(self):
|
|
|
|
"""Do Nothing. This document will be created in the
|
|
|
|
make_report routine."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setup_style_frame(self):
|
|
|
|
"""The style frame is not used in this dialog."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def parse_style_frame(self):
|
|
|
|
"""The style frame is not used in this dialog."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def make_report(self):
|
|
|
|
"""Create the object that will produce the GraphViz file."""
|
2005-01-05 11:26:33 +05:30
|
|
|
GraphViz(self.database,self.person,self.options_class)
|
2003-07-25 23:52:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-12 06:18:42 +05:30
|
|
|
# Combo Box classes
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-05 11:26:33 +05:30
|
|
|
class FormatComboBox(gtk.ComboBox):
|
|
|
|
"""
|
|
|
|
Format combo box class.
|
|
|
|
|
|
|
|
Trivial class supporting only one format.
|
|
|
|
"""
|
2003-01-10 10:51:32 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def set(self,tables=0,callback=None,obj=None,active=None):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell,True)
|
|
|
|
self.add_attribute(cell,'text',0)
|
|
|
|
self.store.append(row=["Graphviz (dot)"])
|
|
|
|
self.set_active(0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
def get_label(self):
|
|
|
|
return "Graphviz (dot)"
|
|
|
|
|
|
|
|
def get_reference(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_paper(self):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def get_styles(self):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_ext(self):
|
|
|
|
return '.dot'
|
|
|
|
|
|
|
|
def get_printable(self):
|
2005-01-18 02:16:32 +05:30
|
|
|
return None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-14 10:32:20 +05:30
|
|
|
def get_clname(self):
|
|
|
|
return 'dot'
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
class GraphicsFormatComboBox(gtk.ComboBox):
|
|
|
|
"""
|
|
|
|
Format combo box class for graphical (not codegen) report.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def set(self,active=None):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell,True)
|
|
|
|
self.add_attribute(cell,'text',0)
|
2005-01-14 10:32:20 +05:30
|
|
|
active_index = 0
|
|
|
|
index = 0
|
2005-01-19 02:30:58 +05:30
|
|
|
for item in _options.formats:
|
|
|
|
self.store.append(row=[item[2]])
|
|
|
|
if active == item[0]:
|
2005-01-14 10:32:20 +05:30
|
|
|
active_index = index
|
|
|
|
index = index + 1
|
|
|
|
self.set_active(active_index)
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
def get_label(self):
|
2005-01-19 02:30:58 +05:30
|
|
|
return _options.formats[self.get_active()][2]
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
def get_reference(self):
|
|
|
|
return EmptyDoc
|
|
|
|
|
|
|
|
def get_paper(self):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def get_styles(self):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_ext(self):
|
2005-01-19 02:30:58 +05:30
|
|
|
return '.%s' % _options.formats[self.get_active()][0]
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
def get_format_str(self):
|
2005-01-19 02:30:58 +05:30
|
|
|
return _options.formats[self.get_active()][0]
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
def get_printable(self):
|
2006-04-13 08:31:12 +05:30
|
|
|
_apptype = _options.formats[self.get_active()][3]
|
|
|
|
print_label = None
|
|
|
|
try:
|
|
|
|
import Utils
|
|
|
|
import GrampsMime
|
|
|
|
mprog = GrampsMime.get_application(_apptype)
|
|
|
|
if Utils.search_for(mprog[0]):
|
|
|
|
print_label = _("Open in %(program_name)s") % { 'program_name':
|
|
|
|
mprog[1]}
|
|
|
|
else:
|
|
|
|
print_label = None
|
|
|
|
except:
|
|
|
|
print_label = None
|
|
|
|
return print_label
|
2005-01-12 06:18:42 +05:30
|
|
|
|
2005-01-14 10:32:20 +05:30
|
|
|
def get_clname(self):
|
|
|
|
return 'print'
|
|
|
|
|
2005-01-12 06:18:42 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Empty class to keep the BaseDoc-targeted format happy
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class EmptyDoc:
|
|
|
|
def __init__(self,styles,type,template,orientation,source=None):
|
2006-04-13 08:31:12 +05:30
|
|
|
self.print_req = 0
|
2005-01-12 06:18:42 +05:30
|
|
|
pass
|
|
|
|
|
2005-01-30 03:35:21 +05:30
|
|
|
def init(self):
|
|
|
|
pass
|
2006-04-13 08:31:12 +05:30
|
|
|
|
|
|
|
def print_requested(self):
|
|
|
|
self.print_req = 1
|
2005-01-30 03:35:21 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-05 11:26:33 +05:30
|
|
|
#
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-05 11:26:33 +05:30
|
|
|
def cl_report(database,name,category,options_str_dict):
|
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
clr = Report.CommandLineReport(database,name,category,GraphVizOptions,
|
|
|
|
options_str_dict)
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
# Exit here if show option was given
|
|
|
|
if clr.show:
|
|
|
|
return
|
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
GraphViz(database,clr.person,clr.option_class)
|
2003-01-10 10:51:32 +05:30
|
|
|
|
2005-01-12 06:18:42 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GraphVizGraphics(Report.Report):
|
|
|
|
def __init__(self,database,person,options_class):
|
|
|
|
self.database = database
|
|
|
|
self.start_person = person
|
|
|
|
self.options_class = options_class
|
2005-01-30 03:35:21 +05:30
|
|
|
self.doc = options_class.get_document()
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
self.user_output = options_class.get_output()
|
2006-03-29 09:41:17 +05:30
|
|
|
self.junk_output = os.path.join(const.home_dir,"junk")
|
2005-01-14 10:32:20 +05:30
|
|
|
self.the_format = self.options_class.handler.options_dict['gvof']
|
2005-01-12 06:18:42 +05:30
|
|
|
self.the_font = self.options_class.handler.options_dict['font']
|
|
|
|
|
|
|
|
def begin_report(self):
|
|
|
|
self.options_class.set_output(self.junk_output)
|
|
|
|
|
|
|
|
def write_report(self):
|
|
|
|
GraphViz(self.database,self.start_person,self.options_class)
|
|
|
|
|
|
|
|
def end_report(self):
|
2005-01-18 02:16:32 +05:30
|
|
|
os.system('dot -T%s -o%s %s ; rm %s' %
|
2005-01-12 06:18:42 +05:30
|
|
|
(self.the_format,self.user_output,
|
|
|
|
self.junk_output,self.junk_output))
|
|
|
|
|
2006-04-13 08:31:12 +05:30
|
|
|
if self.doc.print_req:
|
|
|
|
_apptype = None
|
|
|
|
for format in _options.formats:
|
|
|
|
if format[0] == self.the_format:
|
|
|
|
_apptype = format[3]
|
|
|
|
break
|
|
|
|
if _apptype:
|
|
|
|
try:
|
|
|
|
import Utils
|
|
|
|
import GrampsMime
|
|
|
|
app = GrampsMime.get_application(_apptype)
|
|
|
|
os.environ["FILE"] = self.user_output
|
|
|
|
os.system ('%s "$FILE" &' % app[0])
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2003-01-10 10:51:32 +05:30
|
|
|
#
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
def get_description():
|
|
|
|
return _("Generates relationship graphs, currently only in GraphViz "
|
|
|
|
"format. GraphViz (dot) can transform the graph into "
|
|
|
|
"postscript, jpeg, png, vrml, svg, and many other formats. "
|
|
|
|
"For more information or to get a copy of GraphViz, "
|
|
|
|
"goto http://www.graphviz.org")
|
|
|
|
|
2005-01-12 06:18:42 +05:30
|
|
|
def get_description_graphics():
|
|
|
|
return _("Generates relationship graphs using GraphViz (dot) program. "
|
|
|
|
"This report generates dot file behind the scene and then "
|
|
|
|
"uses dot to convert it into a graph. If you want the dot"
|
|
|
|
"file itself, please use the Code Generators category.")
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-05 11:26:33 +05:30
|
|
|
register_report(
|
|
|
|
name = 'rel_graph',
|
2005-12-06 12:08:09 +05:30
|
|
|
category = Report.CATEGORY_CODE,
|
2005-01-05 11:26:33 +05:30
|
|
|
report_class = GraphVizDialog,
|
|
|
|
options_class = cl_report,
|
|
|
|
modes = Report.MODE_GUI | Report.MODE_CLI,
|
|
|
|
translated_name = _("Relationship Graph"),
|
2005-12-06 12:08:09 +05:30
|
|
|
status = _("Stable"),
|
2005-01-05 11:26:33 +05:30
|
|
|
description= get_description(),
|
|
|
|
author_name="Donald N. Allingham",
|
2005-12-06 12:08:09 +05:30
|
|
|
author_email="don@gramps-project.org"
|
2005-01-05 11:26:33 +05:30
|
|
|
)
|
2005-01-12 06:18:42 +05:30
|
|
|
|
|
|
|
if dot_found:
|
|
|
|
register_report(
|
|
|
|
name = 'rel_graph2',
|
2005-12-06 12:08:09 +05:30
|
|
|
category = Report.CATEGORY_DRAW,
|
2005-01-12 06:18:42 +05:30
|
|
|
report_class = GraphVizGraphics,
|
|
|
|
options_class = GraphVizOptions,
|
|
|
|
modes = Report.MODE_GUI | Report.MODE_CLI,
|
|
|
|
translated_name = _("Relationship Graph"),
|
2005-12-06 12:08:09 +05:30
|
|
|
status = _("Stable"),
|
2005-01-12 06:18:42 +05:30
|
|
|
description= get_description_graphics(),
|
|
|
|
author_name="Donald N. Allingham",
|
2005-12-06 12:08:09 +05:30
|
|
|
author_email="don@gramps-project.org"
|
2005-01-12 06:18:42 +05:30
|
|
|
)
|