From 4398bb57e47e11a138ddd62b002276fd9a05f5b4 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 11:21:16 +0100 Subject: [PATCH 01/30] Create ExportFilter.py --- import_export_filters/ExportFilter.py | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 import_export_filters/ExportFilter.py diff --git a/import_export_filters/ExportFilter.py b/import_export_filters/ExportFilter.py new file mode 100644 index 0000000..5f79d11 --- /dev/null +++ b/import_export_filters/ExportFilter.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.import_export_filters.ExportFilter + ~~~~~~~~~~~ + :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + XMind files to other formats (e.g: GraphViz). + :copyright: + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +import os +import os.path + +FILE_NOT_FOUND_ERROR = 1 + +class ExportFilter: + def __init__(self): + self.name = "export_filter" + + #---------- export() ---------- + def export(self, source_path, target_path): + print("export_filter.name: '" + self.name + "'") + if (not os.path.isfile(source_path)): + print("source_path: '" + source_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + #---------- export() + +#======================== main ======================== +def main(): + print("** xmind.ExportFilter **") + export_filter = ExportFilter() + export_filter.export("", "") + #pass + +if __name__ == '__main__': + main() From f5bdf997f3973d3b43494d203c7f5511c7c19af0 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 15:50:17 +0100 Subject: [PATCH 02/30] commit 1 --- .../import_export_filters}/ExportFilter.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {import_export_filters => xmind/import_export_filters}/ExportFilter.py (100%) diff --git a/import_export_filters/ExportFilter.py b/xmind/import_export_filters/ExportFilter.py similarity index 100% rename from import_export_filters/ExportFilter.py rename to xmind/import_export_filters/ExportFilter.py From 716339dea665bb22882c26379fd551bd78a52859 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 15:54:31 +0100 Subject: [PATCH 03/30] commit 2 --- .settings/org.eclipse.core.resources.prefs | 11 +++++ .../ExportFilter.py | 8 ++-- xmind/import_export/GraphvizExportFilter.py | 43 +++++++++++++++++++ xmind/import_export/__init__.py | 17 ++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 .settings/org.eclipse.core.resources.prefs rename xmind/{import_export_filters => import_export}/ExportFilter.py (89%) create mode 100644 xmind/import_export/GraphvizExportFilter.py create mode 100644 xmind/import_export/__init__.py diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..93b13f4 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +encoding//xmind/__init__.py=utf-8 +encoding//xmind/core/__init__.py=utf-8 +encoding//xmind/core/const.py=utf-8 +encoding//xmind/core/notes.py=utf-8 +encoding//xmind/core/workbook.py=utf-8 +encoding//xmind/import_export/ExportFilter.py=utf-8 +encoding//xmind/import_export/GraphvizExportFilter.py=utf-8 +encoding//xmind/import_export/__init__.py=utf-8 +encoding//xmind/utils.py=utf-8 +encoding/setup.py=utf-8 diff --git a/xmind/import_export_filters/ExportFilter.py b/xmind/import_export/ExportFilter.py similarity index 89% rename from xmind/import_export_filters/ExportFilter.py rename to xmind/import_export/ExportFilter.py index 5f79d11..d3c8fd1 100644 --- a/xmind/import_export_filters/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -5,7 +5,7 @@ ~~~~~~~~~~~ :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing XMind files to other formats (e.g: GraphViz). - :copyright: + :copyright: Michel Kern :license: MIT """ @@ -15,19 +15,21 @@ import os.path FILE_NOT_FOUND_ERROR = 1 - -class ExportFilter: + +class ExportFilter(): def __init__(self): self.name = "export_filter" #---------- export() ---------- def export(self, source_path, target_path): + print("ExportFilter.export'" + self.name + "'") print("export_filter.name: '" + self.name + "'") if (not os.path.isfile(source_path)): print("source_path: '" + source_path + "' not found") exit(FILE_NOT_FOUND_ERROR) #---------- export() + #======================== main ======================== def main(): print("** xmind.ExportFilter **") diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py new file mode 100644 index 0000000..c6899f7 --- /dev/null +++ b/xmind/import_export/GraphvizExportFilter.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.import_export_filters.ExportFilter + ~~~~~~~~~~~ + :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + XMind files to other formats (e.g: GraphViz). + :copyright: Michel Kern + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +import os +import os.path +from ExportFilter import ExportFilter +from ExportFilter import FILE_NOT_FOUND_ERROR + +#------------------- GraphvizExportFilter ------------------- +class GraphvizExportFilter(ExportFilter): + def __init__(self): + ExportFilter.__init__(self) + self.name = "graphviz_export_filter" + + #---------- export() ---------- + def export(self, source_path, target_path): + print(self.name + ".export ") + print("export_filter.name: '" + self.name + "'") + if (not os.path.isfile(source_path)): + print("source_path: '" + source_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + #---------- export() +#------------------- GraphvizExportFilter + +#======================== main ======================== +def main(): + print("** xmind.GraphvizExportFilter **") + export_filter = GraphvizExportFilter() + export_filter.export("", "") + #pass + +if __name__ == '__main__': + main() diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py new file mode 100644 index 0000000..4772be1 --- /dev/null +++ b/xmind/import_export/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.core.import_export + ~~~~~~~~~~ + :copyright: Michel Kern + :license: MIT + +""" +__author__ = "echopraxium@yahoo.com " + +#======================== main ======================== +def main(): + print("** xmind.__init__ **") + +if __name__ == '__main__': + main() From d3ac1240b63bb800d53326485929b9a623b2bcb6 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 15:56:59 +0100 Subject: [PATCH 04/30] 3 --- xmind/import_export/ExportFilter.py | 82 ++++++++++---------- xmind/import_export/GraphvizExportFilter.py | 86 ++++++++++----------- xmind/import_export/__init__.py | 34 ++++---- 3 files changed, 101 insertions(+), 101 deletions(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index d3c8fd1..f7f19f7 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -1,41 +1,41 @@ -#!/usr/bin/env python -#-*- coding: utf-8 -*- -""" - xmind.import_export_filters.ExportFilter - ~~~~~~~~~~~ - :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing - XMind files to other formats (e.g: GraphViz). - :copyright: Michel Kern - :license: MIT -""" - -__author__ = "echopraxium@yahoo.com " - -import os -import os.path - -FILE_NOT_FOUND_ERROR = 1 - -class ExportFilter(): - def __init__(self): - self.name = "export_filter" - - #---------- export() ---------- - def export(self, source_path, target_path): - print("ExportFilter.export'" + self.name + "'") - print("export_filter.name: '" + self.name + "'") - if (not os.path.isfile(source_path)): - print("source_path: '" + source_path + "' not found") - exit(FILE_NOT_FOUND_ERROR) - #---------- export() - - -#======================== main ======================== -def main(): - print("** xmind.ExportFilter **") - export_filter = ExportFilter() - export_filter.export("", "") - #pass - -if __name__ == '__main__': - main() +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.import_export_filters.ExportFilter + ~~~~~~~~~~~ + :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + XMind files to other formats (e.g: GraphViz). + :copyright: Michel Kern + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +import os +import os.path + +FILE_NOT_FOUND_ERROR = 1 + +class ExportFilter(): + def __init__(self): + self.name = "export_filter" + + #---------- export() ---------- + def export(self, source_path, target_path): + print("ExportFilter.export'" + self.name + "'") + print("export_filter.name: '" + self.name + "'") + if (not os.path.isfile(source_path)): + print("source_path: '" + source_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + #---------- export() + + +#======================== main ======================== +def main(): + print("** xmind.ExportFilter **") + export_filter = ExportFilter() + export_filter.export("", "") + #pass + +if __name__ == '__main__': + main() diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index c6899f7..0509497 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -1,43 +1,43 @@ -#!/usr/bin/env python -#-*- coding: utf-8 -*- -""" - xmind.import_export_filters.ExportFilter - ~~~~~~~~~~~ - :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing - XMind files to other formats (e.g: GraphViz). - :copyright: Michel Kern - :license: MIT -""" - -__author__ = "echopraxium@yahoo.com " - -import os -import os.path -from ExportFilter import ExportFilter -from ExportFilter import FILE_NOT_FOUND_ERROR - -#------------------- GraphvizExportFilter ------------------- -class GraphvizExportFilter(ExportFilter): - def __init__(self): - ExportFilter.__init__(self) - self.name = "graphviz_export_filter" - - #---------- export() ---------- - def export(self, source_path, target_path): - print(self.name + ".export ") - print("export_filter.name: '" + self.name + "'") - if (not os.path.isfile(source_path)): - print("source_path: '" + source_path + "' not found") - exit(FILE_NOT_FOUND_ERROR) - #---------- export() -#------------------- GraphvizExportFilter - -#======================== main ======================== -def main(): - print("** xmind.GraphvizExportFilter **") - export_filter = GraphvizExportFilter() - export_filter.export("", "") - #pass - -if __name__ == '__main__': - main() +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.import_export_filters.ExportFilter + ~~~~~~~~~~~ + :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + XMind files to other formats (e.g: GraphViz). + :copyright: Michel Kern + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +import os +import os.path +from ExportFilter import ExportFilter +from ExportFilter import FILE_NOT_FOUND_ERROR + +#------------------- GraphvizExportFilter ------------------- +class GraphvizExportFilter(ExportFilter): + def __init__(self): + ExportFilter.__init__(self) + self.name = "graphviz_export_filter" + + #---------- export() ---------- + def export(self, source_path, target_path): + print(self.name + ".export ") + print("export_filter.name: '" + self.name + "'") + if (not os.path.isfile(source_path)): + print("source_path: '" + source_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + #---------- export() +#------------------- GraphvizExportFilter + +#======================== main ======================== +def main(): + print("** xmind.GraphvizExportFilter **") + export_filter = GraphvizExportFilter() + export_filter.export("", "") + #pass + +if __name__ == '__main__': + main() diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index 4772be1..7f30f0b 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -1,17 +1,17 @@ -#!/usr/bin/env python -#-*- coding: utf-8 -*- -""" - xmind.core.import_export - ~~~~~~~~~~ - :copyright: Michel Kern - :license: MIT - -""" -__author__ = "echopraxium@yahoo.com " - -#======================== main ======================== -def main(): - print("** xmind.__init__ **") - -if __name__ == '__main__': - main() +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.core.import_export + ~~~~~~~~~~ + :copyright: Michel Kern + :license: MIT + +""" +__author__ = "echopraxium@yahoo.com " + +#======================== main ======================== +def main(): + print("** xmind.__init__ **") + +if __name__ == '__main__': + main() From 40ccd4129d99fd93deb835909739f21cab5b9ae4 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 15:59:53 +0100 Subject: [PATCH 05/30] 3 --- xmind/import_export/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index 7f30f0b..3f6c236 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- """ - xmind.core.import_export + xmind.import_export ~~~~~~~~~~ :copyright: Michel Kern :license: MIT From 86b6bac3ec25090cb91f6818d9857571484cc5c8 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 16:01:26 +0100 Subject: [PATCH 06/30] 4 --- xmind/import_export/ExportFilter.py | 3 +-- xmind/import_export/GraphvizExportFilter.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index f7f19f7..e74031a 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -22,8 +22,7 @@ def __init__(self): #---------- export() ---------- def export(self, source_path, target_path): - print("ExportFilter.export'" + self.name + "'") - print("export_filter.name: '" + self.name + "'") + print(self.name + ".export ") if (not os.path.isfile(source_path)): print("source_path: '" + source_path + "' not found") exit(FILE_NOT_FOUND_ERROR) diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 0509497..6a77fd2 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -25,7 +25,6 @@ def __init__(self): #---------- export() ---------- def export(self, source_path, target_path): print(self.name + ".export ") - print("export_filter.name: '" + self.name + "'") if (not os.path.isfile(source_path)): print("source_path: '" + source_path + "' not found") exit(FILE_NOT_FOUND_ERROR) From 5636560ca8ba7cca25ab034f6f04e948a6b3bb99 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 16:04:50 +0100 Subject: [PATCH 07/30] 5 --- xmind/import_export/ExportFilter.py | 5 +++-- xmind/import_export/GraphvizExportFilter.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index e74031a..fcb10f5 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -1,7 +1,7 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- """ - xmind.import_export_filters.ExportFilter + xmind.import_export.ExportFilter ~~~~~~~~~~~ :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing XMind files to other formats (e.g: GraphViz). @@ -16,6 +16,7 @@ FILE_NOT_FOUND_ERROR = 1 +#------------------- ExportFilter ------------------- class ExportFilter(): def __init__(self): self.name = "export_filter" @@ -27,7 +28,7 @@ def export(self, source_path, target_path): print("source_path: '" + source_path + "' not found") exit(FILE_NOT_FOUND_ERROR) #---------- export() - +#------------------- ExportFilter #======================== main ======================== def main(): diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 6a77fd2..270000c 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -3,7 +3,7 @@ """ xmind.import_export_filters.ExportFilter ~~~~~~~~~~~ - :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting / importing XMind files to other formats (e.g: GraphViz). :copyright: Michel Kern :license: MIT From ab28ba7d922670df5cc95b19a4aeef523c51fe67 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 21:40:31 +0100 Subject: [PATCH 08/30] 6 --- xmind/import_export/ExportFilter.py | 3 +- xmind/import_export/GraphvizExportFilter.py | 106 ++++++++++++++++++-- 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index fcb10f5..1da5bd0 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -14,7 +14,8 @@ import os import os.path -FILE_NOT_FOUND_ERROR = 1 +FILE_NOT_FOUND_ERROR = 1 +EMPTY_OUTPUT_FILE_PATH_ERROR = 2 #------------------- ExportFilter ------------------- class ExportFilter(): diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 270000c..df1931c 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -1,10 +1,11 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- """ - xmind.import_export_filters.ExportFilter + xmind.import_export_filters.GraphvizExportFilter ~~~~~~~~~~~ - :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting / importing - XMind files to other formats (e.g: GraphViz). + :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting + XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) + GraphViz (http://www.graphviz.org/) :copyright: Michel Kern :license: MIT """ @@ -13,21 +14,113 @@ import os import os.path +import xmind +from xmind.core import workbook,saver +from xmind.core.topic import TopicElement from ExportFilter import ExportFilter -from ExportFilter import FILE_NOT_FOUND_ERROR +from ExportFilter import FILE_NOT_FOUND_ERROR, EMPTY_OUTPUT_FILE_PATH_ERROR #------------------- GraphvizExportFilter ------------------- class GraphvizExportFilter(ExportFilter): + #---------- constructor ---------- def __init__(self): ExportFilter.__init__(self) self.name = "graphviz_export_filter" + self.output_str = '' + self.topic_count = 0 + + #---------- traverse() ---------- + def getOutput(self): + return self.output_str #---------- export() ---------- def export(self, source_path, target_path): print(self.name + ".export ") + if (not os.path.isfile(source_path)): - print("source_path: '" + source_path + "' not found") + print("> *ERROR* source_path: '" + source_path + "' not found") exit(FILE_NOT_FOUND_ERROR) + + # load an existing file or create a new workbook if nothing is found + workbook = xmind.load(source_path) + worksheet = workbook.getPrimarySheet() # get the first sheet + root_topic = worksheet.getRootTopic() # get the root topic of this sheet + + self.generateGraphvizDotString(root_topic) + self.writeGraphvizDotToFile(target_path) + self.generateImageFile(target_path, 'out.pdf') + + print(">> export done") + + #---------- generateGraphvizDotString() ---------- + def generateGraphvizDotString(self, root_topic): + self.output_str = u"digraph G {\n" + + self.output_str = self.output_str + u"ranksep=2.8;\n" + self.output_str = self.output_str + u"ratio=auto;\n" + + self.traverse(root_topic) + self.output_str = self.output_str + u"}" + #---------- generateGraphvizDotString() + + #---------- writeGraphvizDotToFile() ---------- + def writeGraphvizDotToFile(self, target_path): + if (target_path == ''): + print("> *ERROR* target_path is empty") + exit(EMPTY_OUTPUT_FILE_PATH_ERROR) + + out_fd = open(target_path, "w") + out_fd.write(self.output_str.encode(('utf8'))) + out_fd.close() + #---------- writeGraphvizDotToFile() + + #---------- generateImageFile() ---------- + def generateImageFile(self, dot_input_path, img_output_path): + if (img_output_path == ''): + print("> *ERROR* output_path is empty") + exit(EMPTY_OUTPUT_FILE_PATH_ERROR) + + graphviz_tool = 'dot' + graphviz_tool = 'twopi' + graphviz_dot_path = 'C:\\Program Files (x86)\\Graphviz\\bin\\' + graphviz_tool + '.exe' + if (not os.path.isfile(graphviz_dot_path)): + print("> *ERROR* Graphviz dot.exe: '" + graphviz_dot_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + + # dot -Tps -l lib.ps file.gv -o file.ps + print(os.getcwd()) + cmd = '\"' + graphviz_dot_path + '\" -Tpdf ' + dot_input_path + ' -o ' + img_output_path + print(cmd) + os.system(cmd) + #---------- generateImageFile() + + #---------- traverse() ---------- + def traverse(self, topic, parent_id='', parent_index=0, level=0): + self.topic_count = self.topic_count + 1 + topic_index = self.topic_count + + if (parent_id != ''): + topic_id = u'topic_' + str(parent_index) + '_' + str(topic_index) + self.output_str = self.output_str + u' ' + parent_id + u'->' + topic_id + u';\n' + else: + topic_id = u'topic_' + str(topic_index) + + indent = ' ' * (level * 2) + topic_title = unicode(topic.getTitle()) + + msg = indent + '> ' + str(level) + ': ' + topic_title + self.output_str = self.output_str + u' ' + topic_id + u' [label=\"' + topic_title + u'\"];\n' + + topics = topic.getSubTopics() + + if (topics == None): + print(msg + ' is a LEAF') + return + else: + print(msg) + + for child_topic in topics: + self.traverse(child_topic, topic_id, topic_index, level+1) #---------- export() #------------------- GraphvizExportFilter @@ -35,7 +128,8 @@ def export(self, source_path, target_path): def main(): print("** xmind.GraphvizExportFilter **") export_filter = GraphvizExportFilter() - export_filter.export("", "") + export_filter.export("../test/test.xmind", "map.dot") + print(export_filter.getOutput()) #pass if __name__ == '__main__': From 5735dc90f3e21b32d02aef8bc138fe55e7257673 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 24 Nov 2015 21:42:38 +0100 Subject: [PATCH 09/30] Create t.txt --- xmind/test/t.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 xmind/test/t.txt diff --git a/xmind/test/t.txt b/xmind/test/t.txt new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/xmind/test/t.txt @@ -0,0 +1 @@ +test From be1f3ef183566aa2cc2a2301ea139bc0c8f465a9 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Wed, 25 Nov 2015 11:06:46 +0100 Subject: [PATCH 10/30] 7 --- xmind/import_export/GraphvizExportFilter.py | 44 +++++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index df1931c..103a532 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -56,8 +56,12 @@ def export(self, source_path, target_path): def generateGraphvizDotString(self, root_topic): self.output_str = u"digraph G {\n" - self.output_str = self.output_str + u"ranksep=2.8;\n" - self.output_str = self.output_str + u"ratio=auto;\n" + #self.output_str = self.output_str + u' overlap=scalexy;'; + #self.output_str = self.output_str + u' ranksep=3;\n' + #self.output_str = self.output_str + u' ratio=auto;\n' + + self.output_str = self.output_str + u'root=topic_1;' + self.output_str = self.output_str + u'overlap=false;'; self.traverse(root_topic) self.output_str = self.output_str + u"}" @@ -80,7 +84,7 @@ def generateImageFile(self, dot_input_path, img_output_path): print("> *ERROR* output_path is empty") exit(EMPTY_OUTPUT_FILE_PATH_ERROR) - graphviz_tool = 'dot' + #graphviz_tool = 'dot' graphviz_tool = 'twopi' graphviz_dot_path = 'C:\\Program Files (x86)\\Graphviz\\bin\\' + graphviz_tool + '.exe' if (not os.path.isfile(graphviz_dot_path)): @@ -109,7 +113,39 @@ def traverse(self, topic, parent_id='', parent_index=0, level=0): topic_title = unicode(topic.getTitle()) msg = indent + '> ' + str(level) + ': ' + topic_title - self.output_str = self.output_str + u' ' + topic_id + u' [label=\"' + topic_title + u'\"];\n' + + font_size = 30 - level*2.5 + shape_attribute = ' shape=box, ' + + # http://rich-iannone.github.io/DiagrammeR/graphviz.html + color_attribute = ' style=filled, color=Beige, ' + + if (level == 0): + font_size = 35 + shape_attribute = ' shape=box, margin=\"0.2,0.1\", ' + elif (level == 1): + font_size = 30 + shape_attribute = ' shape=box, margin=\"0.2,0.07\", ' + else: + font_size = 30 - level*2.5 + shape_attribute = ' shape=plaintext, ' + color_attribute = ' style=filled, color=LightCyan, ' + + font_attribute = u'fontname = \"Helvetica\", fontsize = ' + str(font_size) + ', ' + + if (len(topic_title) > 15): + words = topic_title.split(' ') + word_count = len(words) + multiline_topic_title= '' + word_index = 0 + for word in words: + multiline_topic_title = multiline_topic_title + word[word_index] + + label_attribute = ' label=\"' + topic_title + '\", ' + + self.output_str = self.output_str + u' ' + topic_id + u' [' + self.output_str = self.output_str + font_attribute + label_attribute + shape_attribute + color_attribute + self.output_str = self.output_str + u' ];\n' topics = topic.getSubTopics() From 552fe9812c9bbb5cb8d7b78898fe0f494249640c Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Wed, 25 Nov 2015 21:10:38 +0100 Subject: [PATCH 11/30] Removed folder from repository --- xmind/test/t.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 xmind/test/t.txt diff --git a/xmind/test/t.txt b/xmind/test/t.txt deleted file mode 100644 index 9daeafb..0000000 --- a/xmind/test/t.txt +++ /dev/null @@ -1 +0,0 @@ -test From 2e0ca259c90a6281b30a41c19b7e0707dca0159d Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Thu, 26 Nov 2015 00:16:15 +0100 Subject: [PATCH 12/30] 9 --- xmind/import_export/GraphvizExportFilter.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 103a532..18fd6f0 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -48,7 +48,7 @@ def export(self, source_path, target_path): self.generateGraphvizDotString(root_topic) self.writeGraphvizDotToFile(target_path) - self.generateImageFile(target_path, 'out.pdf') + self.generateImageFile(target_path, '../data/out.pdf') print(">> export done") @@ -133,13 +133,13 @@ def traverse(self, topic, parent_id='', parent_index=0, level=0): font_attribute = u'fontname = \"Helvetica\", fontsize = ' + str(font_size) + ', ' - if (len(topic_title) > 15): - words = topic_title.split(' ') - word_count = len(words) - multiline_topic_title= '' - word_index = 0 - for word in words: - multiline_topic_title = multiline_topic_title + word[word_index] + #if (len(topic_title) > 15): + # words = topic_title.split(' ') + # word_count = len(words) + # multiline_topic_title= '' + # word_index = 0 + # for word in words: + # multiline_topic_title = multiline_topic_title + word[word_index] label_attribute = ' label=\"' + topic_title + '\", ' @@ -164,7 +164,7 @@ def traverse(self, topic, parent_id='', parent_index=0, level=0): def main(): print("** xmind.GraphvizExportFilter **") export_filter = GraphvizExportFilter() - export_filter.export("../test/test.xmind", "map.dot") + export_filter.export("../data/Hindouisme.xmind", "../data/map.dot") print(export_filter.getOutput()) #pass From 4e7523e2b6fe89574b3b7040e0d26117b5f707cc Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Thu, 26 Nov 2015 00:17:23 +0100 Subject: [PATCH 13/30] Create t.txt --- xmind/data/t.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 xmind/data/t.txt diff --git a/xmind/data/t.txt b/xmind/data/t.txt new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/xmind/data/t.txt @@ -0,0 +1 @@ +test From 97b1ba7acb46bef8e7876d838d8fe50cb06005fd Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 15:42:02 +0100 Subject: [PATCH 14/30] Create __init__.py --- xmind/framework/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 xmind/framework/__init__.py diff --git a/xmind/framework/__init__.py b/xmind/framework/__init__.py new file mode 100644 index 0000000..e382d5c --- /dev/null +++ b/xmind/framework/__init__.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.framework + --------------- + :copyright: Michel Kern + :license: MIT + +""" +__author__ = "echopraxium@yahoo.com " + +#======================== main ======================== +def main(): + print("** xmind.framework module **") + +if __name__ == '__main__': + main() From 69e8a937cb006e920c0beb8ece088855c776c313 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 15:51:08 +0100 Subject: [PATCH 15/30] Create Enum.py --- xmind/framework/Enum.py | 74 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 xmind/framework/Enum.py diff --git a/xmind/framework/Enum.py b/xmind/framework/Enum.py new file mode 100644 index 0000000..0d7696a --- /dev/null +++ b/xmind/framework/Enum.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.framework.Enum + -------------------- + :mod:``xmind.framework.Enum`` provides an support for an enumerated type + :copyright: http://code.activestate.com/recipes/413486-first-class-enums-in-python/ + :copyright: Zoran Isailovski + :license: PSF + :note: source code copied from 'First Class Enums in Python (Python recipe)': + http://code.activestate.com/recipes/413486-first-class-enums-in-python/ +""" + +__author__ = "http://code.activestate.com/recipes/users/2400454/ " + +#------------------- Enum ------------------- +def Enum(*names): + ##assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment! + + class EnumClass(object): + __slots__ = names + def __iter__(self): return iter(constants) + def __len__(self): return len(constants) + def __getitem__(self, i): return constants[i] + def __repr__(self): return 'Enum' + str(names) + def __str__(self): return 'enum ' + str(constants) + + class EnumValue(object): + __slots__ = ('__value') + def __init__(self, value): self.__value = value + Value = property(lambda self: self.__value) + EnumType = property(lambda self: EnumType) + def __hash__(self): return hash(self.__value) + def __cmp__(self, other): + # C fans might want to remove the following assertion + # to make all enums comparable by ordinal value {;)) + assert self.EnumType is other.EnumType, "Only values from the same enum are comparable" + return cmp(self.__value, other.__value) + def __invert__(self): return constants[maximum - self.__value] + def __nonzero__(self): return bool(self.__value) + def __repr__(self): return str(names[self.__value]) + + maximum = len(names) - 1 + constants = [None] * len(names) + for i, each in enumerate(names): + val = EnumValue(i) + setattr(EnumClass, each, val) + constants[i] = val + constants = tuple(constants) + EnumType = EnumClass() + return EnumType +#------------------- Enum + +#======================== main ======================== +def main(): + print("** xmind.framework.Enum **") + + print '\n*** Enum Demo ***' + print '--- Days of week ---' + Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su') + print Days + print Days.Mo + print Days.Fr + print Days.Mo < Days.Fr + print list(Days) + for each in Days: + print 'Day:', each + print '--- Yes/No ---' + Confirmation = Enum('No', 'Yes') + answer = Confirmation.No + print 'Your answer is not', ~answer + +if __name__ == '__main__': + main() From 89d529d08ad9014d86e82328ffd5ccbfab109202 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 15:52:40 +0100 Subject: [PATCH 16/30] Update ExportFilter.py --- xmind/import_export/ExportFilter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index 1da5bd0..7facc92 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -2,11 +2,11 @@ #-*- coding: utf-8 -*- """ xmind.import_export.ExportFilter - ~~~~~~~~~~~ - :mod:``xmind.import_export_filters.ExportFilter`` provide a handy way for exporting / importing + -------------------------------- + :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting / importing XMind files to other formats (e.g: GraphViz). :copyright: Michel Kern - :license: MIT + :license: MIT """ __author__ = "echopraxium@yahoo.com " @@ -40,3 +40,4 @@ def main(): if __name__ == '__main__': main() + From af497aea742ea13bc4ff4895d365c82e1cfb5810 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 15:54:42 +0100 Subject: [PATCH 17/30] Update GraphvizExportFilter.py --- xmind/import_export/GraphvizExportFilter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 18fd6f0..39d3318 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -1,13 +1,14 @@ + #!/usr/bin/env python #-*- coding: utf-8 -*- """ - xmind.import_export_filters.GraphvizExportFilter - ~~~~~~~~~~~ + xmind.import_export.GraphvizExportFilter + ---------------------------------------- :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) GraphViz (http://www.graphviz.org/) :copyright: Michel Kern - :license: MIT + :license: MIT """ __author__ = "echopraxium@yahoo.com " From 487a34ca6cf2aa407bde3bc5af81f0e90ba0631d Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 22:36:37 +0100 Subject: [PATCH 18/30] 12 --- .settings/org.eclipse.core.resources.prefs | 2 + xmind/import_export/GraphvizExportFilter.py | 173 -------------------- xmind/import_export/__init__.py | 6 +- 3 files changed, 5 insertions(+), 176 deletions(-) delete mode 100644 xmind/import_export/GraphvizExportFilter.py diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 93b13f4..0dafa3a 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -4,6 +4,8 @@ encoding//xmind/core/__init__.py=utf-8 encoding//xmind/core/const.py=utf-8 encoding//xmind/core/notes.py=utf-8 encoding//xmind/core/workbook.py=utf-8 +encoding//xmind/framework/Enum.py=utf-8 +encoding//xmind/framework/__init__.py=utf-8 encoding//xmind/import_export/ExportFilter.py=utf-8 encoding//xmind/import_export/GraphvizExportFilter.py=utf-8 encoding//xmind/import_export/__init__.py=utf-8 diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py deleted file mode 100644 index 39d3318..0000000 --- a/xmind/import_export/GraphvizExportFilter.py +++ /dev/null @@ -1,173 +0,0 @@ - -#!/usr/bin/env python -#-*- coding: utf-8 -*- -""" - xmind.import_export.GraphvizExportFilter - ---------------------------------------- - :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting - XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) - GraphViz (http://www.graphviz.org/) - :copyright: Michel Kern - :license: MIT -""" - -__author__ = "echopraxium@yahoo.com " - -import os -import os.path -import xmind -from xmind.core import workbook,saver -from xmind.core.topic import TopicElement -from ExportFilter import ExportFilter -from ExportFilter import FILE_NOT_FOUND_ERROR, EMPTY_OUTPUT_FILE_PATH_ERROR - -#------------------- GraphvizExportFilter ------------------- -class GraphvizExportFilter(ExportFilter): - #---------- constructor ---------- - def __init__(self): - ExportFilter.__init__(self) - self.name = "graphviz_export_filter" - self.output_str = '' - self.topic_count = 0 - - #---------- traverse() ---------- - def getOutput(self): - return self.output_str - - #---------- export() ---------- - def export(self, source_path, target_path): - print(self.name + ".export ") - - if (not os.path.isfile(source_path)): - print("> *ERROR* source_path: '" + source_path + "' not found") - exit(FILE_NOT_FOUND_ERROR) - - # load an existing file or create a new workbook if nothing is found - workbook = xmind.load(source_path) - worksheet = workbook.getPrimarySheet() # get the first sheet - root_topic = worksheet.getRootTopic() # get the root topic of this sheet - - self.generateGraphvizDotString(root_topic) - self.writeGraphvizDotToFile(target_path) - self.generateImageFile(target_path, '../data/out.pdf') - - print(">> export done") - - #---------- generateGraphvizDotString() ---------- - def generateGraphvizDotString(self, root_topic): - self.output_str = u"digraph G {\n" - - #self.output_str = self.output_str + u' overlap=scalexy;'; - #self.output_str = self.output_str + u' ranksep=3;\n' - #self.output_str = self.output_str + u' ratio=auto;\n' - - self.output_str = self.output_str + u'root=topic_1;' - self.output_str = self.output_str + u'overlap=false;'; - - self.traverse(root_topic) - self.output_str = self.output_str + u"}" - #---------- generateGraphvizDotString() - - #---------- writeGraphvizDotToFile() ---------- - def writeGraphvizDotToFile(self, target_path): - if (target_path == ''): - print("> *ERROR* target_path is empty") - exit(EMPTY_OUTPUT_FILE_PATH_ERROR) - - out_fd = open(target_path, "w") - out_fd.write(self.output_str.encode(('utf8'))) - out_fd.close() - #---------- writeGraphvizDotToFile() - - #---------- generateImageFile() ---------- - def generateImageFile(self, dot_input_path, img_output_path): - if (img_output_path == ''): - print("> *ERROR* output_path is empty") - exit(EMPTY_OUTPUT_FILE_PATH_ERROR) - - #graphviz_tool = 'dot' - graphviz_tool = 'twopi' - graphviz_dot_path = 'C:\\Program Files (x86)\\Graphviz\\bin\\' + graphviz_tool + '.exe' - if (not os.path.isfile(graphviz_dot_path)): - print("> *ERROR* Graphviz dot.exe: '" + graphviz_dot_path + "' not found") - exit(FILE_NOT_FOUND_ERROR) - - # dot -Tps -l lib.ps file.gv -o file.ps - print(os.getcwd()) - cmd = '\"' + graphviz_dot_path + '\" -Tpdf ' + dot_input_path + ' -o ' + img_output_path - print(cmd) - os.system(cmd) - #---------- generateImageFile() - - #---------- traverse() ---------- - def traverse(self, topic, parent_id='', parent_index=0, level=0): - self.topic_count = self.topic_count + 1 - topic_index = self.topic_count - - if (parent_id != ''): - topic_id = u'topic_' + str(parent_index) + '_' + str(topic_index) - self.output_str = self.output_str + u' ' + parent_id + u'->' + topic_id + u';\n' - else: - topic_id = u'topic_' + str(topic_index) - - indent = ' ' * (level * 2) - topic_title = unicode(topic.getTitle()) - - msg = indent + '> ' + str(level) + ': ' + topic_title - - font_size = 30 - level*2.5 - shape_attribute = ' shape=box, ' - - # http://rich-iannone.github.io/DiagrammeR/graphviz.html - color_attribute = ' style=filled, color=Beige, ' - - if (level == 0): - font_size = 35 - shape_attribute = ' shape=box, margin=\"0.2,0.1\", ' - elif (level == 1): - font_size = 30 - shape_attribute = ' shape=box, margin=\"0.2,0.07\", ' - else: - font_size = 30 - level*2.5 - shape_attribute = ' shape=plaintext, ' - color_attribute = ' style=filled, color=LightCyan, ' - - font_attribute = u'fontname = \"Helvetica\", fontsize = ' + str(font_size) + ', ' - - #if (len(topic_title) > 15): - # words = topic_title.split(' ') - # word_count = len(words) - # multiline_topic_title= '' - # word_index = 0 - # for word in words: - # multiline_topic_title = multiline_topic_title + word[word_index] - - label_attribute = ' label=\"' + topic_title + '\", ' - - self.output_str = self.output_str + u' ' + topic_id + u' [' - self.output_str = self.output_str + font_attribute + label_attribute + shape_attribute + color_attribute - self.output_str = self.output_str + u' ];\n' - - topics = topic.getSubTopics() - - if (topics == None): - print(msg + ' is a LEAF') - return - else: - print(msg) - - for child_topic in topics: - self.traverse(child_topic, topic_id, topic_index, level+1) - #---------- export() -#------------------- GraphvizExportFilter - -#======================== main ======================== -def main(): - print("** xmind.GraphvizExportFilter **") - export_filter = GraphvizExportFilter() - export_filter.export("../data/Hindouisme.xmind", "../data/map.dot") - print(export_filter.getOutput()) - #pass - -if __name__ == '__main__': - main() diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index 3f6c236..cff719a 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -2,16 +2,16 @@ #-*- coding: utf-8 -*- """ xmind.import_export - ~~~~~~~~~~ + ------------------- :copyright: Michel Kern - :license: MIT + :license: MIT """ __author__ = "echopraxium@yahoo.com " #======================== main ======================== def main(): - print("** xmind.__init__ **") + print("** xmind.import_export module **") if __name__ == '__main__': main() From 0a76fcf6656b82c430d5d2da5d74db45ab23bd3b Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 22:44:44 +0100 Subject: [PATCH 19/30] 14 --- xmind/framework/__init__.py | 5 ++++- xmind/import_export/__init__.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/xmind/framework/__init__.py b/xmind/framework/__init__.py index e382d5c..c2ff936 100644 --- a/xmind/framework/__init__.py +++ b/xmind/framework/__init__.py @@ -2,13 +2,16 @@ #-*- coding: utf-8 -*- """ xmind.framework - --------------- + ~~~~~~~~~~ :copyright: Michel Kern :license: MIT """ __author__ = "echopraxium@yahoo.com " +def test(): + return + #======================== main ======================== def main(): print("** xmind.framework module **") diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index cff719a..6f9cdf1 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -1,8 +1,8 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- """ - xmind.import_export - ------------------- + xmind.import_export module + -------------------------- :copyright: Michel Kern :license: MIT From 1ae043a58e75a811e13756c6343b9b66ce56a3d7 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 22:50:05 +0100 Subject: [PATCH 20/30] 14 --- xmind/import_export/GraphvizExportFilter.py | 172 ++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 xmind/import_export/GraphvizExportFilter.py diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py new file mode 100644 index 0000000..ecab6b5 --- /dev/null +++ b/xmind/import_export/GraphvizExportFilter.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.import_export.GraphvizExportFilter + ---------------------------------------- + :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting + XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) + GraphViz (http://www.graphviz.org/) + :copyright: Michel Kern + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +import os +import os.path +import xmind +from xmind.core import workbook,saver +from xmind.core.topic import TopicElement +from ExportFilter import ExportFilter +from ExportFilter import FILE_NOT_FOUND_ERROR, EMPTY_OUTPUT_FILE_PATH_ERROR + +#------------------- GraphvizExportFilter ------------------- +class GraphvizExportFilter(ExportFilter): + #---------- constructor ---------- + def __init__(self): + ExportFilter.__init__(self) + self.name = "graphviz_export_filter" + self.output_str = '' + self.topic_count = 0 + + #---------- traverse() ---------- + def getOutput(self): + return self.output_str + + #---------- export() ---------- + def export(self, source_path, target_path): + print(self.name + ".export ") + + if (not os.path.isfile(source_path)): + print("> *ERROR* source_path: '" + source_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + + # load an existing file or create a new workbook if nothing is found + workbook = xmind.load(source_path) + worksheet = workbook.getPrimarySheet() # get the first sheet + root_topic = worksheet.getRootTopic() # get the root topic of this sheet + + self.generateGraphvizDotString(root_topic) + self.writeGraphvizDotToFile(target_path) + self.generateImageFile(target_path, '../data/out.pdf') + + print(">> export done") + + #---------- generateGraphvizDotString() ---------- + def generateGraphvizDotString(self, root_topic): + self.output_str = u"digraph G {\n" + + #self.output_str = self.output_str + u' overlap=scalexy;'; + #self.output_str = self.output_str + u' ranksep=3;\n' + #self.output_str = self.output_str + u' ratio=auto;\n' + + self.output_str = self.output_str + u'root=topic_1;' + self.output_str = self.output_str + u'overlap=false;'; + + self.traverse(root_topic) + self.output_str = self.output_str + u"}" + #---------- generateGraphvizDotString() + + #---------- writeGraphvizDotToFile() ---------- + def writeGraphvizDotToFile(self, target_path): + if (target_path == ''): + print("> *ERROR* target_path is empty") + exit(EMPTY_OUTPUT_FILE_PATH_ERROR) + + out_fd = open(target_path, "w") + out_fd.write(self.output_str.encode(('utf8'))) + out_fd.close() + #---------- writeGraphvizDotToFile() + + #---------- generateImageFile() ---------- + def generateImageFile(self, dot_input_path, img_output_path): + if (img_output_path == ''): + print("> *ERROR* output_path is empty") + exit(EMPTY_OUTPUT_FILE_PATH_ERROR) + + #graphviz_tool = 'dot' + graphviz_tool = 'twopi' + graphviz_dot_path = 'C:\\Program Files (x86)\\Graphviz\\bin\\' + graphviz_tool + '.exe' + if (not os.path.isfile(graphviz_dot_path)): + print("> *ERROR* Graphviz dot.exe: '" + graphviz_dot_path + "' not found") + exit(FILE_NOT_FOUND_ERROR) + + # dot -Tps -l lib.ps file.gv -o file.ps + print(os.getcwd()) + cmd = '\"' + graphviz_dot_path + '\" -Tpdf ' + dot_input_path + ' -o ' + img_output_path + print(cmd) + os.system(cmd) + #---------- generateImageFile() + + #---------- traverse() ---------- + def traverse(self, topic, parent_id='', parent_index=0, level=0): + self.topic_count = self.topic_count + 1 + topic_index = self.topic_count + + if (parent_id != ''): + topic_id = u'topic_' + str(parent_index) + '_' + str(topic_index) + self.output_str = self.output_str + u' ' + parent_id + u'->' + topic_id + u';\n' + else: + topic_id = u'topic_' + str(topic_index) + + indent = ' ' * (level * 2) + topic_title = unicode(topic.getTitle()) + + msg = indent + '> ' + str(level) + ': ' + topic_title + + font_size = 30 - level*2.5 + shape_attribute = ' shape=box, ' + + # http://rich-iannone.github.io/DiagrammeR/graphviz.html + color_attribute = ' style=filled, color=Beige, ' + + if (level == 0): + font_size = 35 + shape_attribute = ' shape=box, margin=\"0.2,0.1\", ' + elif (level == 1): + font_size = 30 + shape_attribute = ' shape=box, margin=\"0.2,0.07\", ' + else: + font_size = 30 - level*2.5 + shape_attribute = ' shape=plaintext, ' + color_attribute = ' style=filled, color=LightCyan, ' + + font_attribute = u'fontname = \"Helvetica\", fontsize = ' + str(font_size) + ', ' + + #if (len(topic_title) > 15): + # words = topic_title.split(' ') + # word_count = len(words) + # multiline_topic_title= '' + # word_index = 0 + # for word in words: + # multiline_topic_title = multiline_topic_title + word[word_index] + + label_attribute = ' label=\"' + topic_title + '\", ' + + self.output_str = self.output_str + u' ' + topic_id + u' [' + self.output_str = self.output_str + font_attribute + label_attribute + shape_attribute + color_attribute + self.output_str = self.output_str + u' ];\n' + + topics = topic.getSubTopics() + + if (topics == None): + print(msg + ' is a LEAF') + return + else: + print(msg) + + for child_topic in topics: + self.traverse(child_topic, topic_id, topic_index, level+1) + #---------- export() +#------------------- GraphvizExportFilter + +#======================== main ======================== +def main(): + print("** xmind.GraphvizExportFilter **") + export_filter = GraphvizExportFilter() + export_filter.export("../data/Hindouisme.xmind", "../data/map.dot") + print(export_filter.getOutput()) + #pass + +if __name__ == '__main__': + main() \ No newline at end of file From c141d3997266e1905e426959180937653fdef442 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 22:54:30 +0100 Subject: [PATCH 21/30] 15 --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index ea1eba3..043cd8c 100644 --- a/setup.py +++ b/setup.py @@ -5,15 +5,15 @@ setup( name="xmind", - version="0.1a.0", + version="0.0.1", packages=find_packages(), install_requires=["distribute"], - author="Woody Ai", - author_email="aiqi@xmind.net", - description="The offical XMind python SDK", + author="Michel Kern", + author_email="echopraxium@yahoo.com", + description="A fork of XMind python SDK", license="MIT", keywords="XMind, SDK, mind mapping", - url="https://github.com/xmindltd/xmind-sdk-python" + url="https://github.com/Almerxsese/xmind-sdk-python" ) From f1d23f388dbb8982148b4b13d1950a1d00156eeb Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 22:56:13 +0100 Subject: [PATCH 22/30] 16 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 043cd8c..1b1736f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ author="Michel Kern", author_email="echopraxium@yahoo.com", - description="A fork of XMind python SDK", + description="A fork of XMind python SDK with extensions for import / export", license="MIT", keywords="XMind, SDK, mind mapping", url="https://github.com/Almerxsese/xmind-sdk-python" From 3d4fd9f7ed2808dbcf06f0714207ccf0a682e294 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:00:18 +0100 Subject: [PATCH 23/30] 18 --- .settings/org.eclipse.core.resources.prefs | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 0dafa3a..3f11f58 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -10,4 +10,5 @@ encoding//xmind/import_export/ExportFilter.py=utf-8 encoding//xmind/import_export/GraphvizExportFilter.py=utf-8 encoding//xmind/import_export/__init__.py=utf-8 encoding//xmind/utils.py=utf-8 +encoding/example.py=utf-8 encoding/setup.py=utf-8 diff --git a/README.md b/README.md index 029b622..7a0ca10 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#XMind SDK for python +#Fork of XMind SDK for python with extensions for import / import **XMind SDK for python** to help Python developers to easily work with XMind files and build XMind extensions. @@ -6,7 +6,7 @@ Clone the repository to a local working directory - git clone https://github.com/xmindltd/xmind-sdk-python.git + git clone https://github.com/Almerxsese/xmind-sdk-python Now there will be a directory named `xmind-sdk-python` under the current directory. Change to the directory `xmind-sdk-python` and install **XMind SDK for python**. From 2118fa5f5ea72c47ea5cd227ea03dbcf07044ea1 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:04:28 +0100 Subject: [PATCH 24/30] 20 --- xmind/import_export/ExportFilter.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index 7facc92..9969e8e 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -13,9 +13,11 @@ import os import os.path +import xmind.framework.Enum FILE_NOT_FOUND_ERROR = 1 EMPTY_OUTPUT_FILE_PATH_ERROR = 2 +#SDK_ERRORS = Enum('FILE_NOT_FOUND_ERROR', 'EMPTY_OUTPUT_FILE_PATH_ERROR') #------------------- ExportFilter ------------------- class ExportFilter(): @@ -27,7 +29,7 @@ def export(self, source_path, target_path): print(self.name + ".export ") if (not os.path.isfile(source_path)): print("source_path: '" + source_path + "' not found") - exit(FILE_NOT_FOUND_ERROR) + exit(SDK_ERRORS.FILE_NOT_FOUND_ERROR) #---------- export() #------------------- ExportFilter From e4a2269b2407da5dd0c983f62fff8941f930048e Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:11:35 +0100 Subject: [PATCH 25/30] 21 --- .settings/org.eclipse.core.resources.prefs | 1 + setup.py | 4 ++-- xmind/framework/Enum.py | 2 +- xmind/import_export/ExportFilter.py | 2 +- xmind/import_export/GraphvizExportFilter.py | 2 +- xmind/import_export/__init__.py | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 3f11f58..d79d2ef 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -2,6 +2,7 @@ eclipse.preferences.version=1 encoding//xmind/__init__.py=utf-8 encoding//xmind/core/__init__.py=utf-8 encoding//xmind/core/const.py=utf-8 +encoding//xmind/core/loader.py=utf-8 encoding//xmind/core/notes.py=utf-8 encoding//xmind/core/workbook.py=utf-8 encoding//xmind/framework/Enum.py=utf-8 diff --git a/setup.py b/setup.py index 1b1736f..5078ec5 100644 --- a/setup.py +++ b/setup.py @@ -12,8 +12,8 @@ author="Michel Kern", author_email="echopraxium@yahoo.com", - description="A fork of XMind python SDK with extensions for import / export", + description="A fork of XMind python SDK with extensions for import / export (e.g. Graphviz)", license="MIT", - keywords="XMind, SDK, mind mapping", + keywords="XMind, SDK, mind mapping, extension, import, export, graphviz", url="https://github.com/Almerxsese/xmind-sdk-python" ) diff --git a/xmind/framework/Enum.py b/xmind/framework/Enum.py index 0d7696a..10c27e5 100644 --- a/xmind/framework/Enum.py +++ b/xmind/framework/Enum.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ xmind.framework.Enum - -------------------- + ~~~~~~~~~~~~~~~~~ :mod:``xmind.framework.Enum`` provides an support for an enumerated type :copyright: http://code.activestate.com/recipes/413486-first-class-enums-in-python/ :copyright: Zoran Isailovski diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index 9969e8e..e67a0dd 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -13,7 +13,7 @@ import os import os.path -import xmind.framework.Enum +import xmind.framework FILE_NOT_FOUND_ERROR = 1 EMPTY_OUTPUT_FILE_PATH_ERROR = 2 diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index ecab6b5..219e6aa 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ xmind.import_export.GraphvizExportFilter - ---------------------------------------- + ~~~~~~~~~~~~~~~~~ :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) GraphViz (http://www.graphviz.org/) diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index 6f9cdf1..d9e8c17 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ xmind.import_export module - -------------------------- + ~~~~~~~~~~~~~~~~~ :copyright: Michel Kern :license: MIT From 0898a37910fcef2cb608b2a99f326f5142741da8 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:20:32 +0100 Subject: [PATCH 26/30] 22 --- xmind/import_export/ExportFilter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index e67a0dd..8aae7af 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -13,7 +13,7 @@ import os import os.path -import xmind.framework +from xmind.framework import Enum FILE_NOT_FOUND_ERROR = 1 EMPTY_OUTPUT_FILE_PATH_ERROR = 2 From 5046222abda98d2664177150468d278372745572 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:40:52 +0100 Subject: [PATCH 27/30] 22 --- xmind/data/{t.txt => sample_text_file.txt} | 0 xmind/framework/__init__.py | 3 --- xmind/import_export/ExportFilter.py | 10 ++++++---- 3 files changed, 6 insertions(+), 7 deletions(-) rename xmind/data/{t.txt => sample_text_file.txt} (100%) diff --git a/xmind/data/t.txt b/xmind/data/sample_text_file.txt similarity index 100% rename from xmind/data/t.txt rename to xmind/data/sample_text_file.txt diff --git a/xmind/framework/__init__.py b/xmind/framework/__init__.py index c2ff936..261ba6c 100644 --- a/xmind/framework/__init__.py +++ b/xmind/framework/__init__.py @@ -9,9 +9,6 @@ """ __author__ = "echopraxium@yahoo.com " -def test(): - return - #======================== main ======================== def main(): print("** xmind.framework module **") diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index 8aae7af..c743d74 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -13,11 +13,11 @@ import os import os.path -from xmind.framework import Enum +from xmind.framework.Enum import Enum FILE_NOT_FOUND_ERROR = 1 EMPTY_OUTPUT_FILE_PATH_ERROR = 2 -#SDK_ERRORS = Enum('FILE_NOT_FOUND_ERROR', 'EMPTY_OUTPUT_FILE_PATH_ERROR') +RETURN_CODE = Enum('OK', 'FILE_NOT_FOUND_ERROR', 'EMPTY_OUTPUT_FILE_PATH_ERROR') #------------------- ExportFilter ------------------- class ExportFilter(): @@ -29,7 +29,8 @@ def export(self, source_path, target_path): print(self.name + ".export ") if (not os.path.isfile(source_path)): print("source_path: '" + source_path + "' not found") - exit(SDK_ERRORS.FILE_NOT_FOUND_ERROR) + exit(RETURN_CODE.FILE_NOT_FOUND_ERROR) + return RETURN_CODE.OK #---------- export() #------------------- ExportFilter @@ -37,7 +38,8 @@ def export(self, source_path, target_path): def main(): print("** xmind.ExportFilter **") export_filter = ExportFilter() - export_filter.export("", "") + rc = export_filter.export("../data/t.txt", "") + print(rc) #pass if __name__ == '__main__': From c369cbb3dee3df1f97161c75efe8657a7c034361 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Mon, 30 Nov 2015 23:51:41 +0100 Subject: [PATCH 28/30] 24 --- README.md | 8 +++++++- xmind/framework/__init__.py | 2 +- xmind/import_export/ExportFilter.py | 2 +- xmind/import_export/__init__.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a0ca10..7d236d7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Fork of XMind SDK for python with extensions for import / import +#Fork of XMind SDK for python with extensions for import / export (e.g. Graphviz) **XMind SDK for python** to help Python developers to easily work with XMind files and build XMind extensions. @@ -14,6 +14,12 @@ Now there will be a directory named `xmind-sdk-python` under the current directo *It is highly recommended to install __XMind SDK for python__ under an isolated python environment using [virtualenv](https://pypi.python.org/pypi/virtualenv)* +##Set PYTHONPATH +You must set PYTHONPATH environment variable to '.'. + +In Eclipse (with PyDev plugin): modify the 'Run Configuration' and define varaiable PYTHONPATH = . (with the +'Environment' Tab) + ##Usage Open an existing XMind file or create a new XMind file and place it into a given path diff --git a/xmind/framework/__init__.py b/xmind/framework/__init__.py index 261ba6c..e382d5c 100644 --- a/xmind/framework/__init__.py +++ b/xmind/framework/__init__.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ xmind.framework - ~~~~~~~~~~ + --------------- :copyright: Michel Kern :license: MIT diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index c743d74..988a7aa 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -38,7 +38,7 @@ def export(self, source_path, target_path): def main(): print("** xmind.ExportFilter **") export_filter = ExportFilter() - rc = export_filter.export("../data/t.txt", "") + rc = export_filter.export("../data/sample_text_file.txt", "") print(rc) #pass diff --git a/xmind/import_export/__init__.py b/xmind/import_export/__init__.py index d9e8c17..6f9cdf1 100644 --- a/xmind/import_export/__init__.py +++ b/xmind/import_export/__init__.py @@ -2,7 +2,7 @@ #-*- coding: utf-8 -*- """ xmind.import_export module - ~~~~~~~~~~~~~~~~~ + -------------------------- :copyright: Michel Kern :license: MIT From 48c40db8fba4f326610e6d1f5fc66205aa3bd1c2 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 1 Dec 2015 11:52:41 +0100 Subject: [PATCH 29/30] 24 --- .settings/org.eclipse.core.resources.prefs | 1 + xmind/import_export/ExportFilter.py | 7 +++---- xmind/import_export/GraphvizExportFilter.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index d79d2ef..b985da1 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -6,6 +6,7 @@ encoding//xmind/core/loader.py=utf-8 encoding//xmind/core/notes.py=utf-8 encoding//xmind/core/workbook.py=utf-8 encoding//xmind/framework/Enum.py=utf-8 +encoding//xmind/framework/UnitTest.py=utf-8 encoding//xmind/framework/__init__.py=utf-8 encoding//xmind/import_export/ExportFilter.py=utf-8 encoding//xmind/import_export/GraphvizExportFilter.py=utf-8 diff --git a/xmind/import_export/ExportFilter.py b/xmind/import_export/ExportFilter.py index 988a7aa..807cf04 100644 --- a/xmind/import_export/ExportFilter.py +++ b/xmind/import_export/ExportFilter.py @@ -3,8 +3,8 @@ """ xmind.import_export.ExportFilter -------------------------------- - :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting / importing - XMind files to other formats (e.g: GraphViz). + :mod: ``xmind.import_export.ExportFilter`` provide a handy way for exporting / importing + XMind files to other formats (e.g: GraphViz). :copyright: Michel Kern :license: MIT """ @@ -43,5 +43,4 @@ def main(): #pass if __name__ == '__main__': - main() - + main() \ No newline at end of file diff --git a/xmind/import_export/GraphvizExportFilter.py b/xmind/import_export/GraphvizExportFilter.py index 219e6aa..c38e142 100644 --- a/xmind/import_export/GraphvizExportFilter.py +++ b/xmind/import_export/GraphvizExportFilter.py @@ -2,10 +2,10 @@ #-*- coding: utf-8 -*- """ xmind.import_export.GraphvizExportFilter - ~~~~~~~~~~~~~~~~~ - :mod:``xmind.import_export.ExportFilter`` provide a handy way for exporting - XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) - GraphViz (http://www.graphviz.org/) + ---------------------------------------- + :mod: ``xmind.import_export.ExportFilter`` provide a handy way for exporting + XMind files to dot format (see http://www.graphviz.org/pdf/dotguide.pdf) + GraphViz (http://www.graphviz.org/) :copyright: Michel Kern :license: MIT """ From 76a5046a64391f04d9cfcf785ab42c07acc61282 Mon Sep 17 00:00:00 2001 From: Almerxsese Date: Tue, 1 Dec 2015 11:54:00 +0100 Subject: [PATCH 30/30] 27 --- xmind/framework/UnitTest.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 xmind/framework/UnitTest.py diff --git a/xmind/framework/UnitTest.py b/xmind/framework/UnitTest.py new file mode 100644 index 0000000..6b3897b --- /dev/null +++ b/xmind/framework/UnitTest.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- +""" + xmind.framework.UnitTest + ------------------------ + :mod: ``xmind.framework.UnitTest`` provides unit test superclass + :copyright: Michel Kern + :license: MIT +""" + +__author__ = "echopraxium@yahoo.com " + +#------------------- UnitTest ------------------- +class UnitTest: + def __init__(self): + self.name = "unit_test" + + def run(self): + print("> run '" + self.name + "'") +#------------------- UnitTest + +#======================== main ======================== +def main(): + print("** xmind.framework.UnitTest **") + + ut = UnitTest() + ut.run() + +if __name__ == '__main__': + main()