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