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