Graphics/ApplicationDiagramBuilder.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2525
8b507a9a2d40
parent 2992
dbdf27746da5
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
39 super(ApplicationDiagramBuilder, self).__init__(dialog, view, project) 39 super(ApplicationDiagramBuilder, self).__init__(dialog, view, project)
40 self.setObjectName("ApplicationDiagram") 40 self.setObjectName("ApplicationDiagram")
41 41
42 self.noModules = noModules 42 self.noModules = noModules
43 43
44 self.umlView.setDiagramName(self.trUtf8("Application Diagram {0}").format( 44 self.umlView.setDiagramName(
45 self.project.getProjectName())) 45 self.trUtf8("Application Diagram {0}").format(
46 self.project.getProjectName()))
46 47
47 def __buildModulesDict(self): 48 def __buildModulesDict(self):
48 """ 49 """
49 Private method to build a dictionary of modules contained in the application. 50 Private method to build a dictionary of modules contained in the
51 application.
50 52
51 @return dictionary of modules contained in the application. 53 @return dictionary of modules contained in the application.
52 """ 54 """
53 import Utilities.ModuleParser 55 import Utilities.ModuleParser
54 extensions = Preferences.getPython("PythonExtensions") + \ 56 extensions = Preferences.getPython("PythonExtensions") + \
55 Preferences.getPython("Python3Extensions") + ['.rb'] 57 Preferences.getPython("Python3Extensions") + ['.rb']
56 moduleDict = {} 58 moduleDict = {}
57 mods = self.project.pdata["SOURCES"] 59 mods = self.project.pdata["SOURCES"]
58 modules = [] 60 modules = []
59 for module in mods: 61 for module in mods:
60 modules.append(Utilities.normabsjoinpath(self.project.ppath, module)) 62 modules.append(Utilities.normabsjoinpath(
63 self.project.ppath, module))
61 tot = len(modules) 64 tot = len(modules)
62 try: 65 try:
63 prog = 0 66 prog = 0
64 progress = QProgressDialog(self.trUtf8("Parsing modules..."), 67 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
65 None, 0, tot, self.parent()) 68 None, 0, tot, self.parent())
71 QApplication.processEvents() 74 QApplication.processEvents()
72 prog += 1 75 prog += 1
73 if module.endswith("__init__.py"): 76 if module.endswith("__init__.py"):
74 continue 77 continue
75 try: 78 try:
76 mod = Utilities.ModuleParser.readModule(module, extensions=extensions, 79 mod = Utilities.ModuleParser.readModule(
77 caching=False) 80 module, extensions=extensions, caching=False)
78 except ImportError: 81 except ImportError:
79 continue 82 continue
80 else: 83 else:
81 name = mod.name 84 name = mod.name
82 moduleDict[name] = mod 85 moduleDict[name] = mod
143 packagePath = os.path.dirname(modules[module].file) 146 packagePath = os.path.dirname(modules[module].file)
144 hasInit = True 147 hasInit = True
145 ppath = packagePath 148 ppath = packagePath
146 while hasInit: 149 while hasInit:
147 ppath = os.path.dirname(ppath) 150 ppath = os.path.dirname(ppath)
148 hasInit = \ 151 hasInit = len(glob.glob(os.path.join(
149 len(glob.glob(os.path.join(ppath, '__init__.*'))) > 0 152 ppath, '__init__.*'))) > 0
150 shortPackage = \ 153 shortPackage = packagePath.replace(ppath, '')\
151 packagePath.replace(ppath, '').replace(os.sep, '.')[1:] 154 .replace(os.sep, '.')[1:]
152 packageList = shortPackage.split('.')[1:] 155 packageList = shortPackage.split('.')[1:]
153 packageListLen = len(packageList) 156 packageListLen = len(packageList)
154 i = '.'.join(packageList[:packageListLen - dots + 1] + [i[dots:]]) 157 i = '.'.join(
158 packageList[:packageListLen - dots + 1] +
159 [i[dots:]])
155 160
156 if i in modules: 161 if i in modules:
157 impLst.append(i) 162 impLst.append(i)
158 else: 163 else:
159 if i.find('.') == -1: 164 if i.find('.') == -1:
185 relPackage = relPackage[1:] 190 relPackage = relPackage[1:]
186 else: 191 else:
187 relPackage = self.trUtf8("<<Application>>") 192 relPackage = self.trUtf8("<<Application>>")
188 else: 193 else:
189 relPackage = self.trUtf8("<<Others>>") 194 relPackage = self.trUtf8("<<Others>>")
190 shape = self.__addPackage(relPackage, packages[package][0], 0.0, 0.0) 195 shape = self.__addPackage(
196 relPackage, packages[package][0], 0.0, 0.0)
191 shapeRect = shape.sceneBoundingRect() 197 shapeRect = shape.sceneBoundingRect()
192 shapes[package] = (shape, packages[package][1]) 198 shapes[package] = (shape, packages[package][1])
193 pn = p + shapeRect.width() + 10 199 pn = p + shapeRect.width() + 10
194 maxHeight = max(maxHeight, shapeRect.height()) 200 maxHeight = max(maxHeight, shapeRect.height())
195 if pn > sceneRect.width(): 201 if pn > sceneRect.width():
220 @param name package name to be shown (string) 226 @param name package name to be shown (string)
221 @param modules list of module names contained in the package 227 @param modules list of module names contained in the package
222 (list of strings) 228 (list of strings)
223 @param x x-coordinate (float) 229 @param x x-coordinate (float)
224 @param y y-coordinate (float) 230 @param y y-coordinate (float)
231 @return reference to the package item (PackageItem)
225 """ 232 """
226 from .PackageItem import PackageItem, PackageModel 233 from .PackageItem import PackageItem, PackageModel
227 modules.sort() 234 modules.sort()
228 pm = PackageModel(name, modules) 235 pm = PackageModel(name, modules)
229 pw = PackageItem(pm, x, y, noModules=self.noModules, scene=self.scene) 236 pw = PackageItem(pm, x, y, noModules=self.noModules, scene=self.scene)
269 276
270 projectFile = parts[0].split("=", 1)[1].strip() 277 projectFile = parts[0].split("=", 1)[1].strip()
271 if projectFile != self.project.getProjectFile(): 278 if projectFile != self.project.getProjectFile():
272 res = E5MessageBox.yesNo(None, 279 res = E5MessageBox.yesNo(None,
273 self.trUtf8("Load Diagram"), 280 self.trUtf8("Load Diagram"),
274 self.trUtf8("""<p>The diagram belongs to the project <b>{0}</b>.""" 281 self.trUtf8(
275 """ Shall this project be opened?</p>""").format( 282 """<p>The diagram belongs to the project <b>{0}</b>."""
283 """ Shall this project be opened?</p>""").format(
276 projectFile)) 284 projectFile))
277 if res: 285 if res:
278 self.project.openProject(projectFile) 286 self.project.openProject(projectFile)
279 287
280 self.noModules = Utilities.toBool(parts[1].split("=", 1)[1].strip()) 288 self.noModules = Utilities.toBool(parts[1].split("=", 1)[1].strip())

eric ide

mercurial