mindm.mindmanager_mac module¶
MacOS-specific implementation of the Mindmanager interface.
This module provides MacOS platform-specific implementation for interacting with MindManager application, including functionality for manipulating topics, properties, relationships, and document structure.
- class mindm.mindmanager_mac.Mindmanager(charttype)¶
Bases:
object- MACOS_LIBRARY_FOLDER = 'C:\\Users\\runneradmin\\Library\\Application Support\\Mindjet\\MindManager\\XX\\English\\Library'¶
- MACOS_MERGE_ALL_WINDOWS = False¶
- __init__(charttype)¶
- add_document(max_topic_level)¶
- add_relationship(guid1, guid2, label='')¶
- add_subtopic_to_topic(topic, topic_text)¶
- add_tag_to_topic(topic, tag_text, topic_guid)¶
- add_topic_link(guid1, guid2, label='')¶
- create_map_icons(map_icons)¶
- create_tags(tags: list[str], DUPLICATED_TAG: str)¶
- document_exists()¶
- finalize(max_topic_level)¶
- get_active_document_object()¶
- get_central_topic() MindmapTopic¶
- get_guid_from_topic(topic) str¶
- get_icons_from_topic(topic) list[MindmapIcon]¶
- get_image_from_topic(topic) MindmapImage¶
- get_level_from_topic(topic)¶
- get_library_folder()¶
- get_links_from_topic(topic) list[MindmapLink]¶
- get_mindmanager_object()¶
- get_mindmaptopic_from_topic(topic) MindmapTopic¶
- get_mindmaptopic_from_topic_content(topic) MindmapTopic¶
- get_mindmaptopic_from_topic_full(topic) MindmapTopic¶
- get_notes_from_topic(topic) MindmapNotes¶
- get_parent_from_topic(topic)¶
- get_references_from_topic(topic) list[MindmapReference]¶
- get_selection()¶
- get_subtopics_from_topic(topic)¶
- get_tags_from_topic(topic) list[MindmapTag]¶
- get_text_from_topic(topic)¶
- get_title_from_topic(topic)¶
- get_topic_by_id(id)¶
- get_version()¶
- set_document_background_image(path)¶
- set_text_to_topic(topic, topic_text)¶
- set_title_to_topic(topic, topic_rtf)¶
- set_topic_from_mindmap_topic(topic, mindmap_topic, map_icons)¶
Source code for mindmanager_mac.py¶
1"""
2MacOS-specific implementation of the Mindmanager interface.
3
4This module provides MacOS platform-specific implementation for interacting
5with MindManager application, including functionality for manipulating topics,
6properties, relationships, and document structure.
7"""
8
9import os
10from appscript import *
11
12from mindmap.mindmap import MindmapLink, MindmapImage, MindmapNotes, MindmapIcon, MindmapTag, MindmapReference, MindmapTopic
13
14class Mindmanager:
15
16 MACOS_MERGE_ALL_WINDOWS = False
17 MACOS_LIBRARY_FOLDER = os.path.join(os.path.expanduser("~"), "Library", "Application Support", "Mindjet", "MindManager", "XX", "English", "Library")
18
19 def __init__(self, charttype):
20 self._mindmanager = app('MindManager')
21 self._version = self._mindmanager.version.get().split('.')[0]
22 self._master_window = self._mindmanager.windows[1].id.get()
23 self._charttype = charttype
24 self._library_folder = self.MACOS_LIBRARY_FOLDER.replace("XX", self._version)
25 if self._version != '24':
26 orgchart_template_path = os.path.join(self._library_folder, "Templates", "Blank Templates", "Org-Chart Map.mmat")
27 else:
28 orgchart_template_path = os.path.join(self._library_folder, "Templates", "Blank Templates", "Organization Chart.mmat")
29 self._orgchart_template = mactypes.Alias(orgchart_template_path)
30 self._radial_template = mactypes.Alias(os.path.join(self._library_folder, "Templates", "Blank Templates", "Radial Map.mmat"))
31
32 def get_mindmanager_object(self):
33 return self._mindmanager
34
35 def get_active_document_object(self):
36 if self.document_exists():
37 return self._mindmanager.documents[1]
38 return None
39
40 def get_library_folder(self):
41 return self._library_folder
42
43 def get_version(self):
44 return self._version
45
46 def set_document_background_image(self, path):
47 pass
48
49 def document_exists(self):
50 try:
51 return self._mindmanager.documents[1].exists()
52 except Exception as e:
53 print(f"Error checking document existence: {e}")
54 return False
55
56 def get_central_topic(self) -> 'MindmapTopic':
57 try:
58 topic = self._mindmanager.documents[1].central_topic.get()
59 #callouts = topic.callouts.get()
60 #relationships = topic.relationships.get()
61 #subtopics = topic.subtopics.get()
62 #shape = topic.shape.get()
63 #attributes = topic.attributes.get()
64 #props = topic.properties.get()
65 #task = topic.task.get()
66 #task_properties = task.properties.get()
67 mindmap_topic = MindmapTopic(
68 guid=self.get_guid_from_topic(topic),
69 text=self.get_text_from_topic(topic),
70 rtf=self.get_title_from_topic(topic),
71 level=self.get_level_from_topic(topic),
72 )
73 return mindmap_topic
74 except Exception as e:
75 print(f"Error getting central topic: {e}")
76 return None
77
78 def get_mindmaptopic_from_topic(self, topic) -> 'MindmapTopic':
79 mindmap_topic = MindmapTopic(
80 guid=self.get_guid_from_topic(topic),
81 text=self.get_text_from_topic(topic),
82 rtf=self.get_title_from_topic(topic),
83 level=self.get_level_from_topic(topic),
84 )
85 return mindmap_topic
86
87 def get_mindmaptopic_from_topic_content(self, topic) -> 'MindmapTopic':
88 mindmap_topic = MindmapTopic(
89 guid=self.get_guid_from_topic(topic),
90 text=self.get_text_from_topic(topic),
91 rtf=self.get_title_from_topic(topic),
92 level=self.get_level_from_topic(topic),
93 notes=self.get_notes_from_topic(topic),
94 )
95 return mindmap_topic
96
97 def get_mindmaptopic_from_topic_full(self, topic) -> 'MindmapTopic':
98 mindmap_topic = MindmapTopic(
99 guid=self.get_guid_from_topic(topic),
100 text=self.get_text_from_topic(topic),
101 rtf=self.get_title_from_topic(topic),
102 level=self.get_level_from_topic(topic),
103 notes=self.get_notes_from_topic(topic),
104 links=self.get_links_from_topic(topic),
105 image=self.get_image_from_topic(topic),
106 icons=self.get_icons_from_topic(topic),
107 tags=self.get_tags_from_topic(topic),
108 references=self.get_references_from_topic(topic),
109 )
110 return mindmap_topic
111
112 def get_topic_by_id(self, id):
113 try:
114 found_topics = self._mindmanager.documents[1].topics[its.id == id]
115 if found_topics.count() == 0:
116 return None
117 return found_topics[0].get()
118 except Exception as e:
119 print(f"Error getting topic by id: {e}")
120 return None
121
122 def get_selection(self):
123 selection = []
124 try:
125 items = self._mindmanager.documents[1].selection.get()
126 for item in items:
127 type = item.class_.get()
128 if type.name == 'topic':
129 selection.append(item)
130 except Exception as e:
131 print(f"Error getting selection: {e}")
132 return selection
133
134 def get_level_from_topic(self, topic):
135 try:
136 return topic.level.get()
137 except Exception as e:
138 print(f"Error getting level from topic: {e}")
139 return None
140
141 def get_text_from_topic(self, topic):
142 try:
143 text = topic.name.get()
144 return text.replace('"', '`').replace("'", "`").replace("\r", "").replace("\n", "")
145 except Exception as e:
146 print(f"Error getting text from topic: {e}")
147 return ""
148
149 def get_title_from_topic(self, topic):
150 try:
151 title = topic.title.get()
152 return title
153 except Exception as e:
154 print(f"Error getting title from topic: {e}")
155 return ""
156
157 def get_subtopics_from_topic(self, topic):
158 try:
159 return topic.subtopics.get()
160 except Exception as e:
161 print(f"Error getting subtopics from topic: {e}")
162 return []
163
164 def get_links_from_topic(self, topic) -> list['MindmapLink']:
165 return None
166 # this results in a severe runtime error of MindManager
167 link = topic.hyperlink_URL.get()
168 # this has no effect
169 label = topic.label.get()
170 return MindmapLink(link=link, label=label) if label != '' else None
171
172 def get_image_from_topic(self, topic) -> MindmapImage:
173 return None
174
175 def get_icons_from_topic(self, topic) -> list[MindmapIcon]:
176 return []
177
178 def get_notes_from_topic(self, topic) -> MindmapNotes:
179 try:
180 notes = topic.notes.get()
181 return MindmapNotes(text=notes)
182 except Exception as e:
183 print(f"Error getting notes from topic: {e}")
184 return None
185
186 def get_tags_from_topic(self, topic) -> list[MindmapTag]:
187 return []
188
189 def get_references_from_topic(self, topic) -> list[MindmapReference]:
190 references = []
191 try:
192 relationships = topic.relationships.get()
193 for relationship in relationships:
194 relationship_instance = relationship.get()
195 starting_location = relationship_instance.starting_location.get()
196 ending_location = relationship_instance.ending_location.get()
197 if starting_location == topic:
198 references.append(MindmapReference(
199 direction=1,
200 guid_1=starting_location.id.get(),
201 guid_2=ending_location.id.get()
202 ))
203 except Exception as e:
204 print(f"Error in get_references_from_topic: {e}")
205 return references
206
207 def get_guid_from_topic(self, topic) -> str:
208 try:
209 return topic.id.get()
210 except Exception as e:
211 print(f"Error in get_guid_from_topic: {e}")
212 return ""
213
214 def add_subtopic_to_topic(self, topic, topic_text):
215 try:
216 topic_instance = topic.get()
217 return topic_instance.subtopics.end.make(new=k.topic, with_properties={k.name: topic_text})
218 except Exception as e:
219 print(f"Error in add_subtopic_to_topic: {e}")
220 return None
221
222 def get_parent_from_topic(self, topic):
223 try:
224 return topic.parent.get()
225 except Exception as e:
226 print(f"Error in get_parent_from_topic: {e}")
227 return None
228
229 def set_text_to_topic(self, topic, topic_text):
230 try:
231 topic.name.set(topic_text)
232 except Exception as e:
233 print(f"Error in set_text_to_topic: {e}")
234
235 def set_title_to_topic(self, topic, topic_rtf):
236 try:
237 topic.title.set(topic_rtf)
238 except Exception as e:
239 print(f"Error in set_title_to_topic: {e}")
240
241 def add_tag_to_topic(self, topic, tag_text, topic_guid):
242 pass
243
244 def set_topic_from_mindmap_topic(self, topic, mindmap_topic, map_icons):
245 try:
246 topic_id = topic.id.get()
247 self.set_text_to_topic(topic, mindmap_topic.text)
248 refreshed_topic = self.get_topic_by_id(topic_id)
249 if mindmap_topic.rtf != '':
250 self.set_title_to_topic(refreshed_topic, mindmap_topic.rtf)
251 refreshed_topic = self.get_topic_by_id(topic_id)
252 if mindmap_topic.notes:
253 refreshed_topic.notes.set(mindmap_topic.notes.text)
254 refreshed_topic = self.get_topic_by_id(topic_id)
255 return refreshed_topic, topic_id
256 except Exception as e:
257 print(f"Error in set_topic_from_mindmap_topic: {e}")
258 return None, None
259
260 def create_map_icons(self, map_icons):
261 pass
262
263 def create_tags(self, tags: list['str'], DUPLICATED_TAG: str):
264 pass
265
266 def add_relationship(self, guid1, guid2, label = ''):
267 try:
268 topic1 = self.get_topic_by_id(guid1)
269 topic2 = self.get_topic_by_id(guid2)
270 if topic1 is None or topic2 is None:
271 print("Error in add_relationship: One or both topics not found.")
272 return
273 topic1.make(new=k.relationship, with_properties={k.starting_location: topic1, k.ending_location: topic2})
274 except Exception as e:
275 print(f"Error in add_relationship: {e}")
276
277 def add_topic_link(self, guid1, guid2, label=''):
278 pass
279
280 def add_document(self, max_topic_level):
281 cnt_subtopics = len(self._mindmanager.documents[1].central_topic.subtopics.get())
282 if self._charttype == "orgchart":
283 template_alias = self._orgchart_template
284 if self._charttype == "radial":
285 template_alias = self._radial_template
286 if self._charttype == "auto":
287 if max_topic_level > 2 and cnt_subtopics > 4:
288 template_alias = self._orgchart_template
289 else:
290 template_alias = self._radial_template
291 self._mindmanager.open(template_alias)
292
293 def finalize(self, max_topic_level):
294 self._mindmanager.documents[1].balance_map()
295 self._mindmanager.activate()
296 if self.MACOS_MERGE_ALL_WINDOWS:
297 self.merge_windows()
298 self._mindmanager = None
299 del self._mindmanager