From 6b7722f20ba86c2789d0c8884ecff815b2c478e8 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 14 Nov 2014 11:26:06 +0800 Subject: [PATCH 1/3] update install using pip, add getRelationships func --- README.md | 8 +------- xmind/core/const.py | 1 + xmind/core/sheet.py | 7 +++++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 029b622..7571908 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,7 @@ ##Install XMind SDK for python -Clone the repository to a local working directory - - git clone https://github.com/xmindltd/xmind-sdk-python.git - -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**. - - python setup.py install + pip install git+https://github.com/xmindltd/xmind-sdk-python.git *It is highly recommended to install __XMind SDK for python__ under an isolated python environment using [virtualenv](https://pypi.python.org/pypi/virtualenv)* diff --git a/xmind/core/const.py b/xmind/core/const.py index a9b27d1..e637c01 100644 --- a/xmind/core/const.py +++ b/xmind/core/const.py @@ -67,6 +67,7 @@ TOPIC_ROOT = "root" TOPIC_ATTACHED = "attached" +TOPIC_DETACHED = "detached" FILE_PROTOCOL = "file://" TOPIC_PROTOCOL = "xmind:#" diff --git a/xmind/core/sheet.py b/xmind/core/sheet.py index b042e40..651cabe 100644 --- a/xmind/core/sheet.py +++ b/xmind/core/sheet.py @@ -64,6 +64,13 @@ def createRelationship(self, end1, end2, title=None): return rel + def getRelationships(self): + """ + Get relationships from current sheet + """ + elems = RelationshipsElement(self._getRelationships()) + return map(RelationshipElement, elems) + def _getRelationships(self): return self.getFirstChildNodeByTagName(const.TAG_RELATIONSHIPS) From 4cfd98ea12eb9bc082aae8e113ea5dad0df9a24f Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 14 Nov 2014 11:44:07 +0800 Subject: [PATCH 2/3] fix getRelation add dump.py examples --- examples/dump.py | 42 ++++++++++++++++++++++++++++++ example.py => examples/example.py | 0 examples/test2.xmind | Bin 0 -> 1813 bytes xmind/core/sheet.py | 2 +- 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 examples/dump.py rename example.py => examples/example.py (100%) create mode 100644 examples/test2.xmind diff --git a/examples/dump.py b/examples/dump.py new file mode 100644 index 0000000..4aa085f --- /dev/null +++ b/examples/dump.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# Author: hzsunshx +# Created: 2014-11-14 11:27 + +""" +dump xmind files +""" + +import xmind +import pipes + +M = {} + +def _echo(tag, element, indent=0): + title = element.getTitle() + M[element.getID()] = title + print '\t'*indent, tag, ':', pipes.quote(title) + +def dump_sheet(sheet): + rootTopic = sheet.getRootTopic() + _echo('RootTopic', rootTopic, 1) + + for topic in rootTopic.getSubTopics() or []: + _echo('AttachedSubTopic', topic, 2) + + for topic in rootTopic.getSubTopics(xmind.core.const.TOPIC_DETACHED) or []: + _echo('DetachedSubTopic', topic, 2) + + for rel in sheet.getRelationships(): + id1, id2 = rel.getEnd1ID(), rel.getEnd2ID() + print 'Relation:', M.get(id1), '-->', M.get(id2) + +def main(): + x = xmind.load('test2.xmind') + for sheet in x.getSheets(): + _echo('Sheet', sheet) + dump_sheet(sheet) + +if __name__ == '__main__': + main() diff --git a/example.py b/examples/example.py similarity index 100% rename from example.py rename to examples/example.py diff --git a/examples/test2.xmind b/examples/test2.xmind new file mode 100644 index 0000000000000000000000000000000000000000..c6d2f2a9e4d281d818af30d51d037f835aa5782d GIT binary patch literal 1813 zcmb_dyOPr|6wR_g0quT(#}rhF{7kHjldYgxik+chhDwpHVzaj7v9u&h#|JP&OF_rC z@CAGj*G^(5*$vI&jAdWz=;r9$BkB6;{OQG@x%5Z%=Et}1e||n644V5Te&bqMPJSoVmAF4iooso~}z)4Y$J_o0niLD=WlDeoVu79D7lO zBfC67lLs>^gGp*NU6;8M*s=;6{5sv{n)bk{)H64;wwe;MTCGN_aHQ)c@hPR`!~1vS zt*%REw^^s=Gt#?{4m{5z*tdhNGg}r90o$}~ZwD=Mb#ofp^t$uZWB}I5#mt@X2}BDP z_>#x5q=BG}f?$&*aZe}|CYZqLD(CkTFh7xT62_c`KpR+Y3z)CK5n8>r4retuS~@n% zjni^S$p(VYCgW~|%xhzh5$%AJ+yjpS_qa#pB4j7Ix1=8C9tJc*F_Li{G1+miwYHAZ z0y?HV%L`G1+KONtdso5CW!5sDfjAH+K|UaOGM*$7iODfdz>EDT^s!z|Ev8uwa^`M~ z_39tR*eO$k$ZOyheePI|N`mu{SS71(pdMm!Gf(@#*}gWFzXRivc}n_Tgmz``D#dN_r~#Rg5^PGzLPb`l!EWg-qmJowW-cr3q#h-s1}Q5@1mYtz<$8?&x* zn>jC#h6U3VvyJ9yRj^#m+rW{!-WaqUmXb|hO199R?0;3(i^5QZ-hz9+3=Wl*c>yRa z$#e-M`(kdD$<}10>l;%s4jaXXM%)amJDX`mV2!(40frQMsYjnGSa!A8lY*gfir&_b zo!7=WjfMIJ(z&TE!`26f>%NA9HD)$hUg6;V5O;9l&)fq89<3on1V@M?i#AU8Cvr08 zLb3>wAQYVPF!p?kYyH$dfv3Q3!J%7hXBV>152v~xHdEhjQCO1xpqXD^ojtiYKYfn1 c2OKuPzBX@rr`q+^Gd$`BgERb5eEx2uzlk?ZbN~PV literal 0 HcmV?d00001 diff --git a/xmind/core/sheet.py b/xmind/core/sheet.py index 651cabe..1acc2bf 100644 --- a/xmind/core/sheet.py +++ b/xmind/core/sheet.py @@ -69,7 +69,7 @@ def getRelationships(self): Get relationships from current sheet """ elems = RelationshipsElement(self._getRelationships()) - return map(RelationshipElement, elems) + return map(RelationshipElement, elems.iterChildNodesByTagName(const.TAG_RELATIONSHIP)) def _getRelationships(self): return self.getFirstChildNodeByTagName(const.TAG_RELATIONSHIPS) From 42e68f6d16edcb9d9fa2d956cfb61ca152ddece2 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Fri, 14 Nov 2014 13:33:43 +0800 Subject: [PATCH 3/3] update print --- examples/dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dump.py b/examples/dump.py index 4aa085f..0186317 100644 --- a/examples/dump.py +++ b/examples/dump.py @@ -30,7 +30,7 @@ def dump_sheet(sheet): for rel in sheet.getRelationships(): id1, id2 = rel.getEnd1ID(), rel.getEnd2ID() - print 'Relation:', M.get(id1), '-->', M.get(id2) + print 'Relation: [%s] --> [%s]' % (M.get(id1), M.get(id2)) def main(): x = xmind.load('test2.xmind')