eric6/Graphics/PackageDiagramBuilder.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8270
6ba3564b7161
child 8400
b3eefd7e58d1
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
34 @param project reference to the project object (Project) 34 @param project reference to the project object (Project)
35 @param package name of a python package to be shown (string) 35 @param package name of a python package to be shown (string)
36 @param noAttrs flag indicating, that no attributes should be shown 36 @param noAttrs flag indicating, that no attributes should be shown
37 (boolean) 37 (boolean)
38 """ 38 """
39 super(PackageDiagramBuilder, self).__init__(dialog, view, project) 39 super().__init__(dialog, view, project)
40 self.setObjectName("PackageDiagram") 40 self.setObjectName("PackageDiagram")
41 41
42 self.package = os.path.abspath(package) 42 self.package = os.path.abspath(package)
43 self.noAttrs = noAttrs 43 self.noAttrs = noAttrs
44 44
45 def initialize(self): 45 def initialize(self):
46 """ 46 """
47 Public method to initialize the object. 47 Public method to initialize the object.
48 """ 48 """
49 pname = self.project.getProjectName() 49 pname = self.project.getProjectName()
50 if pname: 50 name = (
51 name = self.tr("Package Diagram {0}: {1}").format( 51 self.tr("Package Diagram {0}: {1}").format(
52 pname, self.project.getRelativePath(self.package)) 52 pname, self.project.getRelativePath(self.package))
53 else: 53 if pname else
54 name = self.tr("Package Diagram: {0}").format(self.package) 54 self.tr("Package Diagram: {0}").format(self.package)
55 )
55 self.umlView.setDiagramName(name) 56 self.umlView.setDiagramName(name)
56 57
57 def __getCurrentShape(self, name): 58 def __getCurrentShape(self, name):
58 """ 59 """
59 Private method to get the named shape. 60 Private method to get the named shape.
91 progress = E5ProgressDialog( 92 progress = E5ProgressDialog(
92 self.tr("Parsing modules..."), 93 self.tr("Parsing modules..."),
93 None, 0, tot, self.tr("%v/%m Modules"), self.parent()) 94 None, 0, tot, self.tr("%v/%m Modules"), self.parent())
94 progress.setWindowTitle(self.tr("Package Diagram")) 95 progress.setWindowTitle(self.tr("Package Diagram"))
95 try: 96 try:
96 prog = 0
97 progress.show() 97 progress.show()
98 QApplication.processEvents() 98 QApplication.processEvents()
99 99
100 for module in modules: 100 for prog, module in enumerate(modules):
101 progress.setValue(prog) 101 progress.setValue(prog)
102 QApplication.processEvents() 102 QApplication.processEvents()
103 prog += 1
104 try: 103 try:
105 mod = Utilities.ModuleParser.readModule( 104 mod = Utilities.ModuleParser.readModule(
106 module, extensions=extensions, caching=False) 105 module, extensions=extensions, caching=False)
107 except ImportError: 106 except ImportError:
108 continue 107 continue
156 progress = E5ProgressDialog( 155 progress = E5ProgressDialog(
157 self.tr("Parsing modules..."), 156 self.tr("Parsing modules..."),
158 None, 0, tot, self.tr("%v/%m Modules"), self.parent()) 157 None, 0, tot, self.tr("%v/%m Modules"), self.parent())
159 progress.setWindowTitle(self.tr("Package Diagram")) 158 progress.setWindowTitle(self.tr("Package Diagram"))
160 try: 159 try:
161 prog = 0
162 progress.show() 160 progress.show()
163 QApplication.processEvents() 161 QApplication.processEvents()
164 162
165 for subpackage in subpackagesList: 163 for subpackage in subpackagesList:
166 packageName = os.path.basename(subpackage) 164 packageName = os.path.basename(subpackage)
167 subpackagesDict[packageName] = [] 165 subpackagesDict[packageName] = []
168 modules = [] 166 modules = []
169 for ext in supportedExt: 167 for ext in supportedExt:
170 modules.extend(glob.glob( 168 modules.extend(glob.glob(
171 Utilities.normjoinpath(subpackage, ext))) 169 Utilities.normjoinpath(subpackage, ext)))
172 for module in modules: 170 for prog, module in enumerate(modules):
173 progress.setValue(prog) 171 progress.setValue(prog)
174 QApplication.processEvents() 172 QApplication.processEvents()
175 prog += 1
176 try: 173 try:
177 mod = Utilities.ModuleParser.readModule( 174 mod = Utilities.ModuleParser.readModule(
178 module, extensions=extensions, caching=False) 175 module, extensions=extensions, caching=False)
179 except ImportError: 176 except ImportError:
180 continue 177 continue
326 currentHeight = 0 323 currentHeight = 0
327 324
328 for rect in generation: 325 for rect in generation:
329 if rect.bottom() > currentHeight: 326 if rect.bottom() > currentHeight:
330 currentHeight = rect.bottom() 327 currentHeight = rect.bottom()
331 currentWidth = currentWidth + rect.right() 328 currentWidth += rect.right()
332 329
333 # update totals 330 # update totals
334 if currentWidth > width: 331 if currentWidth > width:
335 width = currentWidth 332 width = currentWidth
336 height = height + currentHeight 333 height += currentHeight
337 334
338 # store generation info 335 # store generation info
339 widths.append(currentWidth) 336 widths.append(currentWidth)
340 heights.append(currentHeight) 337 heights.append(currentHeight)
341 338
342 # add in some whitespace 339 # add in some whitespace
343 width = width * whiteSpaceFactor 340 width *= whiteSpaceFactor
344 height = height * whiteSpaceFactor - 20 341 height = height * whiteSpaceFactor - 20
345 verticalWhiteSpace = 40.0 342 verticalWhiteSpace = 40.0
346 343
347 sceneRect = self.umlView.sceneRect() 344 sceneRect = self.umlView.sceneRect()
348 width += 50.0 345 width += 50.0
431 """ 428 """
432 Private method to generate the associations between the class shapes. 429 Private method to generate the associations between the class shapes.
433 430
434 @param routes list of relationsships 431 @param routes list of relationsships
435 """ 432 """
436 from .AssociationItem import AssociationItem, Generalisation 433 from .AssociationItem import AssociationItem, AssociationType
437 for route in routes: 434 for route in routes:
438 if len(route) > 1: 435 if len(route) > 1:
439 assoc = AssociationItem( 436 assoc = AssociationItem(
440 self.__getCurrentShape(route[1]), 437 self.__getCurrentShape(route[1]),
441 self.__getCurrentShape(route[0]), 438 self.__getCurrentShape(route[0]),
442 Generalisation, 439 AssociationType.GENERALISATION,
443 topToBottom=True, 440 topToBottom=True,
444 colors=self.umlView.getDrawingColors()) 441 colors=self.umlView.getDrawingColors())
445 self.scene.addItem(assoc) 442 self.scene.addItem(assoc)
446 443
447 def getPersistenceData(self): 444 def getPersistenceData(self):

eric ide

mercurial