eric6/Graphics/PackageDiagramBuilder.py

Sat, 08 May 2021 18:34:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 08 May 2021 18:34:08 +0200
changeset 8295
3f5e8b0a338e
parent 8291
3d79b1e5bf3c
child 8400
b3eefd7e58d1
permissions
-rw-r--r--

UML Diagrams
- added code to load diagrams saved as JSON files
- changed the prining code

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
8291
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
48
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
49 self.__relPackage = (
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
50 self.project.getRelativePath(self.package)
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
51 if self.project.isProjectSource(self.package) else
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
52 ""
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
53 )
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
54
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
55 def initialize(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
56 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
57 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
58 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
59 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
60 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
61 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
62 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
63 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
64 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
65 )
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
66 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
67
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def __getCurrentShape(self, name):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Private method to get the named shape.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
72 @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
73 @type str
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
74 @return shape
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
75 @rtype QCanvasItem
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 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
78
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def __buildModulesDict(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
81 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
82 package.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
84 @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
85 @rtype dict
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
2402
304fcefd3b04 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
87 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
88
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
89 supportedExt = (
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
90 ['*{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
91 Preferences.getPython("Python3Extensions")] +
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
92 ['*.rb']
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
93 )
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
94 extensions = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
95 Preferences.getPython("Python3Extensions") +
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
96 ['.rb']
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
97 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 moduleDict = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 modules = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 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
102 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
103 Utilities.normjoinpath(self.package, ext)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105 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
106 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
107 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
108 progress.setWindowTitle(self.tr("Package Diagram"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 progress.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
112
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
113 for prog, module in enumerate(modules):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 progress.setValue(prog)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 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
116 try:
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
117 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
118 module, extensions=extensions, caching=False)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 except ImportError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 name = mod.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 if name.startswith(self.package):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 name = name[len(self.package) + 1:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 moduleDict[name] = mod
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 finally:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 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
128 progress.deleteLater()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 return moduleDict
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
130
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
131 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
132 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
133 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
134 package.
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
135
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
136 @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
137 @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
138 """
2433
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
139 import Utilities.ModuleParser
f580320cd0aa Fixed a few issues introduced by the lazy import changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2402
diff changeset
140
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
141 supportedExt = (
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
142 ['*{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
143 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
144 ['*.rb']
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
145 )
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
146 extensions = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
147 Preferences.getPython("Python3Extensions") +
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
148 ['.rb']
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
149 )
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
150
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
151 subpackagesDict = {}
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
152 subpackagesList = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
153
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
154 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
155 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
156 if (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
157 os.path.isdir(subpackagePath) and
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
158 subpackage != "__pycache__" and
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 len(glob.glob(
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
160 os.path.join(subpackagePath, "__init__.*")
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
161 )) != 0
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
162 ):
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
163 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
164
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
165 tot = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
174 progress.show()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
175 QApplication.processEvents()
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
176
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
177 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
178 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
179 subpackagesDict[packageName] = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
180 modules = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
181 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
182 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
183 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
184 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
185 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
186 QApplication.processEvents()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
187 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
188 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
189 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
190 except ImportError:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
191 continue
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
192 else:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
193 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
194 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
195 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
196 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
197 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
198 # 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
199 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
200 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
201 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
202 finally:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
203 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
204 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
205 return subpackagesDict
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
206
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
207 def buildDiagram(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
209 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
210
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
213 self.allClasses = {}
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
214
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 initlist = glob.glob(os.path.join(self.package, '__init__.*'))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 if len(initlist) == 0:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
217 ct = QGraphicsTextItem(None)
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
218 self.scene.addItem(ct)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
219 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
220 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
221 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 modules = self.__buildModulesDict()
8295
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
225 subpackages = self.__buildSubpackagesDict()
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
226
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
227 if not modules and not subpackages:
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)
8295
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
230 ct.setHtml(self.buildErrorMessage(
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
231 self.tr("The package <b>'{0}'</b> does not contain any modules"
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
232 " or subpackages.").format(self.package)
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
233 ))
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 1: build all classes found in the modules
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 classesFound = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
239 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 module = modules[modName]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 for cls in list(module.classes.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 classesFound = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 self.__addLocalClass(cls, module.classes[cls], 0, 0)
8295
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
244 if not classesFound and not subpackages:
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
245 ct = QGraphicsTextItem(None)
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
246 self.scene.addItem(ct)
8295
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
247 ct.setHtml(self.buildErrorMessage(
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
248 self.tr("The package <b>'{0}'</b> does not contain any"
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
249 " classes or subpackages.").format(self.package)
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
250 ))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 # step 2: build the class hierarchies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 routes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 nodes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
257 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 module = modules[modName]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 todo = [module.createHierarchy()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 while todo:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 hierarchy = todo[0]
8286
62ae22eae123 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8277
diff changeset
262 for className in hierarchy:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 if not cw and className.find('.') >= 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 cw = self.__getCurrentShape(className.split('.')[-1])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 if cw:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 self.allClasses[className] = cw
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 if cw and cw.noAttrs != self.noAttrs:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 cw = None
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
270 if cw and not (cw.external and
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 (className in module.classes or
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 className in module.modules)
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
273 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 if className not in nodes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 if className in module.classes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 # 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
279 self.__addLocalClass(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
280 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
281 0, 0)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 elif className in module.modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 # 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
284 self.__addLocalClass(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
285 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
286 0, 0, True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 self.__addExternalClass(className, 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 if hierarchy.get(className):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 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
293 children = list(hierarchy.get(className).keys())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 for child in children:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 if (className, child) not in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 routes.append((className, child))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 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
299
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
300 # 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
301 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
302 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
303 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
304
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 self.__arrangeClasses(nodes, routes[:])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.__createAssociations(routes)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
307 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
308
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
309 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 Private method to arrange the shapes on the canvas.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 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
314
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2433
diff changeset
315 @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
316 @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
317 @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
318 @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
319 @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
320 items
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
321 @type float
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
323 from . import GraphicsUtilities
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 generations = GraphicsUtilities.sort(nodes, routes)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 # calculate width and height of all elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 sizes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 for generation in generations:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 sizes.append([])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 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
331 sizes[-1].append(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
332 self.__getCurrentShape(child).sceneBoundingRect())
0
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 # calculate total width and total height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 width = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 height = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 widths = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 heights = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 for generation in sizes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 currentWidth = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 currentHeight = 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 for rect in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 if rect.bottom() > currentHeight:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 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
346 currentWidth += rect.right()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 # update totals
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 if currentWidth > width:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 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
351 height += currentHeight
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 # store generation info
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 widths.append(currentWidth)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 heights.append(currentHeight)
8286
62ae22eae123 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8277
diff changeset
356
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 # 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
358 width *= whiteSpaceFactor
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 height = height * whiteSpaceFactor - 20
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
360 verticalWhiteSpace = 40.0
0
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 sceneRect = self.umlView.sceneRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 width += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 height += 50.0
8286
62ae22eae123 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8277
diff changeset
365 swidth = sceneRect.width() if width < sceneRect.width() else width
62ae22eae123 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8277
diff changeset
366 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
367 self.umlView.setSceneSize(swidth, sheight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 # distribute each generation across the width and the
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 # generations across height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 y = 10.0
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
372 for currentWidth, currentHeight, generation in (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
373 zip_longest(widths, heights, generations)
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
374 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 x = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 # 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
377 whiteSpace = (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
378 (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
379 (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
380 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 for className in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 cw.setPos(x, y)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 rect = cw.sceneBoundingRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 x = x + rect.width() + whiteSpace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 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
387
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
388 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
389 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 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
391
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
392 @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
393 @type str
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
394 @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
395 @type ModuleParser.Class
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
396 @param x x-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
397 @type float
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
398 @param y y-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
399 @type float
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
400 @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
401 @type bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
403 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 name = _class.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if isRbModule:
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
406 name = "{0} (Module)".format(name)
8277
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
407 cl = ClassModel(
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
408 name,
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
409 sorted(_class.methods.keys())[:],
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
410 sorted(_class.attributes.keys())[:],
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
411 sorted(_class.globals.keys())[:]
ea734702ae94 UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8270
diff changeset
412 )
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
413 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
414 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
415 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 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
417
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418 def __addExternalClass(self, _class, x, y):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 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
421
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 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
423 is enlarged.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
425 @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
426 @type ModuleParser.Class
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
427 @param x x-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
428 @type float
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
429 @param y y-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
430 @type float
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
432 from .ClassItem import ClassItem, ClassModel
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 cl = ClassModel(_class)
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
434 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
435 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
436 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 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
438
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
439 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
440 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
441 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
442
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
443 @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
444 @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
445 @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
446 @type list of str
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
447 @param x x-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
448 @type float
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
449 @param y y-coordinate
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
450 @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
451 """
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2334
diff changeset
452 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
453 pm = PackageModel(name, modules)
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
454 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
455 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
456 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
457 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
458
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 def __createAssociations(self, routes):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 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
462
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 @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
464 @type list of tuple of (str, str)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 """
8270
6ba3564b7161 Modernized some more code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8257
diff changeset
466 from .AssociationItem import AssociationItem, AssociationType
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 for route in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 if len(route) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
469 assoc = AssociationItem(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
470 self.__getCurrentShape(route[1]),
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
471 self.__getCurrentShape(route[0]),
8270
6ba3564b7161 Modernized some more code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8257
diff changeset
472 AssociationType.GENERALISATION,
7529
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
473 topToBottom=True,
2b8a0d8ba12a UML Diagrams: added support for dark color scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
474 colors=self.umlView.getDrawingColors())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 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
476
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
477 def getPersistenceData(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
478 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
479 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
480
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
481 @return persisted data string
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
482 @rtype str
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
483 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
484 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
485 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
486
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
487 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
488 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
489 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
490
8289
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
491 @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
492 @type str
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
493 @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
494 @type str
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
495 @return flag indicating success
871b40c5a77a Changed some source docu string to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8286
diff changeset
496 @rtype bool
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
497 """
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
498 parts = data.split(", ")
7254
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
499 if (
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
500 len(parts) != 2 or
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
501 not parts[0].startswith("package=") or
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
502 not parts[1].startswith("no_attributes=")
f00d825fbdb3 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
503 ):
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
504 return False
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
505
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
506 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
507 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
508
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
509 self.initialize()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
510
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
511 return True
8291
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
512
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
513 def toDict(self):
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
514 """
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
515 Public method to collect data to be persisted.
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
516
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
517 @return dictionary containing data to be persisted
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
518 @rtype dict
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
519 """
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
520 data = {
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
521 "project_name": self.project.getProjectName(),
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
522 "no_attributes": self.noAttrs,
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
523 }
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
524
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
525 data["package"] = (
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
526 Utilities.fromNativeSeparators(self.__relPackage)
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
527 if self.__relPackage else
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
528 Utilities.fromNativeSeparators(self.package)
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
529 )
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
530
3d79b1e5bf3c UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8289
diff changeset
531 return data
8295
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
532
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
533 def fromDict(self, version, data):
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
534 """
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
535 Public method to populate the class with data persisted by 'toDict()'.
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
536
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
537 @param version version of the data
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
538 @type str
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
539 @param data dictionary containing the persisted data
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
540 @type dict
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
541 @return tuple containing a flag indicating success and an info
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
542 message in case the diagram belongs to a different project
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
543 @rtype tuple of (bool, str)
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
544 """
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
545 try:
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
546 self.noAttrs = data["no_attributes"]
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
547
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
548 package = Utilities.toNativeSeparators(data["package"])
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
549 if os.path.isabs(package):
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
550 self.package = package
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
551 self.__relPackage = ""
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
552 else:
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
553 # relative package paths indicate a project package
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
554 if data["project_name"] != self.project.getProjectName():
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
555 msg = self.tr(
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
556 "<p>The diagram belongs to project <b>{0}</b>."
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
557 " Please open it and try again.</p>"
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
558 ).format(data["project_name"])
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
559 return False, msg
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
560
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
561 self.__relPackage = package
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
562 self.package = self.project.getAbsolutePath(package)
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
563 except KeyError:
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
564 return False, ""
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
565
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
566 self.initialize()
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
567
3f5e8b0a338e UML Diagrams
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8291
diff changeset
568 return True, ""

eric ide

mercurial