_GraphvisReportDialog.py: Fix to conform to 80 columns. Add Graphviz generated PDF as an option (requires Graphviz 2.16 to work)

svn: r9602
This commit is contained in:
Brian Matherly 2007-12-27 21:47:11 +00:00
parent 85fd9a2d1b
commit 8456e16cbc
2 changed files with 78 additions and 39 deletions

View File

@ -1,3 +1,7 @@
2007-12-27 Brian Matherly <brian@gramps-project.org>
* src/ReportBase/_GraphvisReportDialog.py: Fix to conform to 80 columns.
Add Graphviz generated PDF as an option (requires Graphviz 2.16 to work)
2007-12-27 Brian Matherly <brian@gramps-project.org> 2007-12-27 Brian Matherly <brian@gramps-project.org>
* src/Config/_GrampsConfigKeys.py: Better default for report output. * src/Config/_GrampsConfigKeys.py: Better default for report output.
* src/gen/db/dbconst.py: Remove constants that are duplicated in const.py. * src/gen/db/dbconst.py: Remove constants that are duplicated in const.py.

View File

@ -48,7 +48,8 @@ import Config
from _Constants import CATEGORY_GRAPHVIZ from _Constants import CATEGORY_GRAPHVIZ
from _ReportDialog import ReportDialog from _ReportDialog import ReportDialog
from _PaperMenu import PaperFrame from _PaperMenu import PaperFrame
from PluginUtils import NumberOption, FloatOption, EnumeratedListOption, TextOption, BooleanOption from PluginUtils import NumberOption, FloatOption, EnumeratedListOption, \
TextOption, BooleanOption
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -77,7 +78,6 @@ _RATIO = [ { 'name' : _("Minimal size"), 'value' : "compress"
{ 'name' : _("Fill the given area"), 'value': "fill" }, { 'name' : _("Fill the given area"), 'value': "fill" },
{ 'name' : _("Use optimal number of pages"), 'value': "expand" } ] { 'name' : _("Use optimal number of pages"), 'value': "expand" } ]
_NOTELOC = [ { 'name' : _("Top"), 'value' : "t" }, _NOTELOC = [ { 'name' : _("Top"), 'value' : "t" },
{ 'name' : _("Bottom"), 'value' : "b" }] { 'name' : _("Bottom"), 'value' : "b" }]
@ -177,9 +177,8 @@ class GVDocBase(BaseDoc.BaseDoc,BaseDoc.GVDoc):
self.dot.write( ' size="%3.2f,%3.2f"; \n' % (sizew, sizeh) ) self.dot.write( ' size="%3.2f,%3.2f"; \n' % (sizew, sizeh) )
self.dot.write( ' splines="true";\n' ) self.dot.write( ' splines="true";\n' )
self.dot.write( '\n' ) self.dot.write( '\n' )
# self.dot.write( ' edge [len=0.5 style=solid arrowhead=none arrowtail=normal fontsize=12];\n') self.dot.write( ' edge [len=0.5 style=solid arrowhead=none '
# self.dot.write( ' node [style=filled fontname="FreeSans" fontsize=12];\n' ) 'arrowtail=normal fontsize=%d];\n' % self.fontsize )
self.dot.write( ' edge [len=0.5 style=solid arrowhead=none arrowtail=normal fontsize=%d];\n' % self.fontsize )
if self.fontfamily: if self.fontfamily:
self.dot.write( ' node [style=filled fontname="%s" fontsize=%d];\n' self.dot.write( ' node [style=filled fontname="%s" fontsize=%d];\n'
% ( self.fontfamily, self.fontsize ) ) % ( self.fontfamily, self.fontsize ) )
@ -303,7 +302,7 @@ class GVPsDoc(GVDocBase):
dotfile.close() dotfile.close()
# Generate the PS file. # Generate the PS file.
os.system( 'dot -Tps -o"%s" "%s"' % (self.filename,tmp_dot) ) os.system( 'dot -Tps2 -o"%s" "%s"' % (self.filename,tmp_dot) )
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
@ -459,10 +458,40 @@ class GVGifDoc(GVDocBase):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# GVPdfDoc # GVPdfGvDoc
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class GVPdfDoc(GVDocBase): class GVPdfGvDoc(GVDocBase):
def close(self):
GVDocBase.close(self)
# Make sure the extension is correct
if self.filename[-4:] != ".pdf":
self.filename += ".pdf"
# Create a temporary dot file
(handle,tmp_dot) = tempfile.mkstemp(".dot" )
dotfile = os.fdopen(handle,"w")
dotfile.write(self.dot.getvalue())
dotfile.close()
# Generate the PDF file.
os.system( 'dot -Tpdf -o"%s" "%s"' % (self.filename,tmp_dot) )
# Delete the temporary dot file
os.remove(tmp_dot)
if self.print_req:
app = Mime.get_application("application/pdf")
Utils.launch(app[0], self.filename)
#-------------------------------------------------------------------------------
#
# GVPdfGsDoc
#
#-------------------------------------------------------------------------------
class GVPdfGsDoc(GVDocBase):
def close(self): def close(self):
GVDocBase.close(self) GVDocBase.close(self)
@ -517,9 +546,14 @@ if _dot_found:
if _gs_cmd != "": if _gs_cmd != "":
_formats += [{ 'type' : "pdf", _formats += [{ 'type' : "pdf",
'descr': _("PDF"), 'descr': _("PDF (Ghostscript)"),
'mime' : "application/pdf", 'mime' : "application/pdf",
'class': GVPdfDoc }] 'class': GVPdfGsDoc }]
_formats += [{ 'type' : "pdf",
'descr': _("PDF (Graphviz)"),
'mime' : "application/pdf",
'class': GVPdfGvDoc }]
_formats += [{ 'type' : "ps", _formats += [{ 'type' : "ps",
'descr': _("Postscript"), 'descr': _("Postscript"),
@ -760,7 +794,8 @@ class GraphvizReportDialog(ReportDialog):
self.options.load_previous_values() self.options.load_previous_values()
def pages_changed(self, sp): def pages_changed(self, sp):
if self.v_pages.gobj.get_value_as_int() > 1 or self.h_pages.gobj.get_value_as_int() > 1: if self.v_pages.gobj.get_value_as_int() > 1 or \
self.h_pages.gobj.get_value_as_int() > 1:
self.page_dir.combo.set_sensitive(True) self.page_dir.combo.set_sensitive(True)
else: else:
self.page_dir.combo.set_sensitive(False) self.page_dir.combo.set_sensitive(False)