Graphics/ImportsDiagramBuilder.py

changeset 2033
4b99609f6a87
parent 2031
c36c2eb62a75
child 2034
8de0fc1f7fef
equal deleted inserted replaced
2032:704593d042fe 2033:4b99609f6a87
43 super().__init__(dialog, view, project) 43 super().__init__(dialog, view, project)
44 self.setObjectName("ImportsDiagram") 44 self.setObjectName("ImportsDiagram")
45 45
46 self.showExternalImports = showExternalImports 46 self.showExternalImports = showExternalImports
47 self.packagePath = Utilities.normabspath(package) 47 self.packagePath = Utilities.normabspath(package)
48
49 def initialize(self):
50 """
51 Public method to initialize the object.
52 """
48 self.package = os.path.splitdrive(self.packagePath)[1].replace(os.sep, '.')[1:] 53 self.package = os.path.splitdrive(self.packagePath)[1].replace(os.sep, '.')[1:]
49 hasInit = True 54 hasInit = True
50 ppath = self.packagePath 55 ppath = self.packagePath
51 while hasInit: 56 while hasInit:
52 ppath = os.path.dirname(ppath) 57 ppath = os.path.dirname(ppath)
53 hasInit = len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0 58 hasInit = len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0
54 self.shortPackage = self.packagePath.replace(ppath, '').replace(os.sep, '.')[1:] 59 self.shortPackage = self.packagePath.replace(ppath, '').replace(os.sep, '.')[1:]
55 60
56 self.umlView.setPersistenceData("package={0}".format(self.packagePath)) 61 pname = self.project.getProjectName()
57
58 pname = project.getProjectName()
59 if pname: 62 if pname:
60 name = self.trUtf8("Imports Diagramm {0}: {1}").format( 63 name = self.trUtf8("Imports Diagramm {0}: {1}").format(
61 pname, project.getRelativePath(self.packagePath)) 64 pname, self.project.getRelativePath(self.packagePath))
62 else: 65 else:
63 name = self.trUtf8("Imports Diagramm: {0}").format(self.packagePath) 66 name = self.trUtf8("Imports Diagramm: {0}").format(self.packagePath)
64 self.umlView.setDiagramName(name) 67 self.umlView.setDiagramName(name)
65 68
66 def __buildModulesDict(self): 69 def __buildModulesDict(self):
67 """ 70 """
68 Private method to build a dictionary of modules contained in the package. 71 Private method to build a dictionary of modules contained in the package.
69 72
70 @return dictionary of modules contained in the package. 73 @return dictionary of modules contained in the package.
100 name = name[len(self.package) + 1:] 103 name = name[len(self.package) + 1:]
101 moduleDict[name] = mod 104 moduleDict[name] = mod
102 finally: 105 finally:
103 progress.setValue(tot) 106 progress.setValue(tot)
104 return moduleDict 107 return moduleDict
105 108
106 def buildDiagram(self): 109 def buildDiagram(self):
107 """ 110 """
108 Public method to build the modules shapes of the diagram. 111 Public method to build the modules shapes of the diagram.
109 """ 112 """
110 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*')) 113 initlist = glob.glob(os.path.join(self.packagePath, '__init__.*'))
205 sceneRect.setHeight(rect.height()) 208 sceneRect.setHeight(rect.height())
206 self.umlView.setSceneSize(sceneRect.width(), sceneRect.height()) 209 self.umlView.setSceneSize(sceneRect.width(), sceneRect.height())
207 210
208 self.__createAssociations(shapes) 211 self.__createAssociations(shapes)
209 self.umlView.autoAdjustSceneSize(limit=True) 212 self.umlView.autoAdjustSceneSize(limit=True)
210 213
211 def __addModule(self, name, classes, x, y): 214 def __addModule(self, name, classes, x, y):
212 """ 215 """
213 Private method to add a module to the diagram. 216 Private method to add a module to the diagram.
214 217
215 @param name module name to be shown (string) 218 @param name module name to be shown (string)
221 classes.sort() 224 classes.sort()
222 impM = ModuleModel(name, classes) 225 impM = ModuleModel(name, classes)
223 impW = ModuleItem(impM, x, y, scene=self.scene) 226 impW = ModuleItem(impM, x, y, scene=self.scene)
224 impW.setId(self.umlView.getItemId()) 227 impW.setId(self.umlView.getItemId())
225 return impW 228 return impW
226 229
227 def __createAssociations(self, shapes): 230 def __createAssociations(self, shapes):
228 """ 231 """
229 Private method to generate the associations between the module shapes. 232 Private method to generate the associations between the module shapes.
230 233
231 @param shapes list of shapes 234 @param shapes list of shapes
234 for rel in shapes[module][1]: 237 for rel in shapes[module][1]:
235 assoc = AssociationItem( 238 assoc = AssociationItem(
236 shapes[module][0], shapes[rel][0], 239 shapes[module][0], shapes[rel][0],
237 Imports) 240 Imports)
238 self.scene.addItem(assoc) 241 self.scene.addItem(assoc)
242
243 def getPersistenceData(self):
244 """
245 Public method to get a string for data to be persisted.
246
247 @return persisted data string (string)
248 """
249 return "package={0}, show_external={1}".format(
250 self.packagePath, self.showExternalImports)
251
252 def parsePersistenceData(self, data):
253 """
254 Public method to parse persisted data.
255
256 @param dat persisted data to be parsed (string)
257 """
258 # TODO: implement this
259 return

eric ide

mercurial