From f3555d016867efd944b41f4c1ff90b707649dab4 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Fri, 13 Sep 2019 21:45:18 +0200 Subject: [PATCH] Add new graph output format to the tree document generator The "graph" is the data part for genealogytree without the boilerplate code around it that makes up a full LaTeX file. This format is useful for people who have their own (more sophisticated) LaTeX file with custom styles and so on. The implementation is pretty straight-forward: Just don't output the LaTeX code. --- gramps/gen/plug/docgen/treedoc.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gramps/gen/plug/docgen/treedoc.py b/gramps/gen/plug/docgen/treedoc.py index e94765740..d770f9a1b 100644 --- a/gramps/gen/plug/docgen/treedoc.py +++ b/gramps/gen/plug/docgen/treedoc.py @@ -586,6 +586,47 @@ class TreeDocBase(BaseDoc, TreeDoc): self.write_end() +#------------------------------------------------------------------------------ +# +# TreeGraphDoc +# +#------------------------------------------------------------------------------ +class TreeGraphDoc(TreeDocBase): + """ + TreeGraphDoc implementation that generates a .graph file. + """ + + def write_start(self): + """ + Write the start of the document - nothing for a graph file. + """ + pass + + def start_tree(self, option_list): + """ + Write the start of a tree - nothing for a graph file. + """ + pass + + def end_tree(self): + """ + Write the end of a tree - nothing for a graph file. + """ + pass + + def write_end(self): + """ + Write the end of the document - nothing for a graph file. + """ + pass + + def close(self): + """ Implements TreeDocBase.close() """ + TreeDocBase.close(self) + + with open(self._filename, 'w', encoding='utf-8') as texfile: + texfile.write(self._tex.getvalue()) + #------------------------------------------------------------------------------ # # TreeTexDoc @@ -653,6 +694,11 @@ if _LATEX_FOUND: 'mime' : "application/pdf", 'class': TreePdfDoc}] +FORMATS += [{'type' : "graph", + 'ext' : "graph", + 'descr': _("Graph File for genealogytree"), + 'class': TreeGraphDoc}] + FORMATS += [{'type' : "tex", 'ext' : "tex", 'descr': _("LaTeX File"),