2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2007-07-24 08:50:23 +05:30
|
|
|
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
|
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$
|
|
|
|
|
2007-08-16 17:39:49 +05:30
|
|
|
"""
|
|
|
|
Generate graphviz dot files --- create a relationship graph
|
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
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
|
2007-01-15 03:39:14 +05:30
|
|
|
import tempfile
|
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-06-01 10:09:40 +05:30
|
|
|
from PluginUtils import register_report
|
|
|
|
from ReportBase import Report, ReportUtils, ReportOptions, \
|
|
|
|
CATEGORY_CODE, CATEGORY_DRAW, MODE_GUI, MODE_CLI
|
|
|
|
from ReportBase._ReportDialog import ReportDialog
|
|
|
|
from ReportBase._CommandLineReport import CommandLineReport
|
2006-08-22 10:58:55 +05:30
|
|
|
from Filters import GenericFilter, Rules
|
2005-07-09 01:54:54 +05:30
|
|
|
import RelLib
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer
|
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
|
2006-07-20 05:12:50 +05:30
|
|
|
import Errors
|
2006-07-22 11:22:16 +05:30
|
|
|
import Utils
|
|
|
|
import Mime
|
2007-08-16 17:39:49 +05:30
|
|
|
import ImgManip
|
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
|
2006-05-02 02:41:26 +05:30
|
|
|
("", "Default", _("Default")),
|
|
|
|
("Helvetica", "Postscript / Helvetica", _("Postscript / Helvetica")),
|
|
|
|
("FreeSans", "Truetype / FreeSans", _("Truetype / FreeSans")),
|
2005-01-19 02:30:58 +05:30
|
|
|
)
|
|
|
|
colors = (
|
|
|
|
("outline", "B&W Outline", _("B&W outline")),
|
|
|
|
("colored", "Colored outline", _("Colored outline")),
|
|
|
|
("filled", "Color fill", _("Color fill")),
|
|
|
|
)
|
2006-05-02 02:41:26 +05:30
|
|
|
ratio = (
|
|
|
|
("compress", "Minimal size", _("Minimal size")),
|
|
|
|
("fill", "Fill the given area", _("Fill the given area")),
|
|
|
|
("expand", "Automatically use optimal number of pages",
|
|
|
|
_("Automatically use optimal number of pages"))
|
|
|
|
)
|
2005-01-19 02:30:58 +05:30
|
|
|
rankdir = (
|
2006-05-02 02:41:26 +05:30
|
|
|
("TB", "Vertical", _("Vertical")),
|
2005-01-19 02:30:58 +05:30
|
|
|
("LR", "Horizontal", _("Horizontal")),
|
2006-05-02 02:41:26 +05:30
|
|
|
)
|
|
|
|
pagedir = (
|
|
|
|
("BL", "Bottom, left", _("Bottom, left")),
|
|
|
|
("BR", "Bottom, right", _("Bottom, right")),
|
|
|
|
("TL", "Top, left", _("Top, left")),
|
|
|
|
("TR", "Top, right", _("Top, Right")),
|
|
|
|
("RB", "Right, bottom", _("Right, bottom")),
|
|
|
|
("RT", "Right, top", _("Right, top")),
|
|
|
|
("LB", "Left, bottom", _("Left, bottom")),
|
|
|
|
("LT", "Left, top", _("Left, top")),
|
|
|
|
)
|
|
|
|
noteloc = (
|
|
|
|
("t", "Top", _("Top")),
|
|
|
|
("b", "Bottom", _("Bottom")),
|
2005-01-19 02:30:58 +05:30
|
|
|
)
|
|
|
|
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
|
|
|
|
2007-01-15 03:39:14 +05:30
|
|
|
gs_cmd = ""
|
|
|
|
|
2006-07-19 09:35:17 +05:30
|
|
|
if os.sys.platform == "win32":
|
2006-07-22 11:22:16 +05:30
|
|
|
_dot_found = Utils.search_for("dot.exe")
|
2007-01-15 03:39:14 +05:30
|
|
|
|
|
|
|
if Utils.search_for("gswin32c.exe") == 1:
|
|
|
|
gs_cmd = "gswin32c.exe"
|
|
|
|
elif Utils.search_for("gswin32.exe") == 1:
|
|
|
|
gs_cmd = "gswin32.exe"
|
2006-07-19 09:35:17 +05:30
|
|
|
else:
|
2006-07-22 11:22:16 +05:30
|
|
|
_dot_found = Utils.search_for("dot")
|
2007-01-15 03:39:14 +05:30
|
|
|
|
|
|
|
if Utils.search_for("gs") == 1:
|
|
|
|
gs_cmd = "gs"
|
2006-05-02 02:41:26 +05:30
|
|
|
|
2007-01-15 03:39:14 +05:30
|
|
|
if gs_cmd != "":
|
2006-05-02 02:41:26 +05:30
|
|
|
_options.formats += (("pdf", "PDF", _("PDF"), "application/pdf"),)
|
2005-01-12 06:18:42 +05:30
|
|
|
|
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.
|
2007-01-14 09:39:44 +05:30
|
|
|
fontsize - Size of the font in points
|
2006-05-02 02:41:26 +05:30
|
|
|
latin - Set if text needs to be converted to latin-1
|
2005-01-19 02:30:58 +05:30
|
|
|
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.
|
2007-08-16 17:39:49 +05:30
|
|
|
inclimg - Include images or not
|
|
|
|
imgpos - Image position, above/beside name
|
2006-05-02 02:41:26 +05:30
|
|
|
rankdir - Graph direction, LR or RL
|
|
|
|
ratio - Output aspect ration, fill/compress/auto
|
2005-01-19 02:30:58 +05:30
|
|
|
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.
|
2006-05-02 02:41:26 +05:30
|
|
|
pagedir - Paging direction
|
|
|
|
note - Note to add to the graph
|
|
|
|
notesize - Note font size (in points)
|
|
|
|
noteloc - Note location t/b
|
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
|
2006-05-02 02:41:26 +05:30
|
|
|
self.pagedir = options['pagedir']
|
2005-01-19 02:30:58 +05:30
|
|
|
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:
|
2006-05-02 02:41:26 +05:30
|
|
|
# GraphViz has rounding errors so have to make the real
|
|
|
|
# margins slightly smaller than (page - content size)
|
2005-08-18 11:28:28 +05:30
|
|
|
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']
|
2007-08-16 17:39:49 +05:30
|
|
|
self.includeimg = options['includeImages']
|
|
|
|
self.imgpos = options['imageOnTheSide']
|
2005-01-19 02:30:58 +05:30
|
|
|
self.adoptionsdashed = options['dashedl']
|
|
|
|
self.show_families = options['showfamily']
|
|
|
|
self.just_years = options['justyears']
|
|
|
|
self.placecause = options['placecause']
|
|
|
|
self.rankdir = options['rankdir']
|
2006-05-02 02:41:26 +05:30
|
|
|
self.ratio = options['ratio']
|
2005-01-19 02:30:58 +05:30
|
|
|
self.fontname = options['font']
|
2007-01-14 09:39:44 +05:30
|
|
|
self.fontsize = options['fontsize']
|
2005-01-19 02:30:58 +05:30
|
|
|
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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
self.latin = options['latin']
|
|
|
|
self.noteloc = options['noteloc']
|
|
|
|
self.notesize = options['notesize']
|
|
|
|
self.note = options['note']
|
|
|
|
|
2007-03-26 02:05:33 +05:30
|
|
|
filter_num = options_class.handler.options_dict['filter']
|
|
|
|
filters = ReportUtils.get_person_filters(person,include_single=False)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.filter = filters[filter_num]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
the_buffer = self.get_report()
|
2006-07-20 05:12:50 +05:30
|
|
|
|
2006-07-21 01:19:27 +05:30
|
|
|
self.f = open(options_class.get_output(),'w')
|
|
|
|
if self.latin:
|
|
|
|
try:
|
|
|
|
self.f.write(the_buffer.encode('iso-8859-1', 'strict'))
|
|
|
|
except UnicodeEncodeError:
|
2006-07-20 05:12:50 +05:30
|
|
|
self.f = open(options_class.get_output(),'w')
|
|
|
|
self.f.write(the_buffer.encode('iso-8859-1', 'replace'))
|
2006-07-21 01:19:27 +05:30
|
|
|
ErrorDialog(
|
|
|
|
_("Your data contains characters that cannot be "
|
|
|
|
"converted to latin-1. These characters were "
|
|
|
|
"replaced with the question marks in the output. "
|
|
|
|
"To get these characters properly displayed, "
|
|
|
|
"unselect latin-1 option and try again."))
|
|
|
|
else:
|
|
|
|
self.f.write(the_buffer)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.f.close()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
def get_report(self):
|
|
|
|
"return string of the .dot file contents"
|
|
|
|
self.person_handles = self.filter.apply(self.database,
|
2005-01-05 11:26:33 +05:30
|
|
|
self.database.get_person_handles(sort_handles=False))
|
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
# graph size
|
2005-08-18 11:28:28 +05:30
|
|
|
if self.orient == PAPER_LANDSCAPE:
|
2006-05-02 02:41:26 +05:30
|
|
|
rotate = 90
|
|
|
|
sizew = (self.height - self.margin*2) * self.hpages
|
|
|
|
sizeh = (self.width - self.margin*2) * self.vpages
|
|
|
|
else:
|
|
|
|
rotate = 0
|
|
|
|
sizew = (self.width - self.margin*2) * self.hpages
|
|
|
|
sizeh = (self.height - self.margin*2) * self.vpages
|
|
|
|
|
|
|
|
|
|
|
|
buffer = self.get_comment_header()
|
|
|
|
buffer += """
|
|
|
|
digraph GRAMPS_relationship_graph {
|
|
|
|
/* whole graph attributes */
|
|
|
|
bgcolor=white;
|
|
|
|
center=1;
|
|
|
|
ratio=%s;
|
|
|
|
rankdir=%s;
|
|
|
|
mclimit=2.0;
|
|
|
|
margin="%3.2f";
|
|
|
|
pagedir="%s";
|
|
|
|
page="%3.2f,%3.2f";
|
|
|
|
size="%3.2f,%3.2f";
|
|
|
|
rotate=%d;
|
|
|
|
/* default node and edge attributes */
|
|
|
|
nodesep=0.25;
|
2007-01-10 08:35:19 +05:30
|
|
|
edge [style=solid, arrowhead=%s arrowtail=%s];
|
2006-05-02 02:41:26 +05:30
|
|
|
""" % (
|
|
|
|
self.ratio,
|
|
|
|
self.rankdir,
|
|
|
|
self.margin_small,
|
|
|
|
self.pagedir,
|
|
|
|
self.width, self.height,
|
|
|
|
sizew, sizeh,
|
|
|
|
rotate,
|
|
|
|
self.arrowheadstyle,
|
|
|
|
self.arrowtailstyle
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.fontname:
|
2007-01-14 09:39:44 +05:30
|
|
|
font = 'fontname="%s" ' % self.fontname
|
2006-05-02 02:41:26 +05:30
|
|
|
else:
|
|
|
|
font = ''
|
2007-01-14 09:39:44 +05:30
|
|
|
font += 'fontsize="%d"' % self.fontsize
|
2006-05-02 02:41:26 +05:30
|
|
|
if self.colorize == 'filled':
|
|
|
|
buffer += 'node [style=filled %s];\n' % font
|
2005-08-18 11:28:28 +05:30
|
|
|
else:
|
2006-05-02 02:41:26 +05:30
|
|
|
buffer += 'node [%s];\n' % font
|
|
|
|
if self.latin:
|
|
|
|
# GraphViz default is UTF-8
|
|
|
|
buffer += 'charset="iso-8859-1";\n'
|
|
|
|
|
|
|
|
if len(self.person_handles) > 1:
|
|
|
|
buffer += "/* persons and their families */\n"
|
|
|
|
buffer += self.get_persons_and_families()
|
|
|
|
buffer += "/* link children to families */\n"
|
|
|
|
buffer += self.get_child_links_to_families()
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
if self.note:
|
|
|
|
buffer += 'labelloc="%s";\n' % self.noteloc
|
|
|
|
buffer += 'label="%s";\n' % self.note.replace('\n', '\\n').replace('"', '\\\"')
|
|
|
|
buffer += 'fontsize="%d";\n' % self.notesize # in points
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
return buffer + "}\n"
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
|
|
|
|
def get_comment_header(self):
|
|
|
|
"return comment of Gramps options which are not Graphviz options"
|
|
|
|
return """/*
|
|
|
|
GRAMPS - Relationship graph
|
|
|
|
|
|
|
|
Generated on %s.
|
|
|
|
|
|
|
|
Report content options:
|
|
|
|
include URLs : %s
|
|
|
|
IDs : %s
|
|
|
|
dates : %s
|
|
|
|
just year : %s
|
|
|
|
place or cause : %s
|
|
|
|
colorize : %s
|
|
|
|
dotted adoptions : %s
|
|
|
|
show family nodes : %s
|
|
|
|
pages horizontal : %s
|
|
|
|
vertical : %s
|
|
|
|
|
|
|
|
For other options, see graph settings below.
|
|
|
|
|
|
|
|
If you need to switch between iso-8859-1 and utf-8 text encodings,
|
|
|
|
e.g. because you're using different font or -T output format,
|
|
|
|
just use iconv:
|
|
|
|
iconv -f iso-8859-1 -t utf-8 old.dot > new.dot
|
|
|
|
iconv -t utf-8 -f iso-8859-1 old.dot > new.dot
|
|
|
|
*/
|
|
|
|
""" % (
|
|
|
|
asctime(),
|
|
|
|
bool(self.includeurl),
|
|
|
|
bool(self.includeid),
|
|
|
|
bool(self.includedates),
|
|
|
|
bool(self.just_years),
|
|
|
|
bool(self.placecause),
|
|
|
|
bool(self.colorize),
|
|
|
|
bool(self.adoptionsdashed),
|
|
|
|
bool(self.show_families),
|
|
|
|
self.hpages, self.vpages
|
|
|
|
)
|
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
def get_child_links_to_families(self):
|
|
|
|
"returns string of GraphViz edges linking parents to families or children"
|
2005-01-05 11:26:33 +05:30
|
|
|
person_dict = {}
|
2006-05-02 02:41:26 +05:30
|
|
|
# Hash people in a dictionary for faster inclusion checking
|
|
|
|
for person_handle in self.person_handles:
|
|
|
|
person_dict[person_handle] = 1
|
|
|
|
the_buffer = ""
|
|
|
|
for person_handle in self.person_handles:
|
2005-01-05 11:26:33 +05:30
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
2006-05-02 02:41:26 +05:30
|
|
|
p_id = person.get_gramps_id()
|
|
|
|
for fam_handle in person.get_parent_family_handle_list():
|
|
|
|
family = self.database.get_family_from_handle(fam_handle)
|
2005-01-05 11:26:33 +05:30
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
2006-05-02 02:41:26 +05:30
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
if child_ref.ref == person_handle:
|
|
|
|
frel = child_ref.frel
|
|
|
|
mrel = child_ref.mrel
|
|
|
|
break
|
2005-01-05 11:26:33 +05:30
|
|
|
if (self.show_families and
|
2006-05-02 02:41:26 +05:30
|
|
|
((father_handle and father_handle in person_dict) or
|
|
|
|
(mother_handle and mother_handle in person_dict))):
|
|
|
|
# Link to the family node if either parent is in graph
|
|
|
|
the_buffer += self.get_family_link(p_id,family,frel,mrel)
|
2005-01-05 11:26:33 +05:30
|
|
|
else:
|
2006-05-02 02:41:26 +05:30
|
|
|
# Link to the parents' nodes directly, if they are in graph
|
|
|
|
if father_handle and father_handle in person_dict:
|
|
|
|
the_buffer += self.get_parent_link(p_id,father_handle,frel)
|
|
|
|
if mother_handle and mother_handle in person_dict:
|
|
|
|
the_buffer += self.get_parent_link(p_id,mother_handle,mrel)
|
|
|
|
return the_buffer
|
|
|
|
|
|
|
|
def get_family_link(self, p_id, family, frel, mrel):
|
|
|
|
"returns string of GraphViz edge linking child to family"
|
|
|
|
style = ''
|
|
|
|
adopted = ((int(frel) != RelLib.ChildRefType.BIRTH) or
|
|
|
|
(int(mrel) != RelLib.ChildRefType.BIRTH))
|
|
|
|
if adopted and self.adoptionsdashed:
|
|
|
|
style = 'style=dotted'
|
|
|
|
return '"p%s" -> "f%s" [%s];\n' % (p_id,
|
|
|
|
family.get_gramps_id(), style)
|
|
|
|
|
|
|
|
def get_parent_link(self, p_id, parent_handle, rel):
|
|
|
|
"returns string of GraphViz edge linking child to parent"
|
|
|
|
style = ''
|
|
|
|
if (int(rel) != RelLib.ChildRefType.BIRTH) and self.adoptionsdashed:
|
|
|
|
style = 'style=dotted'
|
|
|
|
parent = self.database.get_person_from_handle(parent_handle)
|
|
|
|
return '"p%s" -> "p%s" [%s];\n' % (p_id, parent.get_gramps_id(), style)
|
|
|
|
|
|
|
|
def get_persons_and_families(self):
|
|
|
|
"returns string of GraphViz nodes for persons and their families"
|
2007-08-16 17:39:49 +05:30
|
|
|
# variable to communicate with get_person_label
|
|
|
|
self.bUseHtmlOutput = False
|
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
# The list of families for which we have output the node,
|
|
|
|
# so we don't do it twice
|
|
|
|
buffer = ""
|
|
|
|
families_done = {}
|
|
|
|
for person_handle in self.person_handles:
|
2007-08-16 17:39:49 +05:30
|
|
|
# determine per person if we use HTML style label
|
|
|
|
if self.includeimg:
|
|
|
|
self.bUseHtmlOutput = True
|
2005-01-05 11:26:33 +05:30
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
2006-05-02 02:41:26 +05:30
|
|
|
p_id = person.get_gramps_id()
|
|
|
|
# Output the person's node
|
|
|
|
label = self.get_person_label(person)
|
|
|
|
style = self.get_gender_style(person)
|
|
|
|
url = ""
|
2005-01-05 11:26:33 +05:30
|
|
|
if self.includeurl:
|
2006-05-02 02:41:26 +05:30
|
|
|
h = person_handle
|
2007-07-24 08:34:49 +05:30
|
|
|
dirpath = "ppl/%s/%s" % (h[0], h[1])
|
|
|
|
if os.sys.platform == "win32":
|
|
|
|
dirpath = dirpath.lower()
|
|
|
|
url = ', URL="%s/%s.html", ' % (dirpath,h)
|
2007-08-16 17:39:49 +05:30
|
|
|
|
|
|
|
if self.bUseHtmlOutput:
|
|
|
|
label = '<%s>' % label
|
|
|
|
else:
|
|
|
|
label = '"%s"' % label
|
|
|
|
|
|
|
|
buffer += '"p%s" [label=%s, %s%s];\n' % (p_id, label, style, url)
|
2006-05-02 02:41:26 +05:30
|
|
|
|
|
|
|
# Output families where person is a parent
|
2005-01-05 11:26:33 +05:30
|
|
|
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)
|
2006-05-02 02:41:26 +05:30
|
|
|
fam_id = fam.get_gramps_id()
|
2005-01-05 11:26:33 +05:30
|
|
|
if fam_handle not in families_done:
|
2006-05-02 02:41:26 +05:30
|
|
|
families_done[fam_handle] = 1
|
|
|
|
label = ""
|
2006-03-30 10:45:54 +05:30
|
|
|
for event_ref in fam.get_event_ref_list():
|
2006-05-02 02:41:26 +05:30
|
|
|
event = self.database.get_event_from_handle(
|
|
|
|
event_ref.ref)
|
|
|
|
if int(event.get_type()) == RelLib.EventType.MARRIAGE:
|
|
|
|
label = self.get_event_string(event)
|
|
|
|
break
|
2005-01-05 11:26:33 +05:30
|
|
|
if self.includeid:
|
2006-05-02 02:41:26 +05:30
|
|
|
label = "%s (%s)" % (label, fam_id)
|
|
|
|
color = ""
|
|
|
|
if self.colorize == 'colored':
|
|
|
|
color = ', color="%s"' % self.colors['family']
|
|
|
|
elif self.colorize == 'filled':
|
|
|
|
color = ', fillcolor="%s"' % self.colors['family']
|
|
|
|
buffer += '"f%s" [shape=ellipse, label="%s"%s];\n' % (fam_id, label, color)
|
2005-01-05 11:26:33 +05:30
|
|
|
# Link this person to all his/her families.
|
2006-05-02 02:41:26 +05:30
|
|
|
buffer += '"f%s" -> "p%s";\n' % (fam_id, p_id)
|
|
|
|
return buffer
|
|
|
|
|
|
|
|
def get_gender_style(self, person):
|
|
|
|
"return gender specific person style"
|
|
|
|
gender = person.get_gender()
|
|
|
|
if gender == person.MALE:
|
|
|
|
shape = 'shape="box"'
|
|
|
|
elif gender == person.FEMALE:
|
|
|
|
shape = 'shape="box", style="rounded"'
|
|
|
|
else:
|
|
|
|
shape = 'shape="hexagon"'
|
|
|
|
if self.colorize == 'outline':
|
|
|
|
return shape
|
|
|
|
else:
|
|
|
|
if gender == person.MALE:
|
|
|
|
color = self.colors['male']
|
|
|
|
elif gender == person.FEMALE:
|
|
|
|
color = self.colors['female']
|
|
|
|
else:
|
|
|
|
color = self.colors['unknown']
|
|
|
|
if self.colorize == 'filled':
|
|
|
|
# In current GraphViz boxes cannot be both rounded and filled
|
|
|
|
return 'shape="box", fillcolor="%s"' % color
|
|
|
|
else:
|
|
|
|
return '%s, color="%s"' % (shape, color)
|
|
|
|
|
|
|
|
def get_person_label(self, person):
|
|
|
|
"return person label string"
|
2007-08-16 17:39:49 +05:30
|
|
|
# see if we have an image to use for this person
|
|
|
|
imagePath = None
|
|
|
|
if self.bUseHtmlOutput:
|
|
|
|
mediaList = person.get_media_list()
|
|
|
|
if len(mediaList) > 0:
|
|
|
|
mediaHandle = mediaList[0].get_reference_handle()
|
|
|
|
media = self.database.get_object_from_handle(mediaHandle)
|
|
|
|
mediaMimeType = media.get_mime_type()
|
|
|
|
if mediaMimeType[0:5] == "image":
|
|
|
|
imagePath = os.path.abspath(ImgManip.get_thumbnail_path(media.get_path()))
|
|
|
|
#test if thumbnail actually exists in thumbs (import of data means media files might not be present
|
|
|
|
imagePath = Utils.find_file(imagePath)
|
|
|
|
|
|
|
|
label = u""
|
|
|
|
lineDelimiter = '\\n'
|
|
|
|
|
|
|
|
# if we have an image, then start an HTML table; remember to close the table afterwards!
|
|
|
|
if self.bUseHtmlOutput and imagePath:
|
|
|
|
lineDelimiter = '<BR/>'
|
|
|
|
label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" CELLBORDER="0"><TR><TD></TD><TD><IMG SRC="%s"/></TD><TD></TD>' % imagePath
|
|
|
|
if self.imgpos == 0:
|
|
|
|
#trick it into not stretching the image
|
|
|
|
label += '</TR><TR><TD COLSPAN="3">'
|
|
|
|
else :
|
|
|
|
label += '<TD>'
|
|
|
|
else :
|
|
|
|
#no need for html label with this person
|
|
|
|
self.bUseHtmlOutput = False
|
|
|
|
|
|
|
|
# at the very least, the label must have the person's name
|
|
|
|
nm = name_displayer.display_name(person.get_primary_name())
|
|
|
|
if self.bUseHtmlOutput :
|
|
|
|
# avoid < and > in the name, as this is html text
|
|
|
|
label += nm.replace('<','<').replace('>','>')
|
|
|
|
else :
|
|
|
|
label += nm
|
2006-05-02 02:41:26 +05:30
|
|
|
p_id = person.get_gramps_id()
|
|
|
|
if self.includeid:
|
2007-08-16 17:39:49 +05:30
|
|
|
label += " (%s)" % p_id
|
2006-05-02 02:41:26 +05:30
|
|
|
if self.includedates:
|
|
|
|
birth, death = self.get_date_strings(person)
|
2007-08-16 17:39:49 +05:30
|
|
|
label = label + '%s(%s - %s)' % (lineDelimiter,birth, death)
|
|
|
|
|
|
|
|
# see if we have a table that needs to be terminated
|
|
|
|
if self.bUseHtmlOutput:
|
|
|
|
label += '</TD></TR></TABLE>'
|
|
|
|
return label
|
|
|
|
else :
|
|
|
|
# non html label is enclosed by "" so excape other "
|
|
|
|
return label.replace('"', '\\\"')
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
def get_date_strings(self, person):
|
|
|
|
"returns tuple of birth/christening and death/burying date strings"
|
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth_event = self.database.get_event_from_handle(birth_ref.ref)
|
|
|
|
birth = self.get_event_string(birth_event)
|
|
|
|
else:
|
|
|
|
birth = ''
|
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
2006-07-24 11:03:55 +05:30
|
|
|
death_event = self.database.get_event_from_handle(death_ref.ref)
|
2006-05-02 02:41:26 +05:30
|
|
|
death = self.get_event_string(death_event)
|
|
|
|
else:
|
|
|
|
death = ''
|
|
|
|
if birth and death:
|
|
|
|
return (birth, death)
|
|
|
|
# missing info, use (first) christening/burial instead
|
2006-11-22 10:13:33 +05:30
|
|
|
for event_ref in person.get_primary_event_ref_list():
|
2006-05-02 02:41:26 +05:30
|
|
|
event = self.database.get_event_from_handle(event_ref.ref)
|
|
|
|
if int(event.get_type()) == RelLib.EventType.CHRISTEN:
|
|
|
|
if not birth:
|
|
|
|
birth = self.get_event_string(event)
|
|
|
|
elif int(event.get_type()) == RelLib.EventType.BURIAL:
|
|
|
|
if not death:
|
|
|
|
death = self.get_event_string(event)
|
|
|
|
return (birth, death)
|
|
|
|
|
|
|
|
def get_event_string(self, event):
|
2005-01-15 11:21:48 +05:30
|
|
|
"""
|
2006-05-02 02:41:26 +05:30
|
|
|
return string for for an event label.
|
2005-01-15 11:21:48 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
2006-05-22 02:09:14 +05:30
|
|
|
if event:
|
|
|
|
if event.get_date_object().get_year_valid():
|
|
|
|
if self.just_years:
|
|
|
|
return '%i' % event.get_date_object().get_year()
|
|
|
|
else:
|
|
|
|
return DateHandler.get_date(event)
|
|
|
|
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:
|
2006-08-27 12:00:56 +05:30
|
|
|
return '' #event.get_cause()
|
2005-01-15 11:21:48 +05:30
|
|
|
return ''
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 11:26:33 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Options class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class GraphVizOptions(ReportOptions):
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
2006-06-01 10:09:40 +05:30
|
|
|
ReportOptions.__init__(self,name,person_id)
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
def set_new_options(self):
|
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
2007-03-26 02:05:33 +05:30
|
|
|
'filter' : 0,
|
2005-01-19 02:30:58 +05:30
|
|
|
'font' : "",
|
2007-01-14 09:39:44 +05:30
|
|
|
'fontsize' : 14,
|
2005-01-19 02:30:58 +05:30
|
|
|
'latin' : 1,
|
|
|
|
'arrow' : 'd',
|
|
|
|
'showfamily' : 1,
|
|
|
|
'incdate' : 1,
|
|
|
|
'incid' : 0,
|
|
|
|
'justyears' : 0,
|
|
|
|
'placecause' : 1,
|
|
|
|
'url' : 1,
|
2006-05-02 02:41:26 +05:30
|
|
|
'ratio' : "compress",
|
2005-01-19 02:30:58 +05:30
|
|
|
'rankdir' : "LR",
|
|
|
|
'color' : "filled",
|
|
|
|
'dashedl' : 1,
|
2005-08-18 11:28:28 +05:30
|
|
|
'margin' : 1.0,
|
2006-05-02 02:41:26 +05:30
|
|
|
'pagedir' : 'BL',
|
2005-01-19 02:30:58 +05:30
|
|
|
'pagesh' : 1,
|
|
|
|
'pagesv' : 1,
|
2006-05-02 02:41:26 +05:30
|
|
|
'note' : '',
|
|
|
|
'noteloc' : 'b',
|
|
|
|
'notesize' : 32,
|
2005-01-19 02:30:58 +05:30
|
|
|
'gvof' : 'ps',
|
2007-08-16 17:39:49 +05:30
|
|
|
'includeImages' : 1,
|
|
|
|
'imageOnTheSide' : 1,
|
2005-01-05 11:26:33 +05:30
|
|
|
}
|
2007-03-26 02:05:33 +05:30
|
|
|
filters = ReportUtils.get_person_filters(None,include_single=False)
|
2005-01-05 11:26:33 +05:30
|
|
|
self.options_help = {
|
2007-03-26 02:05:33 +05:30
|
|
|
'filter' : ("=num","Filter number.",
|
|
|
|
[ filt.get_name() for filt in filters ],
|
|
|
|
True ),
|
2005-01-05 11:26:33 +05:30
|
|
|
'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),
|
2007-01-14 09:39:44 +05:30
|
|
|
'fontsize' : ("=num","Font size (in points).",
|
|
|
|
"Integer values"),
|
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),
|
2006-05-02 02:41:26 +05:30
|
|
|
'ratio' : ("=str","Graph aspect ratio.",
|
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.ratio ],
|
|
|
|
False),
|
|
|
|
'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"),
|
2006-05-02 02:41:26 +05:30
|
|
|
'pagedir' : ("=str","Paging direction.",
|
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.pagedir ],
|
|
|
|
False),
|
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"),
|
2006-05-02 02:41:26 +05:30
|
|
|
'note' : ("=str","Note to add to the graph.",
|
|
|
|
"Text"),
|
|
|
|
'notesize' : ("=num","Note size (in points).",
|
|
|
|
"Integer values"),
|
|
|
|
'noteloc' : ("=str","Note location.",
|
|
|
|
[ "%s\t%s" % (item[0],item[1]) for item in _options.noteloc ],
|
|
|
|
False),
|
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),
|
2007-08-16 17:39:49 +05:30
|
|
|
'includeImages' : ("=0/1","Whether to include the default person image.",
|
|
|
|
["Do not include image","include image"],
|
|
|
|
True),
|
|
|
|
'imageOnTheSide' : ("=0/1","Where to put the image if present.",
|
|
|
|
["Image above the name","Image besides the name"],
|
|
|
|
True),
|
|
|
|
|
2005-01-05 11:26:33 +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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
def add_list(self, options, default):
|
|
|
|
"returns compobox of given options and default value"
|
|
|
|
box = gtk.ComboBox()
|
|
|
|
store = gtk.ListStore(str)
|
|
|
|
box.set_model(store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
box.pack_start(cell,True)
|
|
|
|
box.add_attribute(cell,'text',0)
|
|
|
|
index = 0
|
|
|
|
for item in options:
|
|
|
|
store.append(row=[item[2]])
|
|
|
|
if item[0] == default:
|
|
|
|
box.set_active(index)
|
|
|
|
index = index + 1
|
|
|
|
return box
|
|
|
|
|
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'])
|
2007-03-26 02:05:33 +05:30
|
|
|
|
|
|
|
filter_index = self.options_dict['filter']
|
|
|
|
filter_list = ReportUtils.get_person_filters(dialog.person,include_single=False)
|
|
|
|
self.filter_menu = gtk.combo_box_new_text()
|
|
|
|
for filter in filter_list:
|
|
|
|
self.filter_menu.append_text(filter.get_name())
|
|
|
|
if filter_index > len(filter_list):
|
|
|
|
filter_index = 0
|
|
|
|
self.filter_menu.set_active(filter_index)
|
|
|
|
dialog.add_option('Filter',self.filter_menu)
|
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."))
|
2007-08-16 17:39:49 +05:30
|
|
|
|
|
|
|
self.includeimg_cb = gtk.CheckButton(_('Include thumbnail images of people'))
|
|
|
|
self.includeimg_cb.set_active(self.options_dict['includeImages'])
|
|
|
|
dialog.add_option(None, self.includeimg_cb,
|
|
|
|
_("Whether to include thumbnails of people."))
|
|
|
|
|
|
|
|
self.imageLocation = gtk.combo_box_new_text()
|
|
|
|
self.imageLocation.append_text(_('place the thumbnail image above the name'))
|
|
|
|
self.imageLocation.append_text(_('place the thumbnail image beside the name'))
|
|
|
|
self.imageLocation.set_active(self.options_dict['imageOnTheSide'])
|
|
|
|
dialog.add_option(None, self.imageLocation)
|
2005-01-19 02:30:58 +05:30
|
|
|
|
|
|
|
# GraphViz output options tab
|
2006-05-02 02:41:26 +05:30
|
|
|
self.color_box = self.add_list(_options.colors,
|
|
|
|
self.options_dict['color'])
|
2005-01-19 02:30:58 +05:30
|
|
|
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."))
|
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
self.arrowstyle_box = self.add_list(_options.arrowstyles,
|
|
|
|
self.options_dict['arrow'])
|
2005-01-05 11:26:33 +05:30
|
|
|
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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
self.font_box = self.add_list(_options.fonts,
|
|
|
|
self.options_dict['font'])
|
2005-01-05 11:26:33 +05:30
|
|
|
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/"))
|
2007-01-14 09:39:44 +05:30
|
|
|
|
|
|
|
fontsize_adj = gtk.Adjustment(value=self.options_dict['fontsize'],
|
|
|
|
lower=8, upper=128, step_incr=1)
|
|
|
|
self.fontsize_sb = gtk.SpinButton(adjustment=fontsize_adj, digits=0)
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"),
|
|
|
|
_("Font size (in points)"),
|
|
|
|
self.fontsize_sb,
|
|
|
|
_("The font size, in points."))
|
2003-08-21 09:17:35 +05:30
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
self.latin_cb = gtk.CheckButton(_("Output format/font requires text as latin-1"))
|
|
|
|
self.latin_cb.set_active(self.options_dict['latin'])
|
|
|
|
dialog.add_frame_option(_("GraphViz Options"), '',
|
|
|
|
self.latin_cb,
|
|
|
|
_("If text doesn't show correctly in report, use this. "
|
2007-06-13 17:23:06 +05:30
|
|
|
"Required e.g. for default font with PS output. "
|
|
|
|
"Not typically required for SVG or JPG output."))
|
2006-05-02 02:41:26 +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."))
|
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
# Page/layout options tab
|
|
|
|
self.rank_box = self.add_list(_options.rankdir,
|
|
|
|
self.options_dict['rankdir'])
|
|
|
|
dialog.add_frame_option(_("Layout Options"),
|
|
|
|
_("Graph direction"),
|
|
|
|
self.rank_box,
|
|
|
|
_("Whether generations go from top to bottom "
|
|
|
|
"or left to right."))
|
|
|
|
|
|
|
|
self.ratio_box = self.add_list(_options.ratio,
|
|
|
|
self.options_dict['ratio'])
|
|
|
|
dialog.add_frame_option(_("Layout Options"),
|
|
|
|
_("Aspect ratio"),
|
|
|
|
self.ratio_box,
|
|
|
|
_("Affects greatly how the graph is layed out "
|
|
|
|
"on the page. Multiple pages overrides the "
|
|
|
|
"pages settings below."))
|
|
|
|
|
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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
dialog.add_frame_option(_("Layout 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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
dialog.add_frame_option(_("Layout 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."))
|
2006-05-02 02:41:26 +05:30
|
|
|
dialog.add_frame_option(_("Layout 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."))
|
2006-05-02 02:41:26 +05:30
|
|
|
self.pagedir_box = self.add_list(_options.pagedir,
|
|
|
|
self.options_dict['pagedir'])
|
|
|
|
dialog.add_frame_option(_("Layout Options"),
|
|
|
|
_("Paging direction"),
|
|
|
|
self.pagedir_box,
|
|
|
|
_("The order in which the graph pages are output."))
|
|
|
|
|
|
|
|
# Notes tab
|
|
|
|
self.textbox = gtk.TextView()
|
|
|
|
self.textbox.get_buffer().set_text(self.options_dict['note'])
|
|
|
|
self.textbox.set_editable(1)
|
|
|
|
swin = gtk.ScrolledWindow()
|
|
|
|
swin.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
swin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
|
|
|
swin.add(self.textbox)
|
|
|
|
dialog.add_frame_option(_("Notes"),
|
|
|
|
_("Note to add to the graph"),
|
|
|
|
swin,
|
|
|
|
_("This text will be added to the graph."))
|
|
|
|
self.noteloc_box = self.add_list(_options.noteloc,
|
|
|
|
self.options_dict['noteloc'])
|
|
|
|
dialog.add_frame_option(_("Notes"),
|
|
|
|
_("Note location"),
|
|
|
|
self.noteloc_box,
|
|
|
|
_("Whether note will appear on top "
|
|
|
|
"or bottom of the page."))
|
|
|
|
|
2007-08-16 17:39:49 +05:30
|
|
|
notesize_adj = gtk.Adjustment(value=self.options_dict['notesize'], lower=8, upper=128, step_incr=1)
|
2006-05-02 02:41:26 +05:30
|
|
|
self.notesize_sb = gtk.SpinButton(adjustment=notesize_adj, digits=0)
|
|
|
|
dialog.add_frame_option(_("Notes"),
|
|
|
|
_("Note size (in points)"),
|
|
|
|
self.notesize_sb,
|
|
|
|
_("The size of note text, in points."))
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
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):
|
2007-03-26 02:05:33 +05:30
|
|
|
self.options_dict['filter'] = int(self.filter_menu.get_active())
|
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())
|
2007-01-14 09:39:44 +05:30
|
|
|
self.options_dict['fontsize'] = self.fontsize_sb.get_value_as_int()
|
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())
|
2006-05-22 07:25:15 +05:30
|
|
|
self.options_dict['latin'] = int(self.latin_cb.get_active())
|
2006-05-02 02:41:26 +05:30
|
|
|
self.options_dict['ratio'] = \
|
|
|
|
_options.ratio[self.ratio_box.get_active()][0]
|
2005-01-19 02:30:58 +05:30
|
|
|
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]
|
2006-05-02 02:41:26 +05:30
|
|
|
self.options_dict['pagedir'] = \
|
|
|
|
_options.pagedir[self.pagedir_box.get_active()][0]
|
|
|
|
self.options_dict['noteloc'] = \
|
|
|
|
_options.noteloc[self.noteloc_box.get_active()][0]
|
|
|
|
self.options_dict['notesize'] = self.notesize_sb.get_value_as_int()
|
|
|
|
b = self.textbox.get_buffer()
|
|
|
|
self.options_dict['note'] = \
|
|
|
|
b.get_text(b.get_start_iter(), b.get_end_iter(), False)
|
|
|
|
|
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()
|
2007-08-16 17:39:49 +05:30
|
|
|
|
|
|
|
self.options_dict['includeImages' ] = int(self.includeimg_cb.get_active() )
|
|
|
|
self.options_dict['imageOnTheSide' ] = int(self.imageLocation.get_active() )
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Dialog class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class GraphVizDialog(ReportDialog):
|
2005-01-05 11:26:33 +05:30
|
|
|
|
2006-06-02 06:10:54 +05:30
|
|
|
def __init__(self,dbstate,uistate,person):
|
|
|
|
self.database = dbstate.db
|
2005-01-05 11:26:33 +05:30
|
|
|
self.person = person
|
|
|
|
name = "rel_graph"
|
|
|
|
translated_name = _("Relationship Graph")
|
|
|
|
self.options_class = GraphVizOptions(name)
|
2006-06-01 10:09:40 +05:30
|
|
|
self.category = CATEGORY_CODE
|
2006-06-02 06:10:54 +05:30
|
|
|
ReportDialog.__init__(self,dbstate,uistate,person,self.options_class,
|
|
|
|
name,translated_name)
|
2005-01-05 11:26:33 +05:30
|
|
|
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))
|
2006-06-25 07:56:29 +05:30
|
|
|
elif response == gtk.RESPONSE_DELETE_EVENT:
|
|
|
|
return
|
2006-06-02 06:10:54 +05:30
|
|
|
self.close()
|
2005-01-05 11:26:33 +05:30
|
|
|
|
|
|
|
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):
|
2006-05-02 02:41:26 +05:30
|
|
|
_apptype = _options.formats[self.get_active()][3]
|
|
|
|
print_label = None
|
|
|
|
try:
|
2006-06-13 07:38:11 +05:30
|
|
|
mprog = Mime.get_application(_apptype)
|
2006-05-02 02:41:26 +05:30
|
|
|
|
|
|
|
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
|
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:
|
2006-06-13 07:38:11 +05:30
|
|
|
mprog = Mime.get_application(_apptype)
|
2006-04-13 08:31:12 +05:30
|
|
|
if Utils.search_for(mprog[0]):
|
|
|
|
print_label = _("Open in %(program_name)s") % { 'program_name':
|
2006-07-22 11:22:16 +05:30
|
|
|
mprog[1] }
|
2006-04-13 08:31:12 +05:30
|
|
|
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:
|
2007-03-06 09:36:04 +05:30
|
|
|
def __init__(self,styles,type,template,source=None):
|
2006-04-13 08:31:12 +05:30
|
|
|
self.print_req = 0
|
2005-01-12 06:18:42 +05:30
|
|
|
|
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-06-01 10:09:40 +05:30
|
|
|
clr = CommandLineReport(database,name,category,GraphVizOptions,
|
2006-03-05 10:01:24 +05:30
|
|
|
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
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class GraphVizGraphics(Report):
|
2005-01-12 06:18:42 +05:30
|
|
|
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()
|
2007-01-15 03:39:14 +05:30
|
|
|
(handle,self.junk_output) = tempfile.mkstemp(".dot", "rel_graph" )
|
|
|
|
os.close( handle )
|
|
|
|
|
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):
|
2007-08-16 17:39:49 +05:30
|
|
|
if self.the_format == "pdf":
|
2007-01-15 03:39:14 +05:30
|
|
|
# Create a temporary Postscript file
|
|
|
|
(handle,tmp_ps) = tempfile.mkstemp(".ps", "rel_graph" )
|
|
|
|
os.close( handle )
|
|
|
|
|
|
|
|
# Generate Postscript using dot
|
|
|
|
command = 'dot -Tps -o"%s" "%s"' % ( tmp_ps, self.junk_output )
|
|
|
|
os.system(command)
|
|
|
|
|
|
|
|
paper = self.options_class.handler.get_paper()
|
|
|
|
# Add .5 to remove rounding errors.
|
|
|
|
width_pt = int( (paper.get_width_inches() * 72) + 0.5 )
|
|
|
|
height_pt = int( (paper.get_height_inches() * 72) + 0.5 )
|
|
|
|
|
|
|
|
# Convert to PDF using ghostscript
|
|
|
|
command = '%s -q -sDEVICE=pdfwrite -dNOPAUSE -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d -sOutputFile="%s" "%s" -c quit' \
|
|
|
|
% ( gs_cmd, width_pt, height_pt, self.user_output, tmp_ps )
|
|
|
|
os.system(command)
|
|
|
|
|
|
|
|
os.remove(tmp_ps)
|
|
|
|
|
|
|
|
else:
|
|
|
|
os.system('dot -T%s -o"%s" "%s"' %
|
|
|
|
(self.the_format,self.user_output,self.junk_output) )
|
|
|
|
|
|
|
|
os.remove(self.junk_output)
|
2005-01-12 06:18:42 +05:30
|
|
|
|
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:
|
2006-06-13 07:38:11 +05:30
|
|
|
app = Mime.get_application(_apptype)
|
2006-07-22 11:22:16 +05:30
|
|
|
Utils.launch(app[0],self.user_output)
|
2006-04-13 08:31:12 +05:30
|
|
|
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',
|
2006-06-01 10:09:40 +05:30
|
|
|
category = CATEGORY_CODE,
|
2005-01-05 11:26:33 +05:30
|
|
|
report_class = GraphVizDialog,
|
|
|
|
options_class = cl_report,
|
2006-06-01 10:09:40 +05:30
|
|
|
modes = MODE_GUI | MODE_CLI,
|
2005-01-05 11:26:33 +05:30
|
|
|
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
|
|
|
|
2006-05-02 02:41:26 +05:30
|
|
|
if _dot_found:
|
2005-01-12 06:18:42 +05:30
|
|
|
register_report(
|
|
|
|
name = 'rel_graph2',
|
2006-06-01 10:09:40 +05:30
|
|
|
category = CATEGORY_DRAW,
|
2005-01-12 06:18:42 +05:30
|
|
|
report_class = GraphVizGraphics,
|
|
|
|
options_class = GraphVizOptions,
|
2006-06-01 10:09:40 +05:30
|
|
|
modes = MODE_GUI | MODE_CLI,
|
2005-01-12 06:18:42 +05:30
|
|
|
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
|
|
|
)
|