eric6/Graphics/PackageDiagramBuilder.py

Sat, 31 Aug 2019 12:58:11 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Aug 2019 12:58:11 +0200
branch
without_py2_and_pyqt4
changeset 7192
a22eee00b052
parent 6942
2602857055c5
child 7229
53054eb5b15a
permissions
-rw-r--r--

Started removing runtime support for Python2 and PyQt4.

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
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2007 - 2019 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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3080
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2433
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import glob
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import os.path
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
14 from itertools import zip_longest
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
16 from PyQt5.QtWidgets import QApplication, QGraphicsTextItem
3071
83d066710d60 Added an extended progress dialog to make the progress bar label more descriptive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
17
83d066710d60 Added an extended progress dialog to make the progress bar label more descriptive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
18 from E5Gui.E5ProgressDialog import E5ProgressDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
20 from .UMLDiagramBuilder import UMLDiagramBuilder
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 import Utilities
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
23 import Preferences
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
25
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
26 class PackageDiagramBuilder(UMLDiagramBuilder):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
28 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
29 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
30 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
31 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
34 @param dialog reference to the UML dialog (UMLDialog)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
35 @param view reference to the view object (UMLGraphicsView)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
36 @param project reference to the project object (Project)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param package name of a python package to be shown (string)
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
38 @keyparam noAttrs flag indicating, that no attributes should be shown
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
39 (boolean)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2433
diff changeset
41 super(PackageDiagramBuilder, self).__init__(dialog, view, project)
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
42 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
43
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.package = Utilities.normabspath(package)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 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
46
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
47 def initialize(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
48 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
49 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
50 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
51 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
52 if pname:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
53 name = self.tr("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
54 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
55 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
56 name = self.tr("Package Diagram: {0}").format(self.package)
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
57 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
58
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def __getCurrentShape(self, name):
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 Private method to get the named shape.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param name name of the shape (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @return shape (QCanvasItem)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def __buildModulesDict(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
70 Private method to build a dictionary of modules contained in the
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
71 package.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 @return dictionary of modules contained in the package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
2402
304fcefd3b04 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
75 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
76
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
77 supportedExt = \
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
78 ['*{0}'.format(ext) for ext in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
79 Preferences.getPython("PythonExtensions")] + \
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
80 ['*{0}'.format(ext) for ext in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
81 Preferences.getPython("Python3Extensions")] + \
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
82 ['*.rb']
1845
d481279d882b Fixed an issue parsing sources in the various UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
83 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
84 Preferences.getPython("Python3Extensions") + ['.rb']
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 moduleDict = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 modules = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 for ext in supportedExt:
2997
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
89 modules.extend(glob.glob(
7f0ef975da9e Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
90 Utilities.normjoinpath(self.package, ext)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 tot = len(modules)
3071
83d066710d60 Added an extended progress dialog to make the progress bar label more descriptive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
92 progress = E5ProgressDialog(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
93 self.tr("Parsing modules..."),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
94 None, 0, tot, self.tr("%v/%m Modules"), self.parent())
3478
beec1d9c1851 Correct window titles of progress dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
95 progress.setWindowTitle(self.tr("Package Diagram"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 prog = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 progress.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
100
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 for module in modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 progress.setValue(prog)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105 try:
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
106 mod = Utilities.ModuleParser.readModule(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
107 module, extensions=extensions, caching=False)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 except ImportError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 name = mod.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 if name.startswith(self.package):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 name = name[len(self.package) + 1:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 moduleDict[name] = mod
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 finally:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 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
117 progress.deleteLater()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 return moduleDict
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
119
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
120 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
121 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
122 Private method to build a dictionary of sub-packages contained in this
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
123 package.
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
124
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
125 @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
126 """
2433
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
127 import Utilities.ModuleParser
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
128
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
129 supportedExt = \
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
130 ['*{0}'.format(ext) for ext in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
131 Preferences.getPython("PythonExtensions")] + \
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
132 ['*{0}'.format(ext) for ext in
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
133 Preferences.getPython("Python3Extensions")] + \
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
134 ['*.rb']
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
135 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
136 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
137
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
138 subpackagesDict = {}
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
139 subpackagesList = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
140
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
141 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
142 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
143 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
144 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
145 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
146 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
147
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
148 tot = 0
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 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
151 tot += len(glob.glob(Utilities.normjoinpath(subpackage, ext)))
3071
83d066710d60 Added an extended progress dialog to make the progress bar label more descriptive.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
152 progress = E5ProgressDialog(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
153 self.tr("Parsing modules..."),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
154 None, 0, tot, self.tr("%v/%m Modules"), self.parent())
3478
beec1d9c1851 Correct window titles of progress dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
155 progress.setWindowTitle(self.tr("Package Diagram"))
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
156 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
157 prog = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
158 progress.show()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
159 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
160
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
161 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
162 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
163 subpackagesDict[packageName] = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
164 modules = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
165 for ext in supportedExt:
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
166 modules.extend(glob.glob(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
167 Utilities.normjoinpath(subpackage, ext)))
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
168 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
169 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
170 QApplication.processEvents()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
171 prog += 1
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
172 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
173 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
174 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
175 except ImportError:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
176 continue
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
177 else:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
178 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
179 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
180 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
181 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
182 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
183 # 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
184 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
185 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
186 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
187 finally:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
188 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
189 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
190 return subpackagesDict
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
191
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
192 def buildDiagram(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
194 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
195
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
198 self.allClasses = {}
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
199
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 initlist = glob.glob(os.path.join(self.package, '__init__.*'))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if len(initlist) == 0:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
202 ct = QGraphicsTextItem(None)
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
203 self.scene.addItem(ct)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
204 ct.setHtml(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
205 self.tr("The directory <b>'{0}'</b> is not a package.")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 modules = self.__buildModulesDict()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 if not modules:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
211 ct = QGraphicsTextItem(None)
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
212 self.scene.addItem(ct)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
213 ct.setHtml(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
214 self.tr(
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
215 "The package <b>'{0}'</b> does not contain any modules.")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
216 .format(self.package))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 # step 1: build all classes found in the modules
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 classesFound = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
222 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 module = modules[modName]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
224 for cls in list(module.classes.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 classesFound = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 self.__addLocalClass(cls, module.classes[cls], 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 if not classesFound:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
228 ct = QGraphicsTextItem(None)
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
229 self.scene.addItem(ct)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
230 ct.setHtml(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
231 self.tr(
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
232 "The package <b>'{0}'</b> does not contain any classes.")
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
233 .format(self.package))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 # step 2: build the class hierarchies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 routes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 nodes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
240 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 module = modules[modName]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 todo = [module.createHierarchy()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 while todo:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 hierarchy = todo[0]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
245 for className in list(hierarchy.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 if not cw and className.find('.') >= 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 cw = self.__getCurrentShape(className.split('.')[-1])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 if cw:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 self.allClasses[className] = cw
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 if cw and cw.noAttrs != self.noAttrs:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 cw = None
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
253 if cw and not (cw.external and
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 (className in module.classes or
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 className in module.modules)
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
256 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 if className not in nodes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 if className in module.classes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 # this is a local class (defined in this module)
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
262 self.__addLocalClass(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
263 className, module.classes[className],
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
264 0, 0)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 elif className in module.modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 # this is a local module (defined in this module)
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
267 self.__addLocalClass(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
268 className, module.modules[className],
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
269 0, 0, True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 self.__addExternalClass(className, 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 if hierarchy.get(className):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 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
276 children = list(hierarchy.get(className).keys())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 for child in children:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 if (className, child) not in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 routes.append((className, child))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 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
282
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
283 # 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
284 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
285 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
286 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
287 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
288
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 self.__arrangeClasses(nodes, routes[:])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.__createAssociations(routes)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
291 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
292
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
293 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 Private method to arrange the shapes on the canvas.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 The algorithm is borrowed from Boa Constructor.
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
298
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
299 @param nodes list of nodes to arrange
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
300 @param routes list of routes
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
301 @param whiteSpaceFactor factor to increase whitespace between
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
302 items (float)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
304 from . import GraphicsUtilities
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 generations = GraphicsUtilities.sort(nodes, routes)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 # calculate width and height of all elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 sizes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 for generation in generations:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 sizes.append([])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 for child in generation:
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
312 sizes[-1].append(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
313 self.__getCurrentShape(child).sceneBoundingRect())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 # calculate total width and total height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 width = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 height = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 widths = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 heights = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 for generation in sizes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 currentWidth = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 currentHeight = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 for rect in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 if rect.bottom() > currentHeight:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 currentHeight = rect.bottom()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 currentWidth = currentWidth + rect.right()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 # update totals
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 if currentWidth > width:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 width = currentWidth
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 height = height + currentHeight
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 # store generation info
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 widths.append(currentWidth)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 heights.append(currentHeight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 # add in some whitespace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 width = width * whiteSpaceFactor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 height = height * whiteSpaceFactor - 20
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
341 verticalWhiteSpace = 40.0
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 sceneRect = self.umlView.sceneRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 width += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 height += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 swidth = width < sceneRect.width() and sceneRect.width() or width
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 sheight = height < sceneRect.height() and sceneRect.height() or height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 self.umlView.setSceneSize(swidth, sheight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 # distribute each generation across the width and the
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 # generations across height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 y = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 for currentWidth, currentHeight, generation in \
2602
affc66a603c7 Fixes for changed API.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2525
diff changeset
354 zip_longest(widths, heights, generations):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 x = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 # whiteSpace is the space between any two elements
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
357 whiteSpace = (width - currentWidth - 20) / \
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
358 (len(generation) - 1.0 or 2.0)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 for className in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 cw.setPos(x, y)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 rect = cw.sceneBoundingRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 x = x + rect.width() + whiteSpace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 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
365
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
366 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
367 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 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
369
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 @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
371 @param _class class to be shown (ModuleParser.Class)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 @param isRbModule flag indicating a Ruby module (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
376 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 meths = sorted(_class.methods.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 attrs = sorted(_class.attributes.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 name = _class.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 if isRbModule:
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
381 name = "{0} (Module)".format(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 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
383 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
384 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 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
386
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 def __addExternalClass(self, _class, x, y):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 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
390
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 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
392 is enlarged.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 @param _class class to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
398 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 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
400 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
401 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 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
403
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
404 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
405 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
406 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
407
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
408 @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
409 @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
410 (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
411 @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
412 @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
413 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
414 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
415 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
416 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
417 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
418 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
419
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 def __createAssociations(self, routes):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 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
423
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 @param routes list of relationsships
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
426 from .AssociationItem import AssociationItem, Generalisation
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 for route in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 if len(route) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
429 assoc = AssociationItem(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
430 self.__getCurrentShape(route[1]),
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
431 self.__getCurrentShape(route[0]),
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
432 Generalisation,
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
433 topToBottom=True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 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
435
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
436 def getPersistenceData(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
437 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
438 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
439
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
440 @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
441 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
442 return "package={0}, no_attributes={1}".format(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
443 self.package, self.noAttrs)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
444
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
445 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
446 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
447 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
448
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
449 @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
450 @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
451 @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
452 """
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
453 parts = data.split(", ")
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
454 if len(parts) != 2 or \
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
455 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
456 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
457 return False
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
458
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
459 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
460 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
461
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
462 self.initialize()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
463
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
464 return True

eric ide

mercurial