-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmindmap.py
40 lines (30 loc) · 1.13 KB
/
mindmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from aqt import mw # import the main window object (mw) from ankiqt
from aqt.utils import showInfo # import the "show info" tool from utils.py
from aqt.qt import * # import all of the Qt GUI library
from .freeplane_importer.model_not_found_exception import ModelNotFoundException
from xml.etree.ElementTree import ElementTree
from .freeplane_importer.reader import Reader
from .freeplane_importer.importer import Importer
##
# Entry point for the anki plugin
##
def importMindmap():
# Load freeplane example mindmap xml
doc = ElementTree()
doc.parse(os.path.dirname(__file__) + '/example/ExampleMindmap.mm')
# Extract notes from xml
reader = Reader()
notes = reader.get_notes(doc)
# Import notes into Anki
importer = Importer(mw.col)
for note in notes:
try:
importer.import_note(note)
except ModelNotFoundException as e:
showInfo('Model ' + e.model_name + ' not found')
mw.reset()
# Create a new menu item and add it to the tools menu
action = QAction("Import mindmap", mw)
action.triggered.connect(importMindmap)
mw.form.menuTools.addAction(action)