eric6/Graphics/ImportsDiagramBuilder.py

changeset 8295
3f5e8b0a338e
parent 8291
3d79b1e5bf3c
child 8400
b3eefd7e58d1
--- a/eric6/Graphics/ImportsDiagramBuilder.py	Thu May 06 19:46:00 2021 +0200
+++ b/eric6/Graphics/ImportsDiagramBuilder.py	Sat May 08 18:34:08 2021 +0200
@@ -133,10 +133,10 @@
         initlist = glob.glob(os.path.join(self.packagePath, '__init__.*'))
         if len(initlist) == 0:
             ct = QGraphicsTextItem(None)
-            ct.setHtml(
-                self.tr(
-                    "The directory <b>'{0}'</b> is not a Python package.")
-                .format(self.package))
+            ct.setHtml(self.buildErrorMessage(
+                self.tr("The directory <b>'{0}'</b> is not a Python"
+                        " package.").format(self.package)
+            ))
             self.scene.addItem(ct)
             return
         
@@ -384,3 +384,40 @@
         )
         
         return data
+    
+    def fromDict(self, version, data):
+        """
+        Public method to populate the class with data persisted by 'toDict()'.
+        
+        @param version version of the data
+        @type str
+        @param data dictionary containing the persisted data
+        @type dict
+        @return tuple containing a flag indicating success and an info
+            message in case the diagram belongs to a different project
+        @rtype tuple of (bool, str)
+        """
+        try:
+            self.showExternalImports = data["show_external"]
+            
+            packagePath = Utilities.toNativeSeparators(data["package"])
+            if os.path.isabs(packagePath):
+                self.packagePath = packagePath
+                self.__relPackagePath = ""
+            else:
+                # relative package paths indicate a project package
+                if data["project_name"] != self.project.getProjectName():
+                    msg = self.tr(
+                        "<p>The diagram belongs to project <b>{0}</b>."
+                        " Please open it and try again.</p>"
+                    ).format(data["project_name"])
+                    return False, msg
+                
+                self.__relPackagePath = packagePath
+                self.package = self.project.getAbsolutePath(packagePath)
+        except KeyError:
+            return False, ""
+        
+        self.initialize()
+        
+        return True, ""

eric ide

mercurial