Graphics/ApplicationDiagramBuilder.py

changeset 2992
dbdf27746da5
parent 2953
703452a2876f
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2991:226481ff40d1 2992:dbdf27746da5
37 super().__init__(dialog, view, project) 37 super().__init__(dialog, view, project)
38 self.setObjectName("ApplicationDiagram") 38 self.setObjectName("ApplicationDiagram")
39 39
40 self.noModules = noModules 40 self.noModules = noModules
41 41
42 self.umlView.setDiagramName(self.trUtf8("Application Diagram {0}").format( 42 self.umlView.setDiagramName(
43 self.project.getProjectName())) 43 self.trUtf8("Application Diagram {0}").format(
44 self.project.getProjectName()))
44 45
45 def __buildModulesDict(self): 46 def __buildModulesDict(self):
46 """ 47 """
47 Private method to build a dictionary of modules contained in the application. 48 Private method to build a dictionary of modules contained in the
49 application.
48 50
49 @return dictionary of modules contained in the application. 51 @return dictionary of modules contained in the application.
50 """ 52 """
51 import Utilities.ModuleParser 53 import Utilities.ModuleParser
52 extensions = Preferences.getPython("PythonExtensions") + \ 54 extensions = Preferences.getPython("PythonExtensions") + \
53 Preferences.getPython("Python3Extensions") + ['.rb'] 55 Preferences.getPython("Python3Extensions") + ['.rb']
54 moduleDict = {} 56 moduleDict = {}
55 mods = self.project.pdata["SOURCES"] 57 mods = self.project.pdata["SOURCES"]
56 modules = [] 58 modules = []
57 for module in mods: 59 for module in mods:
58 modules.append(Utilities.normabsjoinpath(self.project.ppath, module)) 60 modules.append(Utilities.normabsjoinpath(
61 self.project.ppath, module))
59 tot = len(modules) 62 tot = len(modules)
60 try: 63 try:
61 prog = 0 64 prog = 0
62 progress = QProgressDialog(self.trUtf8("Parsing modules..."), 65 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
63 None, 0, tot, self.parent()) 66 None, 0, tot, self.parent())
69 QApplication.processEvents() 72 QApplication.processEvents()
70 prog += 1 73 prog += 1
71 if module.endswith("__init__.py"): 74 if module.endswith("__init__.py"):
72 continue 75 continue
73 try: 76 try:
74 mod = Utilities.ModuleParser.readModule(module, extensions=extensions, 77 mod = Utilities.ModuleParser.readModule(
75 caching=False) 78 module, extensions=extensions, caching=False)
76 except ImportError: 79 except ImportError:
77 continue 80 continue
78 else: 81 else:
79 name = mod.name 82 name = mod.name
80 moduleDict[name] = mod 83 moduleDict[name] = mod
141 packagePath = os.path.dirname(modules[module].file) 144 packagePath = os.path.dirname(modules[module].file)
142 hasInit = True 145 hasInit = True
143 ppath = packagePath 146 ppath = packagePath
144 while hasInit: 147 while hasInit:
145 ppath = os.path.dirname(ppath) 148 ppath = os.path.dirname(ppath)
146 hasInit = \ 149 hasInit = len(glob.glob(os.path.join(
147 len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0 150 ppath, '__init__.*'))) > 0
148 shortPackage = \ 151 shortPackage = packagePath.replace(ppath, '')\
149 packagePath.replace(ppath, '').replace(os.sep, '.')[1:] 152 .replace(os.sep, '.')[1:]
150 packageList = shortPackage.split('.')[1:] 153 packageList = shortPackage.split('.')[1:]
151 packageListLen = len(packageList) 154 packageListLen = len(packageList)
152 i = '.'.join(packageList[:packageListLen - dots + 1] + [i[dots:]]) 155 i = '.'.join(
156 packageList[:packageListLen - dots + 1] +
157 [i[dots:]])
153 158
154 if i in modules: 159 if i in modules:
155 impLst.append(i) 160 impLst.append(i)
156 else: 161 else:
157 if i.find('.') == -1: 162 if i.find('.') == -1:
183 relPackage = relPackage[1:] 188 relPackage = relPackage[1:]
184 else: 189 else:
185 relPackage = self.trUtf8("<<Application>>") 190 relPackage = self.trUtf8("<<Application>>")
186 else: 191 else:
187 relPackage = self.trUtf8("<<Others>>") 192 relPackage = self.trUtf8("<<Others>>")
188 shape = self.__addPackage(relPackage, packages[package][0], 0.0, 0.0) 193 shape = self.__addPackage(
194 relPackage, packages[package][0], 0.0, 0.0)
189 shapeRect = shape.sceneBoundingRect() 195 shapeRect = shape.sceneBoundingRect()
190 shapes[package] = (shape, packages[package][1]) 196 shapes[package] = (shape, packages[package][1])
191 pn = p + shapeRect.width() + 10 197 pn = p + shapeRect.width() + 10
192 maxHeight = max(maxHeight, shapeRect.height()) 198 maxHeight = max(maxHeight, shapeRect.height())
193 if pn > sceneRect.width(): 199 if pn > sceneRect.width():
268 274
269 projectFile = parts[0].split("=", 1)[1].strip() 275 projectFile = parts[0].split("=", 1)[1].strip()
270 if projectFile != self.project.getProjectFile(): 276 if projectFile != self.project.getProjectFile():
271 res = E5MessageBox.yesNo(None, 277 res = E5MessageBox.yesNo(None,
272 self.trUtf8("Load Diagram"), 278 self.trUtf8("Load Diagram"),
273 self.trUtf8("""<p>The diagram belongs to the project <b>{0}</b>.""" 279 self.trUtf8(
274 """ Shall this project be opened?</p>""").format( 280 """<p>The diagram belongs to the project <b>{0}</b>."""
281 """ Shall this project be opened?</p>""").format(
275 projectFile)) 282 projectFile))
276 if res: 283 if res:
277 self.project.openProject(projectFile) 284 self.project.openProject(projectFile)
278 285
279 self.noModules = Utilities.toBool(parts[1].split("=", 1)[1].strip()) 286 self.noModules = Utilities.toBool(parts[1].split("=", 1)[1].strip())

eric ide

mercurial