90 ) |
91 ) |
91 module = Utilities.ModuleParser.readModule( |
92 module = Utilities.ModuleParser.readModule( |
92 self.file, extensions=extensions, caching=False) |
93 self.file, extensions=extensions, caching=False) |
93 except ImportError: |
94 except ImportError: |
94 ct = QGraphicsTextItem(None) |
95 ct = QGraphicsTextItem(None) |
95 ct.setHtml( |
96 ct.setHtml(self.buildErrorMessage( |
96 self.tr("The module <b>'{0}'</b> could not be found.") |
97 self.tr("The module <b>'{0}'</b> could not be found.") |
97 .format(self.file)) |
98 .format(self.file) |
|
99 )) |
98 self.scene.addItem(ct) |
100 self.scene.addItem(ct) |
99 return |
101 return |
100 |
102 |
101 if self.file not in self.allModules: |
103 if self.file not in self.allModules: |
102 self.allModules[self.file] = [] |
104 self.allModules[self.file] = [] |
152 self.__arrangeClasses(nodes, routes[:]) |
154 self.__arrangeClasses(nodes, routes[:]) |
153 self.__createAssociations(routes) |
155 self.__createAssociations(routes) |
154 self.umlView.autoAdjustSceneSize(limit=True) |
156 self.umlView.autoAdjustSceneSize(limit=True) |
155 else: |
157 else: |
156 ct = QGraphicsTextItem(None) |
158 ct = QGraphicsTextItem(None) |
157 ct.setHtml(self.tr( |
159 ct.setHtml(self.buildErrorMessage( |
158 "The module <b>'{0}'</b> does not contain any classes.") |
160 self.tr("The module <b>'{0}'</b> does not contain any" |
159 .format(self.file)) |
161 " classes.").format(self.file) |
|
162 )) |
160 self.scene.addItem(ct) |
163 self.scene.addItem(ct) |
161 |
164 |
162 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2): |
165 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2): |
163 """ |
166 """ |
164 Private method to arrange the shapes on the canvas. |
167 Private method to arrange the shapes on the canvas. |
363 if self.__relFile else |
366 if self.__relFile else |
364 Utilities.fromNativeSeparators(self.file) |
367 Utilities.fromNativeSeparators(self.file) |
365 ) |
368 ) |
366 |
369 |
367 return data |
370 return data |
|
371 |
|
372 def fromDict(self, version, data): |
|
373 """ |
|
374 Public method to populate the class with data persisted by 'toDict()'. |
|
375 |
|
376 @param version version of the data |
|
377 @type str |
|
378 @param data dictionary containing the persisted data |
|
379 @type dict |
|
380 @return tuple containing a flag indicating success and an info |
|
381 message in case the diagram belongs to a different project |
|
382 @rtype tuple of (bool, str) |
|
383 """ |
|
384 try: |
|
385 self.noAttrs = data["no_attributes"] |
|
386 |
|
387 file = Utilities.toNativeSeparators(data["file"]) |
|
388 if os.path.isabs(file): |
|
389 self.file = file |
|
390 self.__relFile = "" |
|
391 else: |
|
392 # relative file paths indicate a project file |
|
393 if data["project_name"] != self.project.getProjectName(): |
|
394 msg = self.tr( |
|
395 "<p>The diagram belongs to project <b>{0}</b>." |
|
396 " Please open it and try again.</p>" |
|
397 ).format(data["project_name"]) |
|
398 return False, msg |
|
399 |
|
400 self.__relFile = file |
|
401 self.file = self.project.getAbsolutePath(file) |
|
402 except KeyError: |
|
403 return False, "" |
|
404 |
|
405 self.initialize() |
|
406 |
|
407 return True, "" |