Graphics/PackageDiagramBuilder.py

Mon, 25 Feb 2013 18:32:53 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 25 Feb 2013 18:32:53 +0100
changeset 2433
f580320cd0aa
parent 2402
304fcefd3b04
child 2525
8b507a9a2d40
child 2953
703452a2876f
permissions
-rw-r--r--

Fixed a few issues introduced by the lazy import changes.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2039
diff changeset
3 # Copyright (c) 2007 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog showing a UML like class diagram of a package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import glob
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os.path
35
42f5cfc851da Ported the UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
12 import itertools
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
14 from PyQt4.QtGui import QProgressDialog, QApplication, QGraphicsTextItem
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
16 from .UMLDiagramBuilder import UMLDiagramBuilder
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Utilities
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
19 import Preferences
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
22 class PackageDiagramBuilder(UMLDiagramBuilder):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
24 Class implementing a builder for UML like class diagrams of a package.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
26 def __init__(self, dialog, view, project, package, noAttrs=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
30 @param dialog reference to the UML dialog (UMLDialog)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
31 @param view reference to the view object (UMLGraphicsView)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
32 @param project reference to the project object (Project)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param package name of a python package to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
36 super().__init__(dialog, view, project)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
37 self.setObjectName("PackageDiagram")
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
38
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.package = Utilities.normabspath(package)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.noAttrs = noAttrs
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
41
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
42 def initialize(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
43 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
44 Public method to initialize the object.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
45 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
46 pname = self.project.getProjectName()
2025
8bb085c59cd2 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2024
diff changeset
47 if pname:
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
48 name = self.trUtf8("Package Diagram {0}: {1}").format(
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
49 pname, self.project.getRelativePath(self.package))
2025
8bb085c59cd2 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2024
diff changeset
50 else:
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
51 name = self.trUtf8("Package Diagram: {0}").format(self.package)
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
52 self.umlView.setDiagramName(name)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
53
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def __getCurrentShape(self, name):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Private method to get the named shape.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @param name name of the shape (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @return shape (QCanvasItem)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 return self.allClasses.get(name)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
62
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 def __buildModulesDict(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 Private method to build a dictionary of modules contained in the package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @return dictionary of modules contained in the package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
2402
304fcefd3b04 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
69 import Utilities.ModuleParser
2433
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
70
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
71 supportedExt = \
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
72 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
73 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
74 ['*.rb']
1845
d481279d882b Fixed an issue parsing sources in the various UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
75 extensions = Preferences.getPython("PythonExtensions") + \
d481279d882b Fixed an issue parsing sources in the various UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
76 Preferences.getPython("Python3Extensions") + ['.rb']
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 moduleDict = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 modules = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 for ext in supportedExt:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 modules.extend(glob.glob(Utilities.normjoinpath(self.package, ext)))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 tot = len(modules)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 prog = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
86 None, 0, tot, self.parent())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 progress.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
89
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 for module in modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 progress.setValue(prog)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 prog += 1
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
94 try:
2039
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
95 mod = Utilities.ModuleParser.readModule(module, extensions=extensions,
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
96 caching=False)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 except ImportError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 name = mod.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 if name.startswith(self.package):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 name = name[len(self.package) + 1:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 moduleDict[name] = mod
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 finally:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 progress.setValue(tot)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
106 progress.deleteLater()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 return moduleDict
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
108
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
109 def __buildSubpackagesDict(self):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
110 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
111 Private method to build a dictionary of sub-packages contained in this package.
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
112
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
113 @return dictionary of sub-packages contained in this package
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
114 """
2433
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
115 import Utilities.ModuleParser
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
116
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
117 supportedExt = \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
118 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
119 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
120 ['*.rb']
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
121 extensions = Preferences.getPython("PythonExtensions") + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
122 Preferences.getPython("Python3Extensions") + ['.rb']
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
123
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
124 subpackagesDict = {}
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
125 subpackagesList = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
126
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
127 for subpackage in os.listdir(self.package):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
128 subpackagePath = os.path.join(self.package, subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
129 if os.path.isdir(subpackagePath) and \
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
130 subpackage != "__pycache__" and \
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
131 len(glob.glob(os.path.join(subpackagePath, "__init__.*"))) != 0:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
132 subpackagesList.append(subpackagePath)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
133
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
134 tot = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
135 for ext in supportedExt:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
136 for subpackage in subpackagesList:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
137 tot += len(glob.glob(Utilities.normjoinpath(subpackage, ext)))
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
138 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
139 prog = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
140 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
141 None, 0, tot, self.parent())
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
142 progress.show()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
143 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
144
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
145 for subpackage in subpackagesList:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
146 packageName = os.path.basename(subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
147 subpackagesDict[packageName] = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
148 modules = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
149 for ext in supportedExt:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
150 modules.extend(glob.glob(Utilities.normjoinpath(subpackage, ext)))
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
151 for module in modules:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
152 progress.setValue(prog)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
153 QApplication.processEvents()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
154 prog += 1
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
155 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
156 mod = Utilities.ModuleParser.readModule(
2039
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
157 module, extensions=extensions, caching=False)
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
158 except ImportError:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
159 continue
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
160 else:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
161 name = mod.name
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
162 if "." in name:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
163 name = name.rsplit(".", 1)[1]
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
164 subpackagesDict[packageName].append(name)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
165 subpackagesDict[packageName].sort()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
166 # move __init__ to the front
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
167 if "__init__" in subpackagesDict[packageName]:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
168 subpackagesDict[packageName].remove("__init__")
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
169 subpackagesDict[packageName].insert(0, "__init__")
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
170 finally:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
171 progress.setValue(tot)
2334
fc69ad77e18a Introduced a zoom widget in the status bar of several windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
172 progress.deleteLater()
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
173 return subpackagesDict
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
174
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
175 def buildDiagram(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
177 Public method to build the class shapes of the package diagram.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
181 self.allClasses = {}
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
182
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 initlist = glob.glob(os.path.join(self.package, '__init__.*'))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 if len(initlist) == 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
186 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 self.trUtf8("The directory <b>'{0}'</b> is not a package.")\
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 modules = self.__buildModulesDict()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 if not modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
194 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.trUtf8("The package <b>'{0}'</b> does not contain any modules.")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 # step 1: build all classes found in the modules
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 classesFound = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 module = modules[modName]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
204 for cls in list(module.classes.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 classesFound = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.__addLocalClass(cls, module.classes[cls], 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 if not classesFound:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
209 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 self.trUtf8("The package <b>'{0}'</b> does not contain any classes.")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 # step 2: build the class hierarchies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 routes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 nodes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
218 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 module = modules[modName]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 todo = [module.createHierarchy()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 while todo:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 hierarchy = todo[0]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
223 for className in list(hierarchy.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 if not cw and className.find('.') >= 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 cw = self.__getCurrentShape(className.split('.')[-1])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 if cw:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 self.allClasses[className] = cw
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 if cw and cw.noAttrs != self.noAttrs:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 cw = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 if cw and not (cw.external and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 (className in module.classes or
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 className in module.modules)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 ):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 if className not in nodes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 if className in module.classes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 # this is a local class (defined in this module)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
240 self.__addLocalClass(className, module.classes[className],
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 elif className in module.modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 # this is a local module (defined in this module)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
244 self.__addLocalClass(className, module.modules[className],
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 0, 0, True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 self.__addExternalClass(className, 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 if hierarchy.get(className):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 todo.append(hierarchy.get(className))
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
252 children = list(hierarchy.get(className).keys())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 for child in children:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 if (className, child) not in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 routes.append((className, child))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 del todo[0]
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
258
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
259 # step 3: build the subpackages
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
260 subpackages = self.__buildSubpackagesDict()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
261 for subpackage in sorted(subpackages.keys()):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
262 self.__addPackage(subpackage, subpackages[subpackage], 0, 0)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
263 nodes.append(subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
264
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.__arrangeClasses(nodes, routes[:])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 self.__createAssociations(routes)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
267 self.umlView.autoAdjustSceneSize(limit=True)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
268
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
269 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 Private method to arrange the shapes on the canvas.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
275 from . import GraphicsUtilities
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 generations = GraphicsUtilities.sort(nodes, routes)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 # calculate width and height of all elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 sizes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 for generation in generations:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 sizes.append([])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 for child in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 sizes[-1].append(self.__getCurrentShape(child).sceneBoundingRect())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 # calculate total width and total height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 width = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 height = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 widths = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 heights = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 for generation in sizes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 currentWidth = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 currentHeight = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 for rect in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 if rect.bottom() > currentHeight:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 currentHeight = rect.bottom()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 currentWidth = currentWidth + rect.right()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 # update totals
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 if currentWidth > width:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 width = currentWidth
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 height = height + currentHeight
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 # store generation info
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 widths.append(currentWidth)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 heights.append(currentHeight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 # add in some whitespace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 width = width * whiteSpaceFactor
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
310 ## rawHeight = height
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 height = height * whiteSpaceFactor - 20
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
312 ## verticalWhiteSpace = max(
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
313 ## (height - rawHeight) / (len(generations) - 1.0 or 2.0),
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
314 ## 40.0
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
315 ## )
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
316 verticalWhiteSpace = 40.0
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 sceneRect = self.umlView.sceneRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 width += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 height += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 swidth = width < sceneRect.width() and sceneRect.width() or width
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 sheight = height < sceneRect.height() and sceneRect.height() or height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 self.umlView.setSceneSize(swidth, sheight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 # distribute each generation across the width and the
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 # generations across height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 y = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 for currentWidth, currentHeight, generation in \
35
42f5cfc851da Ported the UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
329 itertools.zip_longest(widths, heights, generations):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 x = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 # whiteSpace is the space between any two elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 whiteSpace = (width - currentWidth - 20) / (len(generation) - 1.0 or 2.0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 for className in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 cw.setPos(x, y)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 rect = cw.sceneBoundingRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 x = x + rect.width() + whiteSpace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 y = y + currentHeight + verticalWhiteSpace
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
339
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
340 def __addLocalClass(self, className, _class, x, y, isRbModule=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 Private method to add a class defined in the module.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 @param className name of the class to be as a dictionary key (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 @param _class class to be shown (ModuleParser.Class)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 @param isRbModule flag indicating a Ruby module (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
350 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 meths = sorted(_class.methods.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 attrs = sorted(_class.attributes.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 name = _class.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 if isRbModule:
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
355 name = "{0} (Module)".format(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 cl = ClassModel(name, meths[:], attrs[:])
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
357 cw = ClassItem(cl, False, x, y, noAttrs=self.noAttrs, scene=self.scene)
2030
db11a2fe9bbc Implemented functions to save the UML graphics to disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2028
diff changeset
358 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 self.allClasses[className] = cw
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
360
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 def __addExternalClass(self, _class, x, y):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 Private method to add a class defined outside the module.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 If the canvas is too small to take the shape, it
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 is enlarged.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 @param _class class to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
372 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 cl = ClassModel(_class)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
374 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene)
2030
db11a2fe9bbc Implemented functions to save the UML graphics to disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2028
diff changeset
375 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 self.allClasses[_class] = cw
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
377
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
378 def __addPackage(self, name, modules, x, y):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
379 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
380 Private method to add a package to the diagram.
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
381
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
382 @param name package name to be shown (string)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
383 @param modules list of module names contained in the package
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
384 (list of strings)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
385 @param x x-coordinate (float)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
386 @param y y-coordinate (float)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
387 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
388 from .PackageItem import PackageItem, PackageModel
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
389 pm = PackageModel(name, modules)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
390 pw = PackageItem(pm, x, y, scene=self.scene)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
391 pw.setId(self.umlView.getItemId())
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
392 self.allClasses[name] = pw
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
393
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 def __createAssociations(self, routes):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 Private method to generate the associations between the class shapes.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 @param routes list of relationsships
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
400 from .AssociationItem import AssociationItem, Generalisation
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 for route in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 if len(route) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
403 assoc = AssociationItem(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 self.__getCurrentShape(route[1]),
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 self.__getCurrentShape(route[0]),
2024
717b72b32420 Changed the association layout for the package and class diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1845
diff changeset
406 Generalisation,
717b72b32420 Changed the association layout for the package and class diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1845
diff changeset
407 topToBottom=True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 self.scene.addItem(assoc)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
409
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
410 def getPersistenceData(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
411 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
412 Public method to get a string for data to be persisted.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
413
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
414 @return persisted data string (string)
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
415 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
416 return "package={0}, no_attributes={1}".format(self.package, self.noAttrs)
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
417
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
418 def parsePersistenceData(self, version, data):
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
419 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
420 Public method to parse persisted data.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
421
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
422 @param version version of the data (string)
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
423 @param data persisted data to be parsed (string)
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
424 @return flag indicating success (boolean)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
425 """
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
426 parts = data.split(", ")
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
427 if len(parts) != 2 or \
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
428 not parts[0].startswith("package=") or \
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
429 not parts[1].startswith("no_attributes="):
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
430 return False
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
431
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
432 self.package = parts[0].split("=", 1)[1].strip()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
433 self.noAttrs = Utilities.toBool(parts[1].split("=", 1)[1].strip())
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
434
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
435 self.initialize()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
436
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
437 return True

eric ide

mercurial