2007-09-30 10:26:56 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-18 11:09:50 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2008-05-24 14:29:32 +05:30
|
|
|
# Copyright (C) 2007-2008 Stephane Charette
|
2007-09-30 10:26:56 +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
|
|
|
|
#
|
2007-12-23 13:22:01 +05:30
|
|
|
# $Id$
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
from cStringIO import StringIO
|
|
|
|
import tempfile
|
2007-12-16 09:21:02 +05:30
|
|
|
from types import ClassType, InstanceType
|
2008-01-18 11:09:50 +05:30
|
|
|
from gettext import gettext as _
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK+ modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
import Mime
|
|
|
|
import Utils
|
|
|
|
import BaseDoc
|
|
|
|
import Config
|
2008-04-23 10:12:08 +05:30
|
|
|
from ReportBase import CATEGORY_GRAPHVIZ
|
2007-09-30 10:26:56 +05:30
|
|
|
from _ReportDialog import ReportDialog
|
2008-03-10 01:09:56 +05:30
|
|
|
from _FileEntry import FileEntry
|
2007-12-13 07:22:03 +05:30
|
|
|
from _PaperMenu import PaperFrame
|
2008-02-19 01:37:09 +05:30
|
|
|
from PluginUtils import NumberOption, EnumeratedListOption, TextOption
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Private Contstants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
2007-12-28 03:17:11 +05:30
|
|
|
_FONTS = [ { 'name' : _("Default"), 'value' : "" },
|
2008-04-16 01:13:54 +05:30
|
|
|
{ 'name' : _("PostScript / Helvetica"), 'value' : "Helvetica" },
|
|
|
|
{ 'name' : _("TrueType / FreeSans"), 'value' : "FreeSans" } ]
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2007-12-25 07:27:45 +05:30
|
|
|
_RANKDIR = [ { 'name' : _("Vertical (top to bottom)"), 'value' : "TB" },
|
|
|
|
{ 'name' : _("Vertical (bottom to top)"), 'value' : "BT" },
|
|
|
|
{ 'name' : _("Horizontal (left to right)"), 'value' : "LR" },
|
|
|
|
{ 'name' : _("Horizontal (right to left)"), 'value' : "RL" } ]
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2007-12-25 07:27:45 +05:30
|
|
|
_PAGEDIR = [ { 'name' : _("Bottom, left"), 'value' :"BL" },
|
|
|
|
{ 'name' : _("Bottom, right"), 'value' :"BR" },
|
|
|
|
{ 'name' : _("Top, left"), 'value' :"TL" },
|
|
|
|
{ 'name' : _("Top, Right"), 'value' :"TR" },
|
|
|
|
{ 'name' : _("Right, bottom"), 'value' :"RB" },
|
|
|
|
{ 'name' : _("Right, top"), 'value' :"RT" },
|
|
|
|
{ 'name' : _("Left, bottom"), 'value' :"LB" },
|
|
|
|
{ 'name' : _("Left, top"), 'value' :"LT" } ]
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_RATIO = [ { 'name' : _("Minimal size"), 'value': "compress" },
|
2007-12-28 03:17:11 +05:30
|
|
|
{ 'name' : _("Fill the given area"), 'value': "fill" },
|
|
|
|
{ 'name' : _("Use optimal number of pages"), 'value': "expand" } ]
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
_NOTELOC = [ { 'name' : _("Top"), 'value' : "t" },
|
|
|
|
{ 'name' : _("Bottom"), 'value' : "b" }]
|
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
if os.sys.platform == "win32":
|
2008-04-23 08:55:41 +05:30
|
|
|
_DOT_FOUND = Utils.search_for("dot.exe")
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
if Utils.search_for("gswin32c.exe") == 1:
|
2008-04-23 08:55:41 +05:30
|
|
|
_GS_CMD = "gswin32c.exe"
|
2007-09-30 10:26:56 +05:30
|
|
|
elif Utils.search_for("gswin32.exe") == 1:
|
2008-04-23 08:55:41 +05:30
|
|
|
_GS_CMD = "gswin32.exe"
|
|
|
|
else:
|
|
|
|
_GS_CMD = ""
|
2007-09-30 10:26:56 +05:30
|
|
|
else:
|
2008-04-23 08:55:41 +05:30
|
|
|
_DOT_FOUND = Utils.search_for("dot")
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
if Utils.search_for("gs") == 1:
|
2008-04-23 08:55:41 +05:30
|
|
|
_GS_CMD = "gs"
|
|
|
|
else:
|
|
|
|
_GS_CMD = ""
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVDocBase
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
2008-04-23 08:55:41 +05:30
|
|
|
class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
2007-12-28 15:38:19 +05:30
|
|
|
Base document generator for all Graphiz document generators. Classes that
|
2007-09-30 10:26:56 +05:30
|
|
|
inherit from this class will only need to implement the close function.
|
|
|
|
The close function will generate the actual file of the appropriate type.
|
|
|
|
"""
|
2008-03-20 08:48:35 +05:30
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
BaseDoc.BaseDoc.__init__(self, None, paper_style, None)
|
2007-12-23 13:22:01 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
self._filename = None
|
|
|
|
self._dot = StringIO()
|
|
|
|
self._paper = paper_style
|
|
|
|
|
|
|
|
menu = options.menu
|
|
|
|
|
|
|
|
self.dpi = menu.get_option_by_name('dpi').get_value()
|
|
|
|
self.fontfamily = menu.get_option_by_name('font_family').get_value()
|
|
|
|
self.fontsize = menu.get_option_by_name('font_size').get_value()
|
|
|
|
self.hpages = menu.get_option_by_name('h_pages').get_value()
|
|
|
|
self.nodesep = menu.get_option_by_name('nodesep').get_value()
|
|
|
|
self.noteloc = menu.get_option_by_name('noteloc').get_value()
|
|
|
|
self.notesize = menu.get_option_by_name('notesize').get_value()
|
|
|
|
self.note = menu.get_option_by_name('note').get_value()
|
|
|
|
self.pagedir = menu.get_option_by_name('page_dir').get_value()
|
|
|
|
self.rankdir = menu.get_option_by_name('rank_dir').get_value()
|
|
|
|
self.ranksep = menu.get_option_by_name('ranksep').get_value()
|
|
|
|
self.ratio = menu.get_option_by_name('ratio').get_value()
|
|
|
|
self.vpages = menu.get_option_by_name('v_pages').get_value()
|
2007-12-23 13:22:01 +05:30
|
|
|
|
|
|
|
paper_size = paper_style.get_size()
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Subtract 0.01" from the drawing area to make some room between
|
|
|
|
# this area and the margin in order to compensate for different
|
|
|
|
# rounding errors internally in dot
|
2008-03-20 08:48:35 +05:30
|
|
|
sizew = ( paper_size.get_width() -
|
2008-04-23 10:12:08 +05:30
|
|
|
self._paper.get_left_margin() -
|
2008-05-13 14:09:27 +05:30
|
|
|
self._paper.get_right_margin() ) / 2.54 - 0.01
|
2008-03-20 08:48:35 +05:30
|
|
|
sizeh = ( paper_size.get_height() -
|
2008-04-23 10:12:08 +05:30
|
|
|
self._paper.get_top_margin() -
|
2008-05-13 14:09:27 +05:30
|
|
|
self._paper.get_bottom_margin() ) / 2.54 - 0.01
|
2008-03-20 08:48:35 +05:30
|
|
|
|
|
|
|
pheight = paper_size.get_height_inches()
|
|
|
|
pwidth = paper_size.get_width_inches()
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
xmargin = self._paper.get_left_margin() / 2.54
|
|
|
|
ymargin = self._paper.get_top_margin() / 2.54
|
2008-03-20 08:48:35 +05:30
|
|
|
|
2007-12-16 09:21:02 +05:30
|
|
|
sizew = sizew * self.hpages
|
|
|
|
sizeh = sizeh * self.vpages
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( 'digraph GRAMPS_graph\n' )
|
|
|
|
self.write( '{\n' )
|
|
|
|
self.write( ' bgcolor=white;\n' )
|
|
|
|
self.write( ' center="true"; \n' )
|
|
|
|
self.write( ' charset="iso-8859-1";\n' )
|
|
|
|
self.write( ' concentrate="false";\n' )
|
|
|
|
self.write( ' dpi="%d";\n' % self.dpi )
|
|
|
|
self.write( ' graph [fontsize=%d];\n' % self.fontsize )
|
2008-05-06 11:07:00 +05:30
|
|
|
self.write( ' margin="%3.2f,%3.2f"; \n' % (xmargin, ymargin))
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( ' mclimit="99";\n' )
|
|
|
|
self.write( ' nodesep="%.2f";\n' % self.nodesep )
|
|
|
|
self.write( ' outputorder="edgesfirst";\n' )
|
2008-05-11 11:06:34 +05:30
|
|
|
self.write( ' page="%3.2f,%3.2f";\n' % (pwidth, pheight) )
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( ' pagedir="%s";\n' % self.pagedir )
|
|
|
|
self.write( ' rankdir="%s";\n' % self.rankdir )
|
|
|
|
self.write( ' ranksep="%.2f";\n' % self.ranksep )
|
|
|
|
self.write( ' ratio="%s";\n' % self.ratio )
|
|
|
|
self.write( ' searchsize="100";\n' )
|
|
|
|
self.write( ' size="%3.2f,%3.2f"; \n' % (sizew, sizeh) )
|
|
|
|
self.write( ' splines="true";\n' )
|
|
|
|
self.write( '\n' )
|
|
|
|
self.write( ' edge [len=0.5 style=solid arrowhead=none '
|
2007-12-28 15:38:19 +05:30
|
|
|
'arrowtail=normal fontsize=%d];\n' % self.fontsize )
|
2007-12-25 10:57:27 +05:30
|
|
|
if self.fontfamily:
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( ' node [style=filled fontname="%s" fontsize=%d];\n'
|
2007-12-25 10:57:27 +05:30
|
|
|
% ( self.fontfamily, self.fontsize ) )
|
|
|
|
else:
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( ' node [style=filled fontsize=%d];\n'
|
2007-12-25 10:57:27 +05:30
|
|
|
% self.fontsize )
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write( '\n' )
|
|
|
|
|
|
|
|
def write(self, text):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Write text to the dot file """
|
|
|
|
self._dot.write(text.encode('iso-8859-1', 'xmlcharrefreplace'))
|
2007-12-23 13:22:01 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def open(self, filename):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implement BaseDoc.BaseDoc.open() """
|
|
|
|
self._filename = os.path.normpath(os.path.abspath(filename))
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def close(self):
|
|
|
|
"""
|
|
|
|
This isn't useful by itself. Other classes need to override this and
|
|
|
|
actually generate a file.
|
|
|
|
"""
|
2007-12-20 11:56:38 +05:30
|
|
|
if self.note:
|
2008-05-24 14:29:32 +05:30
|
|
|
# build up the label
|
|
|
|
label = u''
|
|
|
|
for line in self.note: # for every line in the note...
|
|
|
|
line = line.strip() # ...strip whitespace from this line...
|
|
|
|
if line != '': # ...and if we still have a line...
|
|
|
|
if label != '': # ...see if we need to insert a newline...
|
|
|
|
label += '\\n'
|
|
|
|
label += line.replace('"', '\\\"')
|
|
|
|
|
|
|
|
# after all that, see if we have a label to display
|
|
|
|
if label != '':
|
|
|
|
self.write( '\n')
|
|
|
|
self.write( ' label="%s";\n' % label )
|
|
|
|
self.write( ' labelloc="%s";\n' % self.noteloc )
|
|
|
|
self.write( ' fontsize="%d";\n' % self.notesize )
|
|
|
|
|
|
|
|
self.write( '}\n\n' )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
def add_node(self, node_id, label, shape="", color="",
|
|
|
|
style="", fillcolor="", url="", htmloutput=False):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a node to this graph. Nodes can be different shapes like boxes and
|
|
|
|
circles.
|
|
|
|
|
2007-12-31 11:13:14 +05:30
|
|
|
Implements BaseDoc.GVDoc.add_node().
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
2007-12-31 11:13:14 +05:30
|
|
|
text = '['
|
|
|
|
|
2007-12-20 11:56:38 +05:30
|
|
|
if shape:
|
2007-12-31 11:13:14 +05:30
|
|
|
text += ' shape="%s"' % shape
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
if color:
|
2007-12-31 11:13:14 +05:30
|
|
|
text += ' color="%s"' % color
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
if fillcolor:
|
2007-12-31 11:13:14 +05:30
|
|
|
text += ' fillcolor="%s"' % fillcolor
|
|
|
|
|
2007-12-20 11:56:38 +05:30
|
|
|
if style:
|
2007-12-31 11:13:14 +05:30
|
|
|
text += ' style="%s"' % style
|
|
|
|
|
|
|
|
# note that we always output a label -- even if an empty string --
|
|
|
|
# otherwise GraphViz uses the node ID as the label which is unlikely
|
|
|
|
# to be what the user wants to see in the graph
|
|
|
|
if label.startswith("<") or htmloutput:
|
|
|
|
text += ' label=<%s>' % label
|
|
|
|
else:
|
|
|
|
text += ' label="%s"' % label
|
|
|
|
|
2007-12-16 09:21:02 +05:30
|
|
|
if url:
|
2007-12-31 11:13:14 +05:30
|
|
|
text += ' URL="%s"' % url
|
2007-12-20 11:56:38 +05:30
|
|
|
|
2007-12-31 11:13:14 +05:30
|
|
|
text += " ]"
|
2008-04-23 10:12:08 +05:30
|
|
|
self.write(' %s %s;\n' % (node_id, text))
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2007-12-31 11:13:14 +05:30
|
|
|
def add_link(self, id1, id2, style="", head="", tail="", comment=""):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a link between two nodes.
|
|
|
|
|
|
|
|
Implementes BaseDoc.GVDoc.add_link().
|
|
|
|
"""
|
2007-12-31 11:13:14 +05:30
|
|
|
self.write(' %s -> %s' % (id1, id2))
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
if style or head or tail:
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write(' [')
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
if style:
|
2007-12-31 11:13:14 +05:30
|
|
|
self.write(' style=%s' % style)
|
2007-12-20 11:56:38 +05:30
|
|
|
if head:
|
2007-12-31 11:13:14 +05:30
|
|
|
self.write(' arrowhead=%s' % head)
|
2007-12-20 11:56:38 +05:30
|
|
|
if tail:
|
2007-12-31 11:13:14 +05:30
|
|
|
self.write(' arrowtail=%s' % tail)
|
2007-12-20 11:56:38 +05:30
|
|
|
|
2007-12-31 11:13:14 +05:30
|
|
|
self.write(' ]')
|
|
|
|
|
|
|
|
self.write(';')
|
|
|
|
|
|
|
|
if comment:
|
|
|
|
self.write(' // %s' % comment)
|
|
|
|
|
|
|
|
self.write('\n')
|
|
|
|
|
2008-01-02 14:13:19 +05:30
|
|
|
def add_comment(self, comment):
|
|
|
|
"""
|
|
|
|
Add a comment.
|
|
|
|
|
|
|
|
Implementes BaseDoc.GVDoc.add_comment().
|
|
|
|
"""
|
|
|
|
tmp = comment.split('\n')
|
|
|
|
for line in tmp:
|
|
|
|
text = line.strip()
|
|
|
|
if text == "":
|
|
|
|
self.write('\n')
|
|
|
|
elif text.startswith('#'):
|
|
|
|
self.write('%s\n' % text)
|
|
|
|
else:
|
|
|
|
self.write('# %s\n' % text)
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
def start_subgraph(self, graph_id):
|
|
|
|
""" Implement BaseDoc.GVDoc.start_subgraph() """
|
|
|
|
self.write(' subgraph cluster_%s\n' % graph_id)
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write(' {\n')
|
2008-05-24 14:29:32 +05:30
|
|
|
self.write(' style="invis";\n') # no border around subgraph (#0002176)
|
2007-12-30 11:11:16 +05:30
|
|
|
|
|
|
|
def end_subgraph(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implement BaseDoc.GVDoc.end_subgraph() """
|
2007-12-31 02:39:55 +05:30
|
|
|
self.write(' }\n')
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVDotDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVDotDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .dot text file. """
|
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 12:22:57 +05:30
|
|
|
GVDocBase.close(self)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".dot":
|
|
|
|
self._filename += ".dot"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile = open(self._filename, "w")
|
|
|
|
dotfile.write(self._dot.getvalue())
|
|
|
|
dotfile.close()
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("text/x-graphviz")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVPsDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVPsDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .ps file using Graphviz. """
|
2008-03-20 08:48:35 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# DPI must always be 72 for PDF.
|
|
|
|
# GV documentation says dpi is only for image formats.
|
2008-05-11 10:35:11 +05:30
|
|
|
options.menu.get_option_by_name('dpi').set_value(72)
|
2008-03-20 08:48:35 +05:30
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-3:] != ".ps":
|
|
|
|
self._filename += ".ps"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
|
|
|
# Generate the PS file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tps2 -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("application/postscript")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVSvgDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVSvgDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .svg file using Graphviz. """
|
2008-05-13 14:09:27 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
2008-04-23 10:12:08 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".svg":
|
|
|
|
self._filename += ".svg"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Generate the SVG file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tsvg -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("image/svg")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVSvgzDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVSvgzDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .svg file using Graphviz. """
|
2008-05-13 14:09:27 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
2008-04-23 10:12:08 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-5:] != ".svgz":
|
|
|
|
self._filename += ".svgz"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Generate the SVGZ file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tsvgz -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("image/svgz")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVPngDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVPngDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .png file using Graphviz. """
|
2008-05-13 14:09:27 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
2008-04-23 10:12:08 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".png":
|
|
|
|
self._filename += ".png"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Generate the PNG file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tpng -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("image/png")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVJpegDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVJpegDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .jpg file using Graphviz. """
|
2008-05-13 14:09:27 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
2008-04-23 10:12:08 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".jpg":
|
|
|
|
self._filename += ".jpg"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Generate the JPEG file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tjpg -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("image/jpeg")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVGifDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVGifDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .gif file using Graphviz. """
|
2008-05-13 14:09:27 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
2008-04-23 10:12:08 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".gif":
|
|
|
|
self._filename += ".gif"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-05-13 14:09:27 +05:30
|
|
|
# Generate the GIF file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tgif -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("image/gif")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-12-28 03:17:11 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVPdfGvDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVPdfGvDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .pdf file using Graphviz. """
|
2008-03-20 08:48:35 +05:30
|
|
|
|
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# DPI must always be 72 for PDF.
|
|
|
|
# GV documentation says dpi is only for image formats.
|
2008-05-11 10:35:11 +05:30
|
|
|
options.menu.get_option_by_name('dpi').set_value(72)
|
2008-05-13 14:09:27 +05:30
|
|
|
# GV documentation allow multiple pages only for ps format,
|
|
|
|
# which also includes pdf via ghostscript.
|
|
|
|
options.menu.get_option_by_name('v_pages').set_value(1)
|
|
|
|
options.menu.get_option_by_name('h_pages').set_value(1)
|
2008-03-20 08:48:35 +05:30
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
|
|
|
|
2007-12-28 03:17:11 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-12-28 03:17:11 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".pdf":
|
|
|
|
self._filename += ".pdf"
|
2007-12-28 03:17:11 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-12-28 03:17:11 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-12-28 03:17:11 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
|
|
|
# Generate the PDF file.
|
2008-04-23 10:12:08 +05:30
|
|
|
os.system( 'dot -Tpdf -o"%s" "%s"' % (self._filename, tmp_dot) )
|
2007-12-28 03:17:11 +05:30
|
|
|
|
|
|
|
# Delete the temporary dot file
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("application/pdf")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-12-28 03:17:11 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
2007-12-28 03:17:11 +05:30
|
|
|
# GVPdfGsDoc
|
2007-09-30 10:26:56 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
2007-12-28 03:17:11 +05:30
|
|
|
class GVPdfGsDoc(GVDocBase):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" GVDoc implementation that generates a .pdf file using Ghostscript. """
|
2008-03-20 08:48:35 +05:30
|
|
|
def __init__(self, options, paper_style):
|
|
|
|
# DPI must always be 72 for PDF.
|
|
|
|
# GV documentation says dpi is only for image formats.
|
2008-05-11 10:35:11 +05:30
|
|
|
options.menu.get_option_by_name('dpi').set_value(72)
|
2008-03-20 08:48:35 +05:30
|
|
|
GVDocBase.__init__(self, options, paper_style)
|
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
def close(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
""" Implements GVDocBase.close() """
|
2007-09-30 10:26:56 +05:30
|
|
|
GVDocBase.close(self)
|
|
|
|
|
|
|
|
# Make sure the extension is correct
|
2008-04-23 10:12:08 +05:30
|
|
|
if self._filename[-4:] != ".pdf":
|
|
|
|
self._filename += ".pdf"
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
# Create a temporary dot file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_dot) = tempfile.mkstemp(".dot" )
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile = os.fdopen(handle,"w")
|
2008-04-23 10:12:08 +05:30
|
|
|
dotfile.write(self._dot.getvalue())
|
2007-09-30 10:26:56 +05:30
|
|
|
dotfile.close()
|
|
|
|
|
2008-04-16 01:13:54 +05:30
|
|
|
# Create a temporary PostScript file
|
2008-04-23 08:55:41 +05:30
|
|
|
(handle, tmp_ps) = tempfile.mkstemp(".ps" )
|
2007-09-30 10:26:56 +05:30
|
|
|
os.close( handle )
|
|
|
|
|
2008-04-16 01:13:54 +05:30
|
|
|
# Generate PostScript using dot
|
2007-09-30 10:26:56 +05:30
|
|
|
command = 'dot -Tps -o"%s" "%s"' % ( tmp_ps, tmp_dot )
|
|
|
|
os.system(command)
|
|
|
|
|
|
|
|
# Add .5 to remove rounding errors.
|
2008-04-23 10:12:08 +05:30
|
|
|
paper_size = self._paper.get_size()
|
2007-09-30 10:26:56 +05:30
|
|
|
width_pt = int( (paper_size.get_width_inches() * 72) + 0.5 )
|
|
|
|
height_pt = int( (paper_size.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' \
|
2008-04-23 10:12:08 +05:30
|
|
|
% ( _GS_CMD, width_pt, height_pt, self._filename, tmp_ps )
|
2007-09-30 10:26:56 +05:30
|
|
|
os.system(command)
|
|
|
|
|
|
|
|
os.remove(tmp_ps)
|
|
|
|
os.remove(tmp_dot)
|
|
|
|
|
|
|
|
if self.print_req:
|
|
|
|
app = Mime.get_application("application/pdf")
|
2008-04-23 10:12:08 +05:30
|
|
|
Utils.launch(app[0], self._filename)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Various Graphviz formats.
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS = []
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-04-23 08:55:41 +05:30
|
|
|
if _DOT_FOUND:
|
2007-12-21 11:27:43 +05:30
|
|
|
|
2008-04-23 08:55:41 +05:30
|
|
|
if _GS_CMD != "":
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "gspdf",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "pdf",
|
2007-12-28 03:17:11 +05:30
|
|
|
'descr': _("PDF (Ghostscript)"),
|
2007-12-21 11:27:43 +05:30
|
|
|
'mime' : "application/pdf",
|
2007-12-28 03:17:11 +05:30
|
|
|
'class': GVPdfGsDoc }]
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "gvpdf",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "pdf",
|
2007-12-28 03:17:11 +05:30
|
|
|
'descr': _("PDF (Graphviz)"),
|
|
|
|
'mime' : "application/pdf",
|
|
|
|
'class': GVPdfGvDoc }]
|
2007-12-21 11:27:43 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "ps",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "ps",
|
2008-04-16 01:13:54 +05:30
|
|
|
'descr': _("PostScript"),
|
2007-09-30 10:26:56 +05:30
|
|
|
'mime' : "application/postscript",
|
|
|
|
'class': GVPsDoc }]
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "svg",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "svg",
|
2007-09-30 10:26:56 +05:30
|
|
|
'descr': _("Structured Vector Graphics (SVG)"),
|
|
|
|
'mime' : "image/svg",
|
|
|
|
'class': GVSvgDoc }]
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "svgz",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "svgz",
|
2007-09-30 10:26:56 +05:30
|
|
|
'descr': _("Compressed Structured Vector Graphs (SVG)"),
|
|
|
|
'mime' : "image/svgz",
|
|
|
|
'class': GVSvgzDoc }]
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "jpg",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "jpg",
|
2007-09-30 10:26:56 +05:30
|
|
|
'descr': _("JPEG image"),
|
|
|
|
'mime' : "image/jpeg",
|
|
|
|
'class': GVJpegDoc }]
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "gif",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "gif",
|
2007-09-30 10:26:56 +05:30
|
|
|
'descr': _("GIF image"),
|
|
|
|
'mime' : "image/gif",
|
|
|
|
'class': GVGifDoc }]
|
2007-12-21 11:27:43 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "png",
|
2007-12-28 03:35:45 +05:30
|
|
|
'ext' : "png",
|
2007-12-21 11:27:43 +05:30
|
|
|
'descr': _("PNG image"),
|
|
|
|
'mime' : "image/png",
|
|
|
|
'class': GVPngDoc }]
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
_FORMATS += [{ 'type' : "dot",
|
|
|
|
'ext' : "dot",
|
|
|
|
'descr': _("Graphviz Dot File"),
|
|
|
|
'mime' : "text/x-graphviz",
|
|
|
|
'class': GVDotDoc }]
|
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GraphvizFormatComboBox
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GraphvizFormatComboBox(gtk.ComboBox):
|
|
|
|
"""
|
|
|
|
Format combo box class for Graphviz report.
|
|
|
|
"""
|
2008-04-23 08:55:41 +05:30
|
|
|
def set(self, active=None):
|
2008-01-22 03:33:43 +05:30
|
|
|
self.store = gtk.ListStore(gobject.TYPE_STRING)
|
2007-09-30 10:26:56 +05:30
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
2008-04-23 08:55:41 +05:30
|
|
|
self.pack_start(cell, True)
|
|
|
|
self.add_attribute(cell, 'text', 0)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
out_pref = Config.get(Config.OUTPUT_PREFERENCE)
|
|
|
|
index = 0
|
|
|
|
active_index = 0
|
2008-04-23 10:12:08 +05:30
|
|
|
for item in _FORMATS:
|
2007-09-30 10:26:56 +05:30
|
|
|
name = item["descr"]
|
|
|
|
self.store.append(row=[name])
|
|
|
|
if item['type'] == active:
|
|
|
|
active_index = index
|
|
|
|
elif not active and name == out_pref:
|
|
|
|
active_index = index
|
|
|
|
index = index + 1
|
|
|
|
self.set_active(active_index)
|
|
|
|
|
|
|
|
def get_label(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
return _FORMATS[self.get_active()]["descr"]
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def get_reference(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
return _FORMATS[self.get_active()]["class"]
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def get_paper(self):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
def get_styles(self):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def get_ext(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
return '.%s' % _FORMATS[self.get_active()]['ext']
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def get_format_str(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
return _FORMATS[self.get_active()]["type"]
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def get_printable(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
_apptype = _FORMATS[self.get_active()]["mime"]
|
2007-09-30 10:26:56 +05:30
|
|
|
print_label = None
|
|
|
|
try:
|
|
|
|
mprog = Mime.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
|
|
|
|
|
|
|
|
def get_clname(self):
|
2008-04-23 10:12:08 +05:30
|
|
|
return _FORMATS[self.get_active()]["type"]
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GraphvizReportDialog
|
|
|
|
#
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
class GraphvizReportDialog(ReportDialog):
|
|
|
|
"""A class of ReportDialog customized for graphviz based reports."""
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, dbstate, uistate, opt, name, translated_name):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""Initialize a dialog to request that the user select options
|
|
|
|
for a graphiz report. See the ReportDialog class for
|
|
|
|
more information."""
|
|
|
|
self.category = CATEGORY_GRAPHVIZ
|
2008-02-20 10:22:10 +05:30
|
|
|
ReportDialog.__init__(self, dbstate, uistate, opt,
|
2008-01-28 10:07:19 +05:30
|
|
|
name, translated_name)
|
2007-12-13 07:22:03 +05:30
|
|
|
|
2008-01-28 10:07:19 +05:30
|
|
|
def init_options(self, option_class):
|
2008-05-26 01:25:47 +05:30
|
|
|
if isinstance(option_class, ClassType):
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options = option_class(self.raw_name,
|
|
|
|
self.dbstate.get_database())
|
2008-05-26 01:25:47 +05:30
|
|
|
elif isinstance(option_class, InstanceType):
|
2007-12-16 09:21:02 +05:30
|
|
|
self.options = option_class
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
################################
|
2007-12-25 07:27:45 +05:30
|
|
|
category = _("GraphViz Layout")
|
2007-12-20 11:56:38 +05:30
|
|
|
################################
|
2008-04-23 10:12:08 +05:30
|
|
|
font_family = EnumeratedListOption(_("Font family"), "")
|
2007-12-16 09:21:02 +05:30
|
|
|
index = 0
|
|
|
|
for item in _FONTS:
|
2008-04-23 10:12:08 +05:30
|
|
|
font_family.add_item(item["value"], item["name"])
|
2008-01-28 10:07:19 +05:30
|
|
|
index += 1
|
2007-12-16 09:21:02 +05:30
|
|
|
font_family.set_help(_("Choose the font family. If international "
|
|
|
|
"characters don't show, use FreeSans font. "
|
|
|
|
"FreeSans is available from: "
|
|
|
|
"http://www.nongnu.org/freefont/"))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "font_family", font_family)
|
2007-12-23 13:22:01 +05:30
|
|
|
|
2008-01-28 10:07:19 +05:30
|
|
|
font_size = NumberOption(_("Font size"), 14, 8, 128)
|
2007-12-16 09:21:02 +05:30
|
|
|
font_size.set_help(_("The font size, in points."))
|
2008-04-23 08:55:41 +05:30
|
|
|
self.options.add_menu_option(category, "font_size", font_size)
|
2007-12-16 09:21:02 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
rank_dir = EnumeratedListOption(_("Graph Direction"), "TB")
|
2007-12-16 09:21:02 +05:30
|
|
|
index = 0
|
|
|
|
for item in _RANKDIR:
|
2008-04-23 10:12:08 +05:30
|
|
|
rank_dir.add_item(item["value"], item["name"])
|
2008-01-28 10:07:19 +05:30
|
|
|
index += 1
|
2007-12-16 09:21:02 +05:30
|
|
|
rank_dir.set_help(_("Whether graph goes from top to bottom "
|
|
|
|
"or left to right."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "rank_dir", rank_dir)
|
2007-12-23 13:22:01 +05:30
|
|
|
|
2008-01-28 10:07:19 +05:30
|
|
|
h_pages = NumberOption(_("Number of Horizontal Pages"), 1, 1, 25)
|
2007-12-25 07:27:45 +05:30
|
|
|
h_pages.set_help(_("GraphViz can create very large graphs by "
|
|
|
|
"spreading the graph across a rectangular "
|
|
|
|
"array of pages. This controls the number "
|
2008-05-13 14:09:27 +05:30
|
|
|
"pages in the array horizontally. "
|
|
|
|
"Only valid for dot, postscript and pdf "
|
|
|
|
"via Ghostscript."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "h_pages", h_pages)
|
2007-12-25 07:27:45 +05:30
|
|
|
|
2008-01-28 10:07:19 +05:30
|
|
|
v_pages = NumberOption(_("Number of Vertical Pages"), 1, 1, 25)
|
2007-12-25 07:27:45 +05:30
|
|
|
v_pages.set_help(_("GraphViz can create very large graphs by "
|
|
|
|
"spreading the graph across a rectangular "
|
|
|
|
"array of pages. This controls the number "
|
2008-05-13 14:09:27 +05:30
|
|
|
"pages in the array vertically. "
|
|
|
|
"Only valid for dot, postscript and pdf "
|
|
|
|
"via Ghostscript."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "v_pages", v_pages)
|
2007-12-25 07:27:45 +05:30
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
page_dir = EnumeratedListOption(_("Paging Direction"), "BL")
|
2007-12-25 07:27:45 +05:30
|
|
|
index = 0
|
|
|
|
for item in _PAGEDIR:
|
2008-04-23 10:12:08 +05:30
|
|
|
page_dir.add_item(item["value"], item["name"])
|
2008-01-28 10:07:19 +05:30
|
|
|
index += 1
|
2007-12-25 07:27:45 +05:30
|
|
|
page_dir.set_help(_("The order in which the graph pages are output. "
|
|
|
|
"This option only applies if the horizontal pages "
|
|
|
|
"or vertical pages are greater than 1."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "page_dir", page_dir)
|
2007-12-25 07:27:45 +05:30
|
|
|
|
|
|
|
# the page direction option only makes sense when the
|
|
|
|
# number of horizontal and/or vertical pages is > 1,
|
|
|
|
# so we need to remember these 3 controls for later
|
|
|
|
self.h_pages = h_pages
|
|
|
|
self.v_pages = v_pages
|
|
|
|
self.page_dir = page_dir
|
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
# the page direction option only makes sense when the
|
|
|
|
# number of horizontal and/or vertical pages is > 1
|
|
|
|
self.h_pages.connect('value-changed', self.pages_changed)
|
|
|
|
self.v_pages.connect('value-changed', self.pages_changed)
|
|
|
|
|
2007-12-25 07:27:45 +05:30
|
|
|
################################
|
|
|
|
category = _("GraphViz Options")
|
|
|
|
################################
|
|
|
|
|
2008-04-23 10:12:08 +05:30
|
|
|
aspect_ratio = EnumeratedListOption(_("Aspect ratio"), "fill")
|
2007-12-25 07:27:45 +05:30
|
|
|
index = 0
|
|
|
|
for item in _RATIO:
|
2008-04-23 10:12:08 +05:30
|
|
|
aspect_ratio.add_item(item["value"], item["name"])
|
2008-01-28 10:07:19 +05:30
|
|
|
index += 1
|
2007-12-25 07:27:45 +05:30
|
|
|
aspect_ratio.set_help(_("Affects greatly how the graph is layed out "
|
|
|
|
"on the page."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "ratio", aspect_ratio)
|
2007-12-25 07:27:45 +05:30
|
|
|
|
2007-12-23 13:22:01 +05:30
|
|
|
dpi = NumberOption(_("DPI"), 75, 20, 1200)
|
|
|
|
dpi.set_help(_( "Dots per inch. When creating images such as "
|
|
|
|
".gif or .png files for the web, try numbers "
|
2008-04-16 01:13:54 +05:30
|
|
|
"such as 100 or 300 DPI. When creating PostScript "
|
|
|
|
"or PDF files, use 72 DPI."))
|
2007-12-23 13:22:01 +05:30
|
|
|
self.options.add_menu_option(category, "dpi", dpi)
|
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
nodesep = NumberOption(_("Node spacing"), 0.20, 0.01, 5.00, 0.01)
|
2007-12-23 13:22:01 +05:30
|
|
|
nodesep.set_help(_( "The minimum amount of free space, in inches, "
|
|
|
|
"between individual nodes. For vertical graphs, "
|
|
|
|
"this corresponds to spacing between columns. "
|
|
|
|
"For horizontal graphs, this corresponds to "
|
|
|
|
"spacing between rows."))
|
|
|
|
self.options.add_menu_option(category, "nodesep", nodesep)
|
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
ranksep = NumberOption(_("Rank spacing"), 0.20, 0.01, 5.00, 0.01)
|
2007-12-23 13:22:01 +05:30
|
|
|
ranksep.set_help(_( "The minimum amount of free space, in inches, "
|
|
|
|
"between ranks. For vertical graphs, this "
|
|
|
|
"corresponds to spacing between rows. For "
|
|
|
|
"horizontal graphs, this corresponds to spacing "
|
|
|
|
"between columns."))
|
|
|
|
self.options.add_menu_option(category, "ranksep", ranksep)
|
|
|
|
|
2007-12-20 11:56:38 +05:30
|
|
|
################################
|
2007-12-28 15:38:19 +05:30
|
|
|
category = _("Note")
|
2007-12-20 11:56:38 +05:30
|
|
|
################################
|
|
|
|
|
|
|
|
note = TextOption(_("Note to add to the graph"),
|
|
|
|
[""] )
|
|
|
|
note.set_help(_("This text will be added to the graph."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "note", note)
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
noteloc = EnumeratedListOption(_("Note location"), 't')
|
|
|
|
for i in range( 0, len(_NOTELOC) ):
|
|
|
|
noteloc.add_item(_NOTELOC[i]["value"], _NOTELOC[i]["name"])
|
|
|
|
noteloc.set_help(_("Whether note will appear on top "
|
|
|
|
"or bottom of the page."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "noteloc", noteloc)
|
2007-12-20 11:56:38 +05:30
|
|
|
|
2008-01-28 10:07:19 +05:30
|
|
|
notesize = NumberOption(_("Note size"), 32, 8, 128)
|
2007-12-20 11:56:38 +05:30
|
|
|
notesize.set_help(_("The size of note text, in points."))
|
2008-01-28 10:07:19 +05:30
|
|
|
self.options.add_menu_option(category, "notesize", notesize)
|
2007-12-16 09:21:02 +05:30
|
|
|
|
|
|
|
self.options.load_previous_values()
|
2007-12-25 07:27:45 +05:30
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
def pages_changed(self):
|
|
|
|
"""
|
|
|
|
This method gets called every time the v_pages or h_pages
|
|
|
|
options are changed; when both vertical and horizontal
|
|
|
|
pages are set to "1", then the page_dir control needs to
|
|
|
|
be unavailable
|
|
|
|
"""
|
|
|
|
if self.v_pages.get_value() > 1 or \
|
|
|
|
self.h_pages.get_value() > 1:
|
|
|
|
self.page_dir.set_available(True)
|
2007-12-25 07:27:45 +05:30
|
|
|
else:
|
2008-01-18 11:09:50 +05:30
|
|
|
self.page_dir.set_available(False)
|
2007-12-28 15:38:19 +05:30
|
|
|
|
2007-12-13 07:22:03 +05:30
|
|
|
def init_interface(self):
|
|
|
|
ReportDialog.init_interface(self)
|
|
|
|
self.doc_type_changed(self.format_menu)
|
|
|
|
|
|
|
|
def setup_format_frame(self):
|
|
|
|
"""Set up the format frame of the dialog."""
|
2007-09-30 10:26:56 +05:30
|
|
|
self.format_menu = GraphvizFormatComboBox()
|
2007-12-13 07:22:03 +05:30
|
|
|
self.format_menu.set(self.options.handler.get_format_name())
|
2008-04-23 08:55:41 +05:30
|
|
|
self.format_menu.connect('changed', self.doc_type_changed)
|
2007-12-13 07:22:03 +05:30
|
|
|
label = gtk.Label("%s:" % _("Output Format"))
|
2008-04-23 08:55:41 +05:30
|
|
|
label.set_alignment(0.0, 0.5)
|
|
|
|
self.tbl.attach(label, 1, 2, self.row, self.row+1, gtk.SHRINK|gtk.FILL)
|
|
|
|
self.tbl.attach(self.format_menu, 2, 4, self.row, self.row+1,
|
2008-03-10 01:09:56 +05:30
|
|
|
yoptions=gtk.SHRINK)
|
|
|
|
self.row += 1
|
|
|
|
|
2008-04-23 08:55:41 +05:30
|
|
|
self.print_report = gtk.CheckButton(_("Open with application"))
|
|
|
|
self.tbl.attach(self.print_report, 2, 4, self.row, self.row+1,
|
2007-12-13 07:22:03 +05:30
|
|
|
yoptions=gtk.SHRINK)
|
2008-03-10 01:09:56 +05:30
|
|
|
self.row += 1
|
2007-12-13 07:22:03 +05:30
|
|
|
|
|
|
|
ext = self.format_menu.get_ext()
|
|
|
|
if ext == None:
|
|
|
|
ext = ""
|
|
|
|
else:
|
|
|
|
spath = self.get_default_directory()
|
2008-04-22 09:15:09 +05:30
|
|
|
base = self.get_default_basename()
|
|
|
|
spath = os.path.normpath("%s/%s%s" % (spath, base, ext))
|
|
|
|
self.target_fileentry.set_filename(spath)
|
2007-12-13 07:22:03 +05:30
|
|
|
|
|
|
|
def setup_report_options_frame(self):
|
|
|
|
self.paper_label = gtk.Label('<b>%s</b>'%_("Paper Options"))
|
|
|
|
self.paper_label.set_use_markup(True)
|
|
|
|
|
2008-04-23 08:55:41 +05:30
|
|
|
self.paper_frame = PaperFrame(
|
|
|
|
self.options.handler.get_paper_metric(),
|
|
|
|
self.options.handler.get_paper_name(),
|
|
|
|
self.options.handler.get_orientation(),
|
|
|
|
self.options.handler.get_margins(),
|
|
|
|
self.options.handler.get_custom_paper_size()
|
2008-01-09 10:53:27 +05:30
|
|
|
)
|
2008-04-23 08:55:41 +05:30
|
|
|
self.notebook.insert_page(self.paper_frame, self.paper_label, 0)
|
2007-12-13 07:22:03 +05:30
|
|
|
self.paper_frame.show_all()
|
|
|
|
|
|
|
|
ReportDialog.setup_report_options_frame(self)
|
|
|
|
|
|
|
|
def doc_type_changed(self, obj):
|
|
|
|
"""This routine is called when the user selects a new file
|
|
|
|
formats for the report. It adjust the various dialog sections
|
|
|
|
to reflect the appropriate values for the currently selected
|
|
|
|
file format. For example, a HTML document doesn't need any
|
|
|
|
paper size/orientation options, but it does need a template
|
|
|
|
file. Those chances are made here."""
|
|
|
|
|
|
|
|
label = obj.get_printable()
|
|
|
|
if label:
|
|
|
|
self.print_report.set_label (label)
|
|
|
|
self.print_report.set_sensitive (True)
|
|
|
|
else:
|
|
|
|
self.print_report.set_label (_("Open with application"))
|
|
|
|
self.print_report.set_sensitive (False)
|
|
|
|
|
2007-12-20 11:56:38 +05:30
|
|
|
fname = self.target_fileentry.get_full_path(0)
|
2008-04-23 08:55:41 +05:30
|
|
|
(spath, ext) = os.path.splitext(fname)
|
2007-12-20 11:56:38 +05:30
|
|
|
|
|
|
|
ext_val = obj.get_ext()
|
|
|
|
if ext_val:
|
|
|
|
fname = spath + ext_val
|
|
|
|
else:
|
|
|
|
fname = spath
|
|
|
|
self.target_fileentry.set_filename(fname)
|
|
|
|
|
2007-12-13 07:22:03 +05:30
|
|
|
def make_document(self):
|
|
|
|
"""Create a document of the type requested by the user.
|
|
|
|
"""
|
|
|
|
pstyle = self.paper_frame.get_paper_style()
|
|
|
|
|
2007-12-16 09:21:02 +05:30
|
|
|
self.doc = self.format(self.options, pstyle)
|
2007-12-13 07:22:03 +05:30
|
|
|
|
|
|
|
self.options.set_document(self.doc)
|
|
|
|
|
|
|
|
if self.print_report.get_active():
|
|
|
|
self.doc.print_requested()
|
|
|
|
|
|
|
|
def on_ok_clicked(self, obj):
|
|
|
|
"""The user is satisfied with the dialog choices. Validate
|
|
|
|
the output file name before doing anything else. If there is
|
|
|
|
a file name, gather the options and create the report."""
|
|
|
|
|
|
|
|
# Is there a filename? This should also test file permissions, etc.
|
|
|
|
if not self.parse_target_frame():
|
|
|
|
self.window.run()
|
|
|
|
|
|
|
|
# Preparation
|
|
|
|
self.parse_format_frame()
|
|
|
|
self.parse_user_options()
|
2008-01-12 17:07:21 +05:30
|
|
|
|
2008-04-23 08:55:41 +05:30
|
|
|
self.options.handler.set_paper_metric(
|
|
|
|
self.paper_frame.get_paper_metric())
|
2007-12-13 07:22:03 +05:30
|
|
|
self.options.handler.set_paper_name(self.paper_frame.get_paper_name())
|
|
|
|
self.options.handler.set_orientation(self.paper_frame.get_orientation())
|
2008-01-09 10:53:27 +05:30
|
|
|
self.options.handler.set_margins(self.paper_frame.get_paper_margins())
|
2008-04-23 08:55:41 +05:30
|
|
|
self.options.handler.set_custom_paper_size(
|
|
|
|
self.paper_frame.get_custom_paper_size())
|
2008-01-09 10:53:27 +05:30
|
|
|
|
2007-12-13 07:22:03 +05:30
|
|
|
# Create the output document.
|
|
|
|
self.make_document()
|
|
|
|
|
|
|
|
# Save options
|
|
|
|
self.options.handler.save_options()
|
|
|
|
|
|
|
|
def parse_format_frame(self):
|
|
|
|
"""Parse the format frame of the dialog. Save the user
|
|
|
|
selected output format for later use."""
|
|
|
|
self.format = self.format_menu.get_reference()
|
|
|
|
format_name = self.format_menu.get_clname()
|
|
|
|
self.options.handler.set_format_name(format_name)
|
|
|
|
|
|
|
|
def setup_style_frame(self):
|
2008-04-22 09:15:09 +05:30
|
|
|
"""Required by ReportDialog"""
|
2007-12-13 07:22:03 +05:30
|
|
|
pass
|