eric6/Graphics/PackageDiagramBuilder.py

Tue, 04 May 2021 20:03:40 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 04 May 2021 20:03:40 +0200
changeset 8289
871b40c5a77a
parent 8286
62ae22eae123
child 8291
3d79b1e5bf3c
permissions
-rw-r--r--

Changed some source docu string to the new style.

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

eric ide

mercurial