From 0eb3838f92889af0fdb55a7c8922ad072a592def Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Thu, 13 Apr 2006 03:01:12 +0000 Subject: [PATCH] Add graph preview based on MIME type. svn: r6319 --- ChangeLog | 3 +++ src/plugins/GraphViz.py | 47 +++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a731b13b5..95bd30a17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2006-04-12 Brian Matherly + * src/plugins/GraphViz.py: Add graph preview based on mime (Bug 1449796) + 2006-04-12 Alex Roitman * src/plugins/Check.py (Check.__init__): Typo. diff --git a/src/plugins/GraphViz.py b/src/plugins/GraphViz.py index 102a0940f..bc7faf635 100644 --- a/src/plugins/GraphViz.py +++ b/src/plugins/GraphViz.py @@ -69,12 +69,12 @@ from QuestionDialog import ErrorDialog class _options: # internal ID, english option name (for cli), localized option name (for gui) formats = ( - ("ps", "Postscript", _("Postscript")), - ("svg", "Structured Vector Graphics (SVG)", _("Structured Vector Graphics (SVG)")), - ("svgz", "Compressed Structured Vector Graphics (SVG)", _("Compressed Structured Vector Graphics (SVG)")), - ("png", "PNG image", _("PNG image")), - ("jpg", "JPEG image", _("JPEG image")), - ("gif", "GIF image", _("GIF image")), + ("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"), ) fonts = ( # Last items tells whether strings need to be converted to Latin1 @@ -878,7 +878,20 @@ class GraphicsFormatComboBox(gtk.ComboBox): return _options.formats[self.get_active()][0] def get_printable(self): - return None + _apptype = _options.formats[self.get_active()][3] + print_label = None + try: + import Utils + import GrampsMime + mprog = GrampsMime.get_application(_apptype) + if Utils.search_for(mprog[0]): + print_label = _("Open in %(program_name)s") % { 'program_name': + mprog[1]} + else: + print_label = None + except: + print_label = None + return print_label def get_clname(self): return 'print' @@ -890,10 +903,14 @@ class GraphicsFormatComboBox(gtk.ComboBox): #------------------------------------------------------------------------ class EmptyDoc: def __init__(self,styles,type,template,orientation,source=None): + self.print_req = 0 pass def init(self): pass + + def print_requested(self): + self.print_req = 1 #------------------------------------------------------------------------ # @@ -939,6 +956,22 @@ class GraphVizGraphics(Report.Report): (self.the_format,self.user_output, self.junk_output,self.junk_output)) + if self.doc.print_req: + _apptype = None + for format in _options.formats: + if format[0] == self.the_format: + _apptype = format[3] + break + if _apptype: + try: + import Utils + import GrampsMime + app = GrampsMime.get_application(_apptype) + os.environ["FILE"] = self.user_output + os.system ('%s "$FILE" &' % app[0]) + except: + pass + #------------------------------------------------------------------------ # #