12 from PyQt4.QtCore import pyqtSignal |
12 from PyQt4.QtCore import pyqtSignal |
13 from PyQt4.QtGui import QDialog, QInputDialog, QMenu |
13 from PyQt4.QtGui import QDialog, QInputDialog, QMenu |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from E5Gui import E5MessageBox |
16 |
16 |
17 from UI.BrowserModel import BrowserFileItem, BrowserClassItem, BrowserMethodItem, \ |
17 from UI.BrowserModel import BrowserFileItem, BrowserClassItem, \ |
18 BrowserClassAttributeItem |
18 BrowserMethodItem, BrowserClassAttributeItem |
19 |
19 |
20 from .ProjectBrowserModel import ProjectBrowserFileItem, \ |
20 from .ProjectBrowserModel import ProjectBrowserFileItem, \ |
21 ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem, \ |
21 ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem, \ |
22 ProjectBrowserSourceType |
22 ProjectBrowserSourceType |
23 from .ProjectBaseBrowser import ProjectBaseBrowser |
23 from .ProjectBaseBrowser import ProjectBaseBrowser |
28 |
28 |
29 class ProjectSourcesBrowser(ProjectBaseBrowser): |
29 class ProjectSourcesBrowser(ProjectBaseBrowser): |
30 """ |
30 """ |
31 A class used to display the Sources part of the project. |
31 A class used to display the Sources part of the project. |
32 |
32 |
33 @signal closeSourceWindow(str) emitted after a file has been removed/deleted |
33 @signal closeSourceWindow(str) emitted after a file has been |
34 from the project |
34 removed/deleted from the project |
35 @signal showMenu(str, QMenu) emitted when a menu is about to be shown. The name |
35 @signal showMenu(str, QMenu) emitted when a menu is about to be shown. |
36 of the menu and a reference to the menu are given. |
36 The name of the menu and a reference to the menu are given. |
37 @signal sourceFile(str) emitted to open the given file. |
37 @signal sourceFile(str) emitted to open the given file. |
38 @signal sourceFile(str, int) emitted to open the given file at the given line. |
38 @signal sourceFile(str, int) emitted to open the given file at the given |
39 @signal sourceFile(str, int, str) emitted to open the given file as the given type |
39 line. |
40 at the given line. |
40 @signal sourceFile(str, int, str) emitted to open the given file as the |
|
41 given type at the given line. |
41 """ |
42 """ |
42 showMenu = pyqtSignal(str, QMenu) |
43 showMenu = pyqtSignal(str, QMenu) |
43 |
44 |
44 def __init__(self, project, parent=None): |
45 def __init__(self, project, parent=None): |
45 """ |
46 """ |
46 Constructor |
47 Constructor |
47 |
48 |
48 @param project reference to the project object |
49 @param project reference to the project object |
49 @param parent parent widget of this browser (QWidget) |
50 @param parent parent widget of this browser (QWidget) |
50 """ |
51 """ |
51 ProjectBaseBrowser.__init__(self, project, ProjectBrowserSourceType, parent) |
52 ProjectBaseBrowser.__init__(self, project, ProjectBrowserSourceType, |
|
53 parent) |
52 |
54 |
53 self.selectedItemsFilter = \ |
55 self.selectedItemsFilter = \ |
54 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] |
56 [ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem] |
55 |
57 |
56 self.setWindowTitle(self.trUtf8('Sources')) |
58 self.setWindowTitle(self.trUtf8('Sources')) |
57 |
59 |
58 self.setWhatsThis(self.trUtf8( |
60 self.setWhatsThis(self.trUtf8( |
59 """<b>Project Sources Browser</b>""" |
61 """<b>Project Sources Browser</b>""" |
60 """<p>This allows to easily see all sources contained in the current""" |
62 """<p>This allows to easily see all sources contained in the""" |
61 """ project. Several actions can be executed via the context menu.</p>""" |
63 """ current project. Several actions can be executed via the""" |
|
64 """ context menu.</p>""" |
62 )) |
65 )) |
63 |
66 |
64 project.prepareRepopulateItem.connect(self._prepareRepopulateItem) |
67 project.prepareRepopulateItem.connect(self._prepareRepopulateItem) |
65 project.completeRepopulateItem.connect(self._completeRepopulateItem) |
68 project.completeRepopulateItem.connect(self._completeRepopulateItem) |
66 |
69 |
98 Protected overloaded method to generate the popup menu. |
101 Protected overloaded method to generate the popup menu. |
99 """ |
102 """ |
100 ProjectBaseBrowser._createPopupMenus(self) |
103 ProjectBaseBrowser._createPopupMenus(self) |
101 self.sourceMenuActions = {} |
104 self.sourceMenuActions = {} |
102 |
105 |
103 if self.project.pdata["PROGLANGUAGE"][0] in ["Python", "Python2", "Python3"]: |
106 if self.project.pdata["PROGLANGUAGE"][0] in \ |
|
107 ["Python", "Python2", "Python3"]: |
104 self.__createPythonPopupMenus() |
108 self.__createPythonPopupMenus() |
105 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": |
109 elif self.project.pdata["PROGLANGUAGE"][0] == "Ruby": |
106 self.__createRubyPopupMenus() |
110 self.__createRubyPopupMenus() |
107 |
111 |
108 def __createPythonPopupMenus(self): |
112 def __createPythonPopupMenus(self): |
111 """ |
115 """ |
112 self.checksMenu = QMenu(self.trUtf8('Check')) |
116 self.checksMenu = QMenu(self.trUtf8('Check')) |
113 self.checksMenu.aboutToShow.connect(self.__showContextMenuCheck) |
117 self.checksMenu.aboutToShow.connect(self.__showContextMenuCheck) |
114 |
118 |
115 self.menuShow = QMenu(self.trUtf8('Show')) |
119 self.menuShow = QMenu(self.trUtf8('Show')) |
116 self.menuShow.addAction(self.trUtf8('Code metrics...'), self.__showCodeMetrics) |
120 self.menuShow.addAction( |
|
121 self.trUtf8('Code metrics...'), self.__showCodeMetrics) |
117 self.coverageMenuAction = self.menuShow.addAction( |
122 self.coverageMenuAction = self.menuShow.addAction( |
118 self.trUtf8('Code coverage...'), self.__showCodeCoverage) |
123 self.trUtf8('Code coverage...'), self.__showCodeCoverage) |
119 self.profileMenuAction = self.menuShow.addAction( |
124 self.profileMenuAction = self.menuShow.addAction( |
120 self.trUtf8('Profile data...'), self.__showProfileData) |
125 self.trUtf8('Profile data...'), self.__showProfileData) |
121 self.menuShow.aboutToShow.connect(self.__showContextMenuShow) |
126 self.menuShow.aboutToShow.connect(self.__showContextMenuShow) |
126 self.graphicsMenu.addAction( |
131 self.graphicsMenu.addAction( |
127 self.trUtf8("Package Diagram..."), self.__showPackageDiagram) |
132 self.trUtf8("Package Diagram..."), self.__showPackageDiagram) |
128 self.importsDiagramAction = self.graphicsMenu.addAction( |
133 self.importsDiagramAction = self.graphicsMenu.addAction( |
129 self.trUtf8("Imports Diagram..."), self.__showImportsDiagram) |
134 self.trUtf8("Imports Diagram..."), self.__showImportsDiagram) |
130 self.graphicsMenu.addAction( |
135 self.graphicsMenu.addAction( |
131 self.trUtf8("Application Diagram..."), self.__showApplicationDiagram) |
136 self.trUtf8("Application Diagram..."), |
|
137 self.__showApplicationDiagram) |
132 self.graphicsMenu.addSeparator() |
138 self.graphicsMenu.addSeparator() |
133 self.graphicsMenu.addAction(UI.PixmapCache.getIcon("open.png"), |
139 self.graphicsMenu.addAction(UI.PixmapCache.getIcon("open.png"), |
134 self.trUtf8("Load Diagram..."), self.__loadDiagram) |
140 self.trUtf8("Load Diagram..."), self.__loadDiagram) |
135 self.graphicsMenu.aboutToShow.connect(self.__showContextMenuGraphics) |
141 self.graphicsMenu.aboutToShow.connect(self.__showContextMenuGraphics) |
136 |
142 |
137 self.unittestAction = self.sourceMenu.addAction( |
143 self.unittestAction = self.sourceMenu.addAction( |
138 self.trUtf8('Run unittest...'), self.handleUnittest) |
144 self.trUtf8('Run unittest...'), self.handleUnittest) |
139 self.sourceMenu.addSeparator() |
145 self.sourceMenu.addSeparator() |
140 act = self.sourceMenu.addAction(self.trUtf8('Rename file'), self._renameFile) |
146 act = self.sourceMenu.addAction( |
|
147 self.trUtf8('Rename file'), self._renameFile) |
141 self.menuActions.append(act) |
148 self.menuActions.append(act) |
142 act = self.sourceMenu.addAction(self.trUtf8('Remove from project'), |
149 act = self.sourceMenu.addAction(self.trUtf8('Remove from project'), |
143 self._removeFile) |
150 self._removeFile) |
144 self.menuActions.append(act) |
151 self.menuActions.append(act) |
145 act = self.sourceMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
152 act = self.sourceMenu.addAction( |
|
153 self.trUtf8('Delete'), self.__deleteFile) |
146 self.menuActions.append(act) |
154 self.menuActions.append(act) |
147 self.sourceMenu.addSeparator() |
155 self.sourceMenu.addSeparator() |
148 self.sourceMenu.addAction(self.trUtf8('New package...'), |
156 self.sourceMenu.addAction(self.trUtf8('New package...'), |
149 self.__addNewPackage) |
157 self.__addNewPackage) |
150 self.sourceMenu.addAction(self.trUtf8('Add source files...'), |
158 self.sourceMenu.addAction(self.trUtf8('Add source files...'), |
202 self.attributeMenu.addAction(self.trUtf8('Expand all directories'), |
210 self.attributeMenu.addAction(self.trUtf8('Expand all directories'), |
203 self._expandAllDirs) |
211 self._expandAllDirs) |
204 self.attributeMenu.addAction(self.trUtf8('Collapse all directories'), |
212 self.attributeMenu.addAction(self.trUtf8('Collapse all directories'), |
205 self._collapseAllDirs) |
213 self._collapseAllDirs) |
206 self.attributeMenu.addSeparator() |
214 self.attributeMenu.addSeparator() |
207 self.attributeMenu.addAction(self.trUtf8('Configure...'), self._configure) |
215 self.attributeMenu.addAction( |
|
216 self.trUtf8('Configure...'), self._configure) |
208 |
217 |
209 self.backMenu = QMenu(self) |
218 self.backMenu = QMenu(self) |
210 self.backMenu.addAction(self.trUtf8('New package...'), |
219 self.backMenu.addAction(self.trUtf8('New package...'), |
211 self.__addNewPackage) |
220 self.__addNewPackage) |
212 self.backMenu.addAction(self.trUtf8('Add source files...'), |
221 self.backMenu.addAction(self.trUtf8('Add source files...'), |
224 |
233 |
225 self.multiMenu.addSeparator() |
234 self.multiMenu.addSeparator() |
226 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
235 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
227 self._removeFile) |
236 self._removeFile) |
228 self.multiMenuActions.append(act) |
237 self.multiMenuActions.append(act) |
229 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
238 act = self.multiMenu.addAction( |
|
239 self.trUtf8('Delete'), self.__deleteFile) |
230 self.multiMenuActions.append(act) |
240 self.multiMenuActions.append(act) |
231 self.multiMenu.addSeparator() |
241 self.multiMenu.addSeparator() |
232 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
242 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
233 self._expandAllDirs) |
243 self._expandAllDirs) |
234 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
244 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
235 self._collapseAllDirs) |
245 self._collapseAllDirs) |
236 self.multiMenu.addSeparator() |
246 self.multiMenu.addSeparator() |
237 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
247 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
238 |
248 |
239 self.dirMenu = QMenu(self) |
249 self.dirMenu = QMenu(self) |
240 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) |
250 act = self.dirMenu.addAction( |
|
251 self.trUtf8('Remove from project'), self._removeDir) |
241 self.dirMenuActions.append(act) |
252 self.dirMenuActions.append(act) |
242 act = self.dirMenu.addAction(self.trUtf8('Delete'), self._deleteDirectory) |
253 act = self.dirMenu.addAction( |
|
254 self.trUtf8('Delete'), self._deleteDirectory) |
243 self.dirMenuActions.append(act) |
255 self.dirMenuActions.append(act) |
244 self.dirMenu.addSeparator() |
256 self.dirMenu.addSeparator() |
245 self.dirMenu.addAction(self.trUtf8('New package...'), self.__addNewPackage) |
257 self.dirMenu.addAction( |
246 self.dirMenu.addAction(self.trUtf8('Add source files...'), self.__addSourceFiles) |
258 self.trUtf8('New package...'), self.__addNewPackage) |
|
259 self.dirMenu.addAction( |
|
260 self.trUtf8('Add source files...'), self.__addSourceFiles) |
247 self.dirMenu.addAction(self.trUtf8('Add source directory...'), |
261 self.dirMenu.addAction(self.trUtf8('Add source directory...'), |
248 self.__addSourceDirectory) |
262 self.__addSourceDirectory) |
249 self.dirMenu.addSeparator() |
263 self.dirMenu.addSeparator() |
250 act = self.dirMenu.addMenu(self.graphicsMenu) |
264 act = self.dirMenu.addMenu(self.graphicsMenu) |
251 self.dirMenu.addSeparator() |
265 self.dirMenu.addSeparator() |
265 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), |
279 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), |
266 self._expandAllDirs) |
280 self._expandAllDirs) |
267 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), |
281 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), |
268 self._collapseAllDirs) |
282 self._collapseAllDirs) |
269 self.dirMultiMenu.addSeparator() |
283 self.dirMultiMenu.addSeparator() |
270 self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
284 self.dirMultiMenu.addAction( |
|
285 self.trUtf8('Configure...'), self._configure) |
271 |
286 |
272 self.sourceMenu.aboutToShow.connect(self.__showContextMenu) |
287 self.sourceMenu.aboutToShow.connect(self.__showContextMenu) |
273 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) |
288 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) |
274 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) |
289 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) |
275 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) |
290 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) |
290 self.graphicsMenu.addSeparator() |
305 self.graphicsMenu.addSeparator() |
291 self.graphicsMenu.addAction(UI.PixmapCache.getIcon("fileOpen.png"), |
306 self.graphicsMenu.addAction(UI.PixmapCache.getIcon("fileOpen.png"), |
292 self.trUtf8("Load Diagram..."), self.__loadDiagram) |
307 self.trUtf8("Load Diagram..."), self.__loadDiagram) |
293 |
308 |
294 self.sourceMenu.addSeparator() |
309 self.sourceMenu.addSeparator() |
295 act = self.sourceMenu.addAction(self.trUtf8('Rename file'), self._renameFile) |
310 act = self.sourceMenu.addAction( |
|
311 self.trUtf8('Rename file'), self._renameFile) |
296 self.menuActions.append(act) |
312 self.menuActions.append(act) |
297 act = self.sourceMenu.addAction(self.trUtf8('Remove from project'), |
313 act = self.sourceMenu.addAction(self.trUtf8('Remove from project'), |
298 self._removeFile) |
314 self._removeFile) |
299 self.menuActions.append(act) |
315 self.menuActions.append(act) |
300 act = self.sourceMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
316 act = self.sourceMenu.addAction( |
|
317 self.trUtf8('Delete'), self.__deleteFile) |
301 self.menuActions.append(act) |
318 self.menuActions.append(act) |
302 self.sourceMenu.addSeparator() |
319 self.sourceMenu.addSeparator() |
303 self.sourceMenu.addAction(self.trUtf8('Add source files...'), |
320 self.sourceMenu.addAction(self.trUtf8('Add source files...'), |
304 self.__addSourceFiles) |
321 self.__addSourceFiles) |
305 self.sourceMenu.addAction(self.trUtf8('Add source directory...'), |
322 self.sourceMenu.addAction(self.trUtf8('Add source directory...'), |
313 self._collapseAllDirs) |
330 self._collapseAllDirs) |
314 self.sourceMenu.addSeparator() |
331 self.sourceMenu.addSeparator() |
315 self.sourceMenu.addAction(self.trUtf8('Configure...'), self._configure) |
332 self.sourceMenu.addAction(self.trUtf8('Configure...'), self._configure) |
316 |
333 |
317 self.menu.addSeparator() |
334 self.menu.addSeparator() |
318 self.menu.addAction(self.trUtf8('Add source files...'), self.__addSourceFiles) |
335 self.menu.addAction( |
|
336 self.trUtf8('Add source files...'), self.__addSourceFiles) |
319 self.menu.addAction(self.trUtf8('Add source directory...'), |
337 self.menu.addAction(self.trUtf8('Add source directory...'), |
320 self.__addSourceDirectory) |
338 self.__addSourceDirectory) |
321 self.menu.addSeparator() |
339 self.menu.addSeparator() |
322 self.menu.addAction(self.trUtf8('Expand all directories'), |
340 self.menu.addAction(self.trUtf8('Expand all directories'), |
323 self._expandAllDirs) |
341 self._expandAllDirs) |
344 self.attributeMenu.addAction(self.trUtf8('Expand all directories'), |
362 self.attributeMenu.addAction(self.trUtf8('Expand all directories'), |
345 self._expandAllDirs) |
363 self._expandAllDirs) |
346 self.attributeMenu.addAction(self.trUtf8('Collapse all directories'), |
364 self.attributeMenu.addAction(self.trUtf8('Collapse all directories'), |
347 self._collapseAllDirs) |
365 self._collapseAllDirs) |
348 self.attributeMenu.addSeparator() |
366 self.attributeMenu.addSeparator() |
349 self.attributeMenu.addAction(self.trUtf8('Configure...'), self._configure) |
367 self.attributeMenu.addAction( |
|
368 self.trUtf8('Configure...'), self._configure) |
350 |
369 |
351 self.backMenu = QMenu(self) |
370 self.backMenu = QMenu(self) |
352 self.backMenu.addAction(self.trUtf8('Add source files...'), |
371 self.backMenu.addAction(self.trUtf8('Add source files...'), |
353 self.project.addSourceFiles) |
372 self.project.addSourceFiles) |
354 self.backMenu.addAction(self.trUtf8('Add source directory...'), |
373 self.backMenu.addAction(self.trUtf8('Add source directory...'), |
364 |
383 |
365 self.multiMenu.addSeparator() |
384 self.multiMenu.addSeparator() |
366 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
385 act = self.multiMenu.addAction(self.trUtf8('Remove from project'), |
367 self._removeFile) |
386 self._removeFile) |
368 self.multiMenuActions.append(act) |
387 self.multiMenuActions.append(act) |
369 act = self.multiMenu.addAction(self.trUtf8('Delete'), self.__deleteFile) |
388 act = self.multiMenu.addAction( |
|
389 self.trUtf8('Delete'), self.__deleteFile) |
370 self.multiMenuActions.append(act) |
390 self.multiMenuActions.append(act) |
371 self.multiMenu.addSeparator() |
391 self.multiMenu.addSeparator() |
372 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
392 self.multiMenu.addAction(self.trUtf8('Expand all directories'), |
373 self._expandAllDirs) |
393 self._expandAllDirs) |
374 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
394 self.multiMenu.addAction(self.trUtf8('Collapse all directories'), |
375 self._collapseAllDirs) |
395 self._collapseAllDirs) |
376 self.multiMenu.addSeparator() |
396 self.multiMenu.addSeparator() |
377 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
397 self.multiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
378 |
398 |
379 self.dirMenu = QMenu(self) |
399 self.dirMenu = QMenu(self) |
380 act = self.dirMenu.addAction(self.trUtf8('Remove from project'), self._removeDir) |
400 act = self.dirMenu.addAction( |
|
401 self.trUtf8('Remove from project'), self._removeDir) |
381 self.dirMenuActions.append(act) |
402 self.dirMenuActions.append(act) |
382 self.dirMenu.addSeparator() |
403 self.dirMenu.addSeparator() |
383 self.dirMenu.addAction(self.trUtf8('Add source files...'), self.__addSourceFiles) |
404 self.dirMenu.addAction( |
|
405 self.trUtf8('Add source files...'), self.__addSourceFiles) |
384 self.dirMenu.addAction(self.trUtf8('Add source directory...'), |
406 self.dirMenu.addAction(self.trUtf8('Add source directory...'), |
385 self.__addSourceDirectory) |
407 self.__addSourceDirectory) |
386 self.dirMenu.addSeparator() |
408 self.dirMenu.addSeparator() |
387 act = self.dirMenu.addMenu(self.graphicsMenu) |
409 act = self.dirMenu.addMenu(self.graphicsMenu) |
388 self.dirMenu.addSeparator() |
410 self.dirMenu.addSeparator() |
397 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), |
419 self.dirMultiMenu.addAction(self.trUtf8('Expand all directories'), |
398 self._expandAllDirs) |
420 self._expandAllDirs) |
399 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), |
421 self.dirMultiMenu.addAction(self.trUtf8('Collapse all directories'), |
400 self._collapseAllDirs) |
422 self._collapseAllDirs) |
401 self.dirMultiMenu.addSeparator() |
423 self.dirMultiMenu.addSeparator() |
402 self.dirMultiMenu.addAction(self.trUtf8('Configure...'), self._configure) |
424 self.dirMultiMenu.addAction( |
|
425 self.trUtf8('Configure...'), self._configure) |
403 |
426 |
404 self.sourceMenu.aboutToShow.connect(self.__showContextMenu) |
427 self.sourceMenu.aboutToShow.connect(self.__showContextMenu) |
405 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) |
428 self.multiMenu.aboutToShow.connect(self.__showContextMenuMulti) |
406 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) |
429 self.dirMenu.aboutToShow.connect(self.__showContextMenuDir) |
407 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) |
430 self.dirMultiMenu.aboutToShow.connect(self.__showContextMenuDirMulti) |
450 if isinstance(itm, ProjectBrowserFileItem): |
473 if isinstance(itm, ProjectBrowserFileItem): |
451 fn = itm.fileName() |
474 fn = itm.fileName() |
452 if self.project.pdata["PROGLANGUAGE"][0] in \ |
475 if self.project.pdata["PROGLANGUAGE"][0] in \ |
453 ["Python", "Python2", "Python3"]: |
476 ["Python", "Python2", "Python3"]: |
454 if fn.endswith('.ptl'): |
477 if fn.endswith('.ptl'): |
455 for act in list(self.sourceMenuActions.values()): |
478 for act in self.sourceMenuActions.values(): |
456 act.setEnabled(False) |
479 act.setEnabled(False) |
457 self.classDiagramAction.setEnabled(True) |
480 self.classDiagramAction.setEnabled(True) |
458 self.importsDiagramAction.setEnabled(True) |
481 self.importsDiagramAction.setEnabled(True) |
459 self.unittestAction.setEnabled(False) |
482 self.unittestAction.setEnabled(False) |
460 self.checksMenu.menuAction().setEnabled(False) |
483 self.checksMenu.menuAction().setEnabled( |
461 elif fn.endswith('.rb'): # entry for mixed mode programs |
484 False) |
462 for act in list(self.sourceMenuActions.values()): |
485 elif fn.endswith('.rb'): # entry for mixed |
|
486 # mode programs |
|
487 for act in self.sourceMenuActions.values(): |
463 act.setEnabled(False) |
488 act.setEnabled(False) |
464 self.classDiagramAction.setEnabled(True) |
489 self.classDiagramAction.setEnabled(True) |
465 self.importsDiagramAction.setEnabled(False) |
490 self.importsDiagramAction.setEnabled(False) |
466 self.unittestAction.setEnabled(False) |
491 self.unittestAction.setEnabled(False) |
467 self.checksMenu.menuAction().setEnabled(False) |
492 self.checksMenu.menuAction().setEnabled( |
468 else: # assume the source file is a Python file |
493 False) |
469 for act in list(self.sourceMenuActions.values()): |
494 else: # assume the source file is a |
|
495 # Python file |
|
496 for act in self.sourceMenuActions.values(): |
470 act.setEnabled(True) |
497 act.setEnabled(True) |
471 self.classDiagramAction.setEnabled(True) |
498 self.classDiagramAction.setEnabled(True) |
472 self.importsDiagramAction.setEnabled(True) |
499 self.importsDiagramAction.setEnabled(True) |
473 self.unittestAction.setEnabled(True) |
500 self.unittestAction.setEnabled(True) |
474 self.checksMenu.menuAction().setEnabled(True) |
501 self.checksMenu.menuAction().setEnabled( |
|
502 True) |
475 self.sourceMenu.popup(self.mapToGlobal(coord)) |
503 self.sourceMenu.popup(self.mapToGlobal(coord)) |
476 elif isinstance(itm, BrowserClassItem) or \ |
504 elif isinstance(itm, BrowserClassItem) or \ |
477 isinstance(itm, BrowserMethodItem): |
505 isinstance(itm, BrowserMethodItem): |
478 self.menu.popup(self.mapToGlobal(coord)) |
506 self.menu.popup(self.mapToGlobal(coord)) |
479 elif isinstance(itm, BrowserClassAttributeItem): |
507 elif isinstance(itm, BrowserClassAttributeItem): |
581 if itm.isPython2File(): |
609 if itm.isPython2File(): |
582 self.sourceFile[str].emit(itm.fileName()) |
610 self.sourceFile[str].emit(itm.fileName()) |
583 elif itm.isPython3File(): |
611 elif itm.isPython3File(): |
584 self.sourceFile[str].emit(itm.fileName()) |
612 self.sourceFile[str].emit(itm.fileName()) |
585 elif itm.isRubyFile(): |
613 elif itm.isRubyFile(): |
586 self.sourceFile[str, int, str].emit(itm.fileName(), -1, "Ruby") |
614 self.sourceFile[str, int, str].emit( |
|
615 itm.fileName(), -1, "Ruby") |
587 elif itm.isDFile(): |
616 elif itm.isDFile(): |
588 self.sourceFile[str, int, str].emit(itm.fileName(), -1, "D") |
617 self.sourceFile[str, int, str].emit( |
|
618 itm.fileName(), -1, "D") |
589 else: |
619 else: |
590 self.sourceFile[str].emit(itm.fileName()) |
620 self.sourceFile[str].emit(itm.fileName()) |
591 elif isinstance(itm, BrowserClassItem): |
621 elif isinstance(itm, BrowserClassItem): |
592 self.sourceFile[str, int].emit(itm.fileName(), itm.classObject().lineno) |
622 self.sourceFile[str, int].emit( |
|
623 itm.fileName(), itm.classObject().lineno) |
593 elif isinstance(itm, BrowserMethodItem): |
624 elif isinstance(itm, BrowserMethodItem): |
594 self.sourceFile[str, int].emit( |
625 self.sourceFile[str, int].emit( |
595 itm.fileName(), itm.functionObject().lineno) |
626 itm.fileName(), itm.functionObject().lineno) |
596 elif isinstance(itm, BrowserClassAttributeItem): |
627 elif isinstance(itm, BrowserClassAttributeItem): |
597 self.sourceFile[str, int].emit( |
628 self.sourceFile[str, int].emit( |
628 try: |
659 try: |
629 os.mkdir(packagePath) |
660 os.mkdir(packagePath) |
630 except OSError as err: |
661 except OSError as err: |
631 E5MessageBox.critical(self, |
662 E5MessageBox.critical(self, |
632 self.trUtf8("Add new Python package"), |
663 self.trUtf8("Add new Python package"), |
633 self.trUtf8("""<p>The package directory <b>{0}</b> could""" |
664 self.trUtf8( |
634 """ not be created. Aborting...</p>""" |
665 """<p>The package directory <b>{0}</b> could""" |
635 """<p>Reason: {1}</p>""")\ |
666 """ not be created. Aborting...</p>""" |
|
667 """<p>Reason: {1}</p>""")\ |
636 .format(packagePath, str(err))) |
668 .format(packagePath, str(err))) |
637 return |
669 return |
638 packageFile = os.path.join(packagePath, "__init__.py") |
670 packageFile = os.path.join(packagePath, "__init__.py") |
639 if not os.path.exists(packageFile): |
671 if not os.path.exists(packageFile): |
640 try: |
672 try: |
641 f = open(packageFile, "w", encoding="utf-8") |
673 f = open(packageFile, "w", encoding="utf-8") |
642 f.close() |
674 f.close() |
643 except IOError as err: |
675 except IOError as err: |
644 E5MessageBox.critical(self, |
676 E5MessageBox.critical(self, |
645 self.trUtf8("Add new Python package"), |
677 self.trUtf8("Add new Python package"), |
646 self.trUtf8("""<p>The package file <b>{0}</b> could""" |
678 self.trUtf8( |
647 """ not be created. Aborting...</p>""" |
679 """<p>The package file <b>{0}</b> could""" |
648 """<p>Reason: {1}</p>""")\ |
680 """ not be created. Aborting...</p>""" |
|
681 """<p>Reason: {1}</p>""")\ |
649 .format(packageFile, str(err))) |
682 .format(packageFile, str(err))) |
650 return |
683 return |
651 self.project.appendFile(packageFile) |
684 self.project.appendFile(packageFile) |
652 if packageFile: |
685 if packageFile: |
653 self.sourceFile[str].emit(packageFile) |
686 self.sourceFile[str].emit(packageFile) |
696 fn2 = itm.fileName() |
729 fn2 = itm.fileName() |
697 fullNames.append(fn2) |
730 fullNames.append(fn2) |
698 fn = self.project.getRelativePath(fn2) |
731 fn = self.project.getRelativePath(fn2) |
699 files.append(fn) |
732 files.append(fn) |
700 |
733 |
701 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
734 from UI.DeleteFilesConfirmationDialog import \ |
|
735 DeleteFilesConfirmationDialog |
702 dlg = DeleteFilesConfirmationDialog(self.parent(), |
736 dlg = DeleteFilesConfirmationDialog(self.parent(), |
703 self.trUtf8("Delete files"), |
737 self.trUtf8("Delete files"), |
704 self.trUtf8("Do you really want to delete these files from the project?"), |
738 self.trUtf8( |
|
739 "Do you really want to delete these files from the project?"), |
705 files) |
740 files) |
706 |
741 |
707 if dlg.exec_() == QDialog.Accepted: |
742 if dlg.exec_() == QDialog.Accepted: |
708 for fn2, fn in zip(fullNames, files): |
743 for fn2, fn in zip(fullNames, files): |
709 self.closeSourceWindow.emit(fn2) |
744 self.closeSourceWindow.emit(fn2) |
710 self.project.deleteFile(fn) |
745 self.project.deleteFile(fn) |
711 |
746 |
712 ############################################################################ |
747 ########################################################################### |
713 ## Methods for the Checks submenu |
748 ## Methods for the Checks submenu |
714 ############################################################################ |
749 ########################################################################### |
715 |
750 |
716 def __showContextMenuCheck(self): |
751 def __showContextMenuCheck(self): |
717 """ |
752 """ |
718 Private slot called before the checks menu is shown. |
753 Private slot called before the checks menu is shown. |
719 """ |
754 """ |
720 self.showMenu.emit("Checks", self.checksMenu) |
755 self.showMenu.emit("Checks", self.checksMenu) |
721 |
756 |
722 ############################################################################ |
757 ########################################################################### |
723 ## Methods for the Show submenu |
758 ## Methods for the Show submenu |
724 ############################################################################ |
759 ########################################################################### |
725 |
760 |
726 def __showCodeMetrics(self): |
761 def __showCodeMetrics(self): |
727 """ |
762 """ |
728 Private method to handle the code metrics context menu action. |
763 Private method to handle the code metrics context menu action. |
729 """ |
764 """ |
841 from DataViews.PyProfileDialog import PyProfileDialog |
876 from DataViews.PyProfileDialog import PyProfileDialog |
842 self.profiledata = PyProfileDialog() |
877 self.profiledata = PyProfileDialog() |
843 self.profiledata.show() |
878 self.profiledata.show() |
844 self.profiledata.start(pfn, fn) |
879 self.profiledata.start(pfn, fn) |
845 |
880 |
846 ############################################################################ |
881 ########################################################################### |
847 ## Methods for the Graphics submenu |
882 ## Methods for the Graphics submenu |
848 ############################################################################ |
883 ########################################################################### |
849 |
884 |
850 def __showContextMenuGraphics(self): |
885 def __showContextMenuGraphics(self): |
851 """ |
886 """ |
852 Private slot called before the checks menu is shown. |
887 Private slot called before the checks menu is shown. |
853 """ |
888 """ |
883 package = os.path.isdir(fn) and fn or os.path.dirname(fn) |
918 package = os.path.isdir(fn) and fn or os.path.dirname(fn) |
884 res = E5MessageBox.yesNo(self, |
919 res = E5MessageBox.yesNo(self, |
885 self.trUtf8("Imports Diagram"), |
920 self.trUtf8("Imports Diagram"), |
886 self.trUtf8("""Include imports from external modules?""")) |
921 self.trUtf8("""Include imports from external modules?""")) |
887 from Graphics.UMLDialog import UMLDialog |
922 from Graphics.UMLDialog import UMLDialog |
888 self.importsDiagram = UMLDialog(UMLDialog.ImportsDiagram, self.project, package, |
923 self.importsDiagram = UMLDialog( |
889 self, showExternalImports=res) |
924 UMLDialog.ImportsDiagram, self.project, package, |
|
925 self, showExternalImports=res) |
890 self.importsDiagram.show() |
926 self.importsDiagram.show() |
891 |
927 |
892 def __showPackageDiagram(self): |
928 def __showPackageDiagram(self): |
893 """ |
929 """ |
894 Private method to handle the package diagram context menu action. |
930 Private method to handle the package diagram context menu action. |
902 res = E5MessageBox.yesNo(self, |
938 res = E5MessageBox.yesNo(self, |
903 self.trUtf8("Package Diagram"), |
939 self.trUtf8("Package Diagram"), |
904 self.trUtf8("""Include class attributes?"""), |
940 self.trUtf8("""Include class attributes?"""), |
905 yesDefault=True) |
941 yesDefault=True) |
906 from Graphics.UMLDialog import UMLDialog |
942 from Graphics.UMLDialog import UMLDialog |
907 self.packageDiagram = UMLDialog(UMLDialog.PackageDiagram, self.project, package, |
943 self.packageDiagram = UMLDialog( |
908 self, noAttrs=not res) |
944 UMLDialog.PackageDiagram, self.project, package, |
|
945 self, noAttrs=not res) |
909 self.packageDiagram.show() |
946 self.packageDiagram.show() |
910 |
947 |
911 def __showApplicationDiagram(self): |
948 def __showApplicationDiagram(self): |
912 """ |
949 """ |
913 Private method to handle the application diagram context menu action. |
950 Private method to handle the application diagram context menu action. |
915 res = E5MessageBox.yesNo(self, |
952 res = E5MessageBox.yesNo(self, |
916 self.trUtf8("Application Diagram"), |
953 self.trUtf8("Application Diagram"), |
917 self.trUtf8("""Include module names?"""), |
954 self.trUtf8("""Include module names?"""), |
918 yesDefault=True) |
955 yesDefault=True) |
919 from Graphics.UMLDialog import UMLDialog |
956 from Graphics.UMLDialog import UMLDialog |
920 self.applicationDiagram = UMLDialog(UMLDialog.ApplicationDiagram, self.project, |
957 self.applicationDiagram = UMLDialog( |
921 self, noModules=not res) |
958 UMLDialog.ApplicationDiagram, self.project, |
|
959 self, noModules=not res) |
922 self.applicationDiagram.show() |
960 self.applicationDiagram.show() |
923 |
961 |
924 def __loadDiagram(self): |
962 def __loadDiagram(self): |
925 """ |
963 """ |
926 Private slot to load a diagram from file. |
964 Private slot to load a diagram from file. |
927 """ |
965 """ |
928 from Graphics.UMLDialog import UMLDialog |
966 from Graphics.UMLDialog import UMLDialog |
929 self.loadedDiagram = None |
967 self.loadedDiagram = None |
930 loadedDiagram = UMLDialog(UMLDialog.NoDiagram, self.project, parent=self) |
968 loadedDiagram = UMLDialog( |
|
969 UMLDialog.NoDiagram, self.project, parent=self) |
931 if loadedDiagram.load(): |
970 if loadedDiagram.load(): |
932 self.loadedDiagram = loadedDiagram |
971 self.loadedDiagram = loadedDiagram |
933 self.loadedDiagram.show(fromFile=True) |
972 self.loadedDiagram.show(fromFile=True) |