From 4749ef7d106134d91c303e0668e2d95118e6ac21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damien=20Fran=C3=A7ois?= Date: Sat, 3 Sep 2016 13:15:08 +0200 Subject: [PATCH] Add setLabels --- xmind/core/const.py | 2 ++ xmind/core/labels.py | 71 ++++++++++++++++++++++++++++++++++++++++++++ xmind/core/topic.py | 32 ++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 xmind/core/labels.py diff --git a/xmind/core/const.py b/xmind/core/const.py index a9b27d1..4762875 100644 --- a/xmind/core/const.py +++ b/xmind/core/const.py @@ -37,6 +37,7 @@ TAG_TITLE = "title" TAG_POSITION = "position" TAG_CHILDREN = "children" +TAG_LABELS = "labels" TAG_NOTES = "notes" TAG_RELATIONSHIP = "relationship" TAG_RELATIONSHIPS = "relationships" @@ -75,3 +76,4 @@ HTML_FORMAT_NOTE = "html" PLAIN_FORMAT_NOTE = "plain" +LABEL = "label" diff --git a/xmind/core/labels.py b/xmind/core/labels.py new file mode 100644 index 0000000..755335f --- /dev/null +++ b/xmind/core/labels.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +""" + xmind.core.notes + ~~~~~~~~~~~~~~~~ + + :copyright: + :license: + +""" + +__author__ = "aiqi@xmind.net " + +from . import const + +from .mixin import TopicMixinElement + + +class LabelsElement(TopicMixinElement): + TAG_NAME = const.TAG_LABELS + + def __init__(self, node=None, ownerTopic=None): + super(LabelsElement, self).__init__(node, ownerTopic) + + def getContent(self): + """ Get notes content + + """ + + content = self.getFirstChildNodeByTagName(const.TAG_LABEL) + + if not content: + return + + return content.getTextContent() + + +class _LabelContentElement(TopicMixinElement): + def __init__(self, node=None, ownerTopic=None): + super(_LabelContentElement, self).__init__(node, ownerTopic) + + def getFormat(self): + return self.getImplementation().tagName + + +class Labels(_LabelContentElement): + """ text notes + + :param content: utf8 plain text. + :param node: `xml.dom.Element` object` + :param ownerTopic: `xmind.core.topic.TopicElement` object + + """ + + TAG_NAME = const.LABEL + + def __init__(self, content=None, node=None, ownerTopic=None): + super(Labels, self).__init__(node, ownerTopic) + if content is not None: + self.setTextContent(content) + + def setContent(self, content): + self.setTextContent(content) + + +def main(): + pass + +if __name__ == '__main__': + main() diff --git a/xmind/core/topic.py b/xmind/core/topic.py index 9b011cd..db49c76 100644 --- a/xmind/core/topic.py +++ b/xmind/core/topic.py @@ -18,6 +18,7 @@ from .title import TitleElement from .position import PositionElement from .notes import NotesElement, PlainNotes +from .labels import Labels, LabelsElement from .markerref import MarkerRefElement from .markerref import MarkerRefsElement from .markerref import MarkerId @@ -331,6 +332,26 @@ def getNotes(self): if notes is not None: return NotesElement(notes, self) + def getLabels(self): + """ + Return `NotesElement` object` and invoke + `NotesElement.getContent()` to get notes content. + """ + + labels = self.getFirstChildNodeByTagName(const.TAG_LABELS) + + if labels is not None: + return LabelsElement(labels, self) + + def _set_labels(self): + labels = self.getLabels() + + if labels is None: + labels = LabelsElement(ownerTopic=self) + self.appendChild(labels) + + return labels + def _set_notes(self): notes = self.getNotes() @@ -355,6 +376,17 @@ def setPlainNotes(self, content): notes.appendChild(new) + def setLabels(self, content): + """ Set plain text notes to topic + + :param content: utf8 plain text + + """ + labels = self._set_labels() + new = Labels(content, None) + + labels.appendChild(new) + class ChildrenElement(WorkbookMixinElement): TAG_NAME = const.TAG_CHILDREN