29 |
29 |
30 @param dialog reference to the UML dialog (UMLDialog) |
30 @param dialog reference to the UML dialog (UMLDialog) |
31 @param view reference to the view object (UMLGraphicsView) |
31 @param view reference to the view object (UMLGraphicsView) |
32 @param project reference to the project object (Project) |
32 @param project reference to the project object (Project) |
33 @param package name of a python package to be shown (string) |
33 @param package name of a python package to be shown (string) |
34 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean) |
34 @keyparam noAttrs flag indicating, that no attributes should be shown |
|
35 (boolean) |
35 """ |
36 """ |
36 super().__init__(dialog, view, project) |
37 super().__init__(dialog, view, project) |
37 self.setObjectName("PackageDiagram") |
38 self.setObjectName("PackageDiagram") |
38 |
39 |
39 self.package = Utilities.normabspath(package) |
40 self.package = Utilities.normabspath(package) |
60 """ |
61 """ |
61 return self.allClasses.get(name) |
62 return self.allClasses.get(name) |
62 |
63 |
63 def __buildModulesDict(self): |
64 def __buildModulesDict(self): |
64 """ |
65 """ |
65 Private method to build a dictionary of modules contained in the package. |
66 Private method to build a dictionary of modules contained in the |
|
67 package. |
66 |
68 |
67 @return dictionary of modules contained in the package. |
69 @return dictionary of modules contained in the package. |
68 """ |
70 """ |
69 import Utilities.ModuleParser |
71 import Utilities.ModuleParser |
70 |
72 |
71 supportedExt = \ |
73 supportedExt = \ |
72 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \ |
74 ['*{0}'.format(ext) for ext in |
73 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \ |
75 Preferences.getPython("PythonExtensions")] + \ |
|
76 ['*{0}'.format(ext) for ext in |
|
77 Preferences.getPython("Python3Extensions")] + \ |
74 ['*.rb'] |
78 ['*.rb'] |
75 extensions = Preferences.getPython("PythonExtensions") + \ |
79 extensions = Preferences.getPython("PythonExtensions") + \ |
76 Preferences.getPython("Python3Extensions") + ['.rb'] |
80 Preferences.getPython("Python3Extensions") + ['.rb'] |
77 |
81 |
78 moduleDict = {} |
82 moduleDict = {} |
90 for module in modules: |
94 for module in modules: |
91 progress.setValue(prog) |
95 progress.setValue(prog) |
92 QApplication.processEvents() |
96 QApplication.processEvents() |
93 prog += 1 |
97 prog += 1 |
94 try: |
98 try: |
95 mod = Utilities.ModuleParser.readModule(module, extensions=extensions, |
99 mod = Utilities.ModuleParser.readModule( |
96 caching=False) |
100 module, extensions=extensions, caching=False) |
97 except ImportError: |
101 except ImportError: |
98 continue |
102 continue |
99 else: |
103 else: |
100 name = mod.name |
104 name = mod.name |
101 if name.startswith(self.package): |
105 if name.startswith(self.package): |
106 progress.deleteLater() |
110 progress.deleteLater() |
107 return moduleDict |
111 return moduleDict |
108 |
112 |
109 def __buildSubpackagesDict(self): |
113 def __buildSubpackagesDict(self): |
110 """ |
114 """ |
111 Private method to build a dictionary of sub-packages contained in this package. |
115 Private method to build a dictionary of sub-packages contained in this |
|
116 package. |
112 |
117 |
113 @return dictionary of sub-packages contained in this package |
118 @return dictionary of sub-packages contained in this package |
114 """ |
119 """ |
115 import Utilities.ModuleParser |
120 import Utilities.ModuleParser |
116 |
121 |
117 supportedExt = \ |
122 supportedExt = \ |
118 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \ |
123 ['*{0}'.format(ext) for ext in |
119 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \ |
124 Preferences.getPython("PythonExtensions")] + \ |
|
125 ['*{0}'.format(ext) for ext in |
|
126 Preferences.getPython("Python3Extensions")] + \ |
120 ['*.rb'] |
127 ['*.rb'] |
121 extensions = Preferences.getPython("PythonExtensions") + \ |
128 extensions = Preferences.getPython("PythonExtensions") + \ |
122 Preferences.getPython("Python3Extensions") + ['.rb'] |
129 Preferences.getPython("Python3Extensions") + ['.rb'] |
123 |
130 |
124 subpackagesDict = {} |
131 subpackagesDict = {} |
145 for subpackage in subpackagesList: |
152 for subpackage in subpackagesList: |
146 packageName = os.path.basename(subpackage) |
153 packageName = os.path.basename(subpackage) |
147 subpackagesDict[packageName] = [] |
154 subpackagesDict[packageName] = [] |
148 modules = [] |
155 modules = [] |
149 for ext in supportedExt: |
156 for ext in supportedExt: |
150 modules.extend(glob.glob(Utilities.normjoinpath(subpackage, ext))) |
157 modules.extend(glob.glob( |
|
158 Utilities.normjoinpath(subpackage, ext))) |
151 for module in modules: |
159 for module in modules: |
152 progress.setValue(prog) |
160 progress.setValue(prog) |
153 QApplication.processEvents() |
161 QApplication.processEvents() |
154 prog += 1 |
162 prog += 1 |
155 try: |
163 try: |
190 |
198 |
191 modules = self.__buildModulesDict() |
199 modules = self.__buildModulesDict() |
192 if not modules: |
200 if not modules: |
193 ct = QGraphicsTextItem(None, self.scene) |
201 ct = QGraphicsTextItem(None, self.scene) |
194 ct.setHtml( |
202 ct.setHtml( |
195 self.trUtf8("The package <b>'{0}'</b> does not contain any modules.") |
203 self.trUtf8( |
|
204 "The package <b>'{0}'</b> does not contain any modules.") |
196 .format(self.package)) |
205 .format(self.package)) |
197 return |
206 return |
198 |
207 |
199 # step 1: build all classes found in the modules |
208 # step 1: build all classes found in the modules |
200 classesFound = False |
209 classesFound = False |
205 classesFound = True |
214 classesFound = True |
206 self.__addLocalClass(cls, module.classes[cls], 0, 0) |
215 self.__addLocalClass(cls, module.classes[cls], 0, 0) |
207 if not classesFound: |
216 if not classesFound: |
208 ct = QGraphicsTextItem(None, self.scene) |
217 ct = QGraphicsTextItem(None, self.scene) |
209 ct.setHtml( |
218 ct.setHtml( |
210 self.trUtf8("The package <b>'{0}'</b> does not contain any classes.") |
219 self.trUtf8( |
|
220 "The package <b>'{0}'</b> does not contain any classes.") |
211 .format(self.package)) |
221 .format(self.package)) |
212 return |
222 return |
213 |
223 |
214 # step 2: build the class hierarchies |
224 # step 2: build the class hierarchies |
215 routes = [] |
225 routes = [] |
235 if className not in nodes: |
245 if className not in nodes: |
236 nodes.append(className) |
246 nodes.append(className) |
237 else: |
247 else: |
238 if className in module.classes: |
248 if className in module.classes: |
239 # this is a local class (defined in this module) |
249 # this is a local class (defined in this module) |
240 self.__addLocalClass(className, module.classes[className], |
250 self.__addLocalClass( |
241 0, 0) |
251 className, module.classes[className], |
|
252 0, 0) |
242 elif className in module.modules: |
253 elif className in module.modules: |
243 # this is a local module (defined in this module) |
254 # this is a local module (defined in this module) |
244 self.__addLocalClass(className, module.modules[className], |
255 self.__addLocalClass( |
245 0, 0, True) |
256 className, module.modules[className], |
|
257 0, 0, True) |
246 else: |
258 else: |
247 self.__addExternalClass(className, 0, 0) |
259 self.__addExternalClass(className, 0, 0) |
248 nodes.append(className) |
260 nodes.append(className) |
249 |
261 |
250 if hierarchy.get(className): |
262 if hierarchy.get(className): |
283 # calculate width and height of all elements |
295 # calculate width and height of all elements |
284 sizes = [] |
296 sizes = [] |
285 for generation in generations: |
297 for generation in generations: |
286 sizes.append([]) |
298 sizes.append([]) |
287 for child in generation: |
299 for child in generation: |
288 sizes[-1].append(self.__getCurrentShape(child).sceneBoundingRect()) |
300 sizes[-1].append( |
|
301 self.__getCurrentShape(child).sceneBoundingRect()) |
289 |
302 |
290 # calculate total width and total height |
303 # calculate total width and total height |
291 width = 0 |
304 width = 0 |
292 height = 0 |
305 height = 0 |
293 widths = [] |
306 widths = [] |
332 y = 10.0 |
345 y = 10.0 |
333 for currentWidth, currentHeight, generation in \ |
346 for currentWidth, currentHeight, generation in \ |
334 itertools.zip_longest(widths, heights, generations): |
347 itertools.zip_longest(widths, heights, generations): |
335 x = 10.0 |
348 x = 10.0 |
336 # whiteSpace is the space between any two elements |
349 # whiteSpace is the space between any two elements |
337 whiteSpace = (width - currentWidth - 20) / (len(generation) - 1.0 or 2.0) |
350 whiteSpace = (width - currentWidth - 20) / \ |
|
351 (len(generation) - 1.0 or 2.0) |
338 for className in generation: |
352 for className in generation: |
339 cw = self.__getCurrentShape(className) |
353 cw = self.__getCurrentShape(className) |
340 cw.setPos(x, y) |
354 cw.setPos(x, y) |
341 rect = cw.sceneBoundingRect() |
355 rect = cw.sceneBoundingRect() |
342 x = x + rect.width() + whiteSpace |
356 x = x + rect.width() + whiteSpace |
416 """ |
430 """ |
417 Public method to get a string for data to be persisted. |
431 Public method to get a string for data to be persisted. |
418 |
432 |
419 @return persisted data string (string) |
433 @return persisted data string (string) |
420 """ |
434 """ |
421 return "package={0}, no_attributes={1}".format(self.package, self.noAttrs) |
435 return "package={0}, no_attributes={1}".format( |
|
436 self.package, self.noAttrs) |
422 |
437 |
423 def parsePersistenceData(self, version, data): |
438 def parsePersistenceData(self, version, data): |
424 """ |
439 """ |
425 Public method to parse persisted data. |
440 Public method to parse persisted data. |
426 |
441 |