131 Public method to build the modules shapes of the diagram. |
131 Public method to build the modules shapes of the diagram. |
132 """ |
132 """ |
133 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*')) |
133 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*')) |
134 if len(initlist) == 0: |
134 if len(initlist) == 0: |
135 ct = QGraphicsTextItem(None) |
135 ct = QGraphicsTextItem(None) |
136 ct.setHtml( |
136 ct.setHtml(self.buildErrorMessage( |
137 self.tr( |
137 self.tr("The directory <b>'{0}'</b> is not a Python" |
138 "The directory <b>'{0}'</b> is not a Python package.") |
138 " package.").format(self.package) |
139 .format(self.package)) |
139 )) |
140 self.scene.addItem(ct) |
140 self.scene.addItem(ct) |
141 return |
141 return |
142 |
142 |
143 self.__shapes = {} |
143 self.__shapes = {} |
144 |
144 |
382 if self.__relPackagePath else |
382 if self.__relPackagePath else |
383 Utilities.fromNativeSeparators(self.packagePath) |
383 Utilities.fromNativeSeparators(self.packagePath) |
384 ) |
384 ) |
385 |
385 |
386 return data |
386 return data |
|
387 |
|
388 def fromDict(self, version, data): |
|
389 """ |
|
390 Public method to populate the class with data persisted by 'toDict()'. |
|
391 |
|
392 @param version version of the data |
|
393 @type str |
|
394 @param data dictionary containing the persisted data |
|
395 @type dict |
|
396 @return tuple containing a flag indicating success and an info |
|
397 message in case the diagram belongs to a different project |
|
398 @rtype tuple of (bool, str) |
|
399 """ |
|
400 try: |
|
401 self.showExternalImports = data["show_external"] |
|
402 |
|
403 packagePath = Utilities.toNativeSeparators(data["package"]) |
|
404 if os.path.isabs(packagePath): |
|
405 self.packagePath = packagePath |
|
406 self.__relPackagePath = "" |
|
407 else: |
|
408 # relative package paths indicate a project package |
|
409 if data["project_name"] != self.project.getProjectName(): |
|
410 msg = self.tr( |
|
411 "<p>The diagram belongs to project <b>{0}</b>." |
|
412 " Please open it and try again.</p>" |
|
413 ).format(data["project_name"]) |
|
414 return False, msg |
|
415 |
|
416 self.__relPackagePath = packagePath |
|
417 self.package = self.project.getAbsolutePath(packagePath) |
|
418 except KeyError: |
|
419 return False, "" |
|
420 |
|
421 self.initialize() |
|
422 |
|
423 return True, "" |