src/eric7/Project/ProjectSourcesBrowser.py

branch
eric7-maintenance
changeset 9549
67295777d9fe
parent 9442
906485dcd210
parent 9535
8b5402794fb6
child 9654
7328efba128b
equal deleted inserted replaced
9451:24c847222774 9549:67295777d9fe
5 5
6 """ 6 """
7 Module implementing a class used to display the Sources part of the project. 7 Module implementing a class used to display the Sources part of the project.
8 """ 8 """
9 9
10 import contextlib
10 import os 11 import os
11 import contextlib
12 12
13 from PyQt6.QtCore import pyqtSignal 13 from PyQt6.QtCore import pyqtSignal
14 from PyQt6.QtWidgets import QDialog, QInputDialog, QMenu 14 from PyQt6.QtWidgets import QDialog, QInputDialog, QMenu
15 15
16 from eric7 import Utilities
17 from eric7.CodeFormatting.BlackFormattingAction import BlackFormattingAction
18 from eric7.CodeFormatting.BlackUtilities import aboutBlack
19 from eric7.CodeFormatting.IsortFormattingAction import IsortFormattingAction
20 from eric7.CodeFormatting.IsortUtilities import aboutIsort
21 from eric7.EricGui import EricPixmapCache
16 from eric7.EricWidgets import EricMessageBox 22 from eric7.EricWidgets import EricMessageBox
17 from eric7.EricWidgets.EricApplication import ericApp 23 from eric7.EricWidgets.EricApplication import ericApp
18 24 from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType
19 from eric7.UI.BrowserModel import ( 25 from eric7.UI.BrowserModel import (
26 BrowserClassAttributeItem,
27 BrowserClassItem,
20 BrowserFileItem, 28 BrowserFileItem,
21 BrowserClassItem, 29 BrowserImportItem,
22 BrowserMethodItem, 30 BrowserMethodItem,
23 BrowserClassAttributeItem,
24 BrowserImportItem,
25 ) 31 )
26 32 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
33
34 from .FileCategoryRepositoryItem import FileCategoryRepositoryItem
35 from .ProjectBaseBrowser import ProjectBaseBrowser
27 from .ProjectBrowserModel import ( 36 from .ProjectBrowserModel import (
37 ProjectBrowserDirectoryItem,
28 ProjectBrowserFileItem, 38 ProjectBrowserFileItem,
29 ProjectBrowserSimpleDirectoryItem, 39 ProjectBrowserSimpleDirectoryItem,
30 ProjectBrowserDirectoryItem,
31 ProjectBrowserSourceType,
32 ) 40 )
33 from .ProjectBaseBrowser import ProjectBaseBrowser 41 from .ProjectBrowserRepositoryItem import ProjectBrowserRepositoryItem
34
35 from eric7 import Utilities
36 from eric7.EricGui import EricPixmapCache
37
38 from eric7.CodeFormatting.BlackFormattingAction import BlackFormattingAction
39 from eric7.CodeFormatting.BlackUtilities import aboutBlack
40 42
41 43
42 class ProjectSourcesBrowser(ProjectBaseBrowser): 44 class ProjectSourcesBrowser(ProjectBaseBrowser):
43 """ 45 """
44 A class used to display the Sources part of the project. 46 A class used to display the Sources part of the project.
47 The name of the menu and a reference to the menu are given. 49 The name of the menu and a reference to the menu are given.
48 """ 50 """
49 51
50 showMenu = pyqtSignal(str, QMenu) 52 showMenu = pyqtSignal(str, QMenu)
51 53
52 def __init__(self, project, parent=None): 54 def __init__(self, project, projectBrowser, parent=None):
53 """ 55 """
54 Constructor 56 Constructor
55 57
56 @param project reference to the project object 58 @param project reference to the project object
57 @param parent parent widget of this browser (QWidget) 59 @type Project
58 """ 60 @param projectBrowser reference to the project browser object
59 ProjectBaseBrowser.__init__(self, project, ProjectBrowserSourceType, parent) 61 @type ProjectBrowser
62 @param parent parent widget of this browser
63 @type QWidget
64 """
65 ProjectBaseBrowser.__init__(self, project, "source", parent)
60 66
61 self.selectedItemsFilter = [ 67 self.selectedItemsFilter = [
62 ProjectBrowserFileItem, 68 ProjectBrowserFileItem,
63 ProjectBrowserSimpleDirectoryItem, 69 ProjectBrowserSimpleDirectoryItem,
64 ] 70 ]
72 """ current project. Several actions can be executed via the""" 78 """ current project. Several actions can be executed via the"""
73 """ context menu.</p>""" 79 """ context menu.</p>"""
74 ) 80 )
75 ) 81 )
76 82
83 # Add the file category handled by the browser.
84 project.addFileCategory(
85 "SOURCES",
86 FileCategoryRepositoryItem(
87 fileCategoryFilterTemplate=self.tr("Source Files ({0})"),
88 fileCategoryUserString=self.tr("Source Files"),
89 fileCategoryTyeString=self.tr("Sources"),
90 fileCategoryExtensions=["*.py", "*.pyw"], # Python files as default
91 ),
92 )
93
94 # Add the project browser type to the browser type repository.
95 projectBrowser.addTypedProjectBrowser(
96 "sources",
97 ProjectBrowserRepositoryItem(
98 projectBrowser=self,
99 projectBrowserUserString=self.tr("Sources Browser"),
100 priority=100,
101 fileCategory="SOURCES",
102 fileFilter="source",
103 getIcon=self.getIcon,
104 ),
105 )
106
107 # Connect signals of Project.
77 project.prepareRepopulateItem.connect(self._prepareRepopulateItem) 108 project.prepareRepopulateItem.connect(self._prepareRepopulateItem)
78 project.completeRepopulateItem.connect(self._completeRepopulateItem) 109 project.completeRepopulateItem.connect(self._completeRepopulateItem)
110 project.projectClosed.connect(self._projectClosed)
111 project.projectOpened.connect(self._projectOpened)
112 project.newProject.connect(self._newProject)
113 project.reinitVCS.connect(self._initMenusAndVcs)
114 project.projectPropertiesChanged.connect(self._initMenusAndVcs)
115
116 # Connect signals of ProjectBrowser.
117 projectBrowser.preferencesChanged.connect(self.handlePreferencesChanged)
118
119 # Connect some of our own signals.
120 self.sourceFile[str].connect(projectBrowser.sourceFile[str])
121 self.sourceFile[str, int].connect(projectBrowser.sourceFile[str, int])
122 self.sourceFile[str, list].connect(projectBrowser.sourceFile[str, list])
123 self.sourceFile[str, int, str].connect(projectBrowser.sourceFile[str, int, str])
124 self.closeSourceWindow.connect(projectBrowser.closeSourceWindow)
125 self.testFile.connect(projectBrowser.testFile)
79 126
80 self.codemetrics = None 127 self.codemetrics = None
81 self.codecoverage = None 128 self.codecoverage = None
82 self.profiledata = None 129 self.profiledata = None
83 self.classDiagram = None 130 self.classDiagram = None
84 self.importsDiagram = None 131 self.importsDiagram = None
85 self.packageDiagram = None 132 self.packageDiagram = None
86 self.applicationDiagram = None 133 self.applicationDiagram = None
87 self.loadedDiagram = None 134 self.loadedDiagram = None
135
136 def getIcon(self):
137 """
138 Public method to get an icon for the project browser.
139
140 @return icon for the browser
141 @rtype QIcon
142 """
143 if not self.project.isOpen():
144 icon = EricPixmapCache.getIcon("projectSources")
145 else:
146 if self.project.getProjectLanguage() == "Python3":
147 if self.project.isMixedLanguageProject():
148 icon = EricPixmapCache.getIcon("projectSourcesPyMixed")
149 else:
150 icon = EricPixmapCache.getIcon("projectSourcesPy")
151 elif self.project.getProjectLanguage() == "MicroPython":
152 icon = EricPixmapCache.getIcon("micropython")
153 elif self.project.getProjectLanguage() == "Ruby":
154 if self.project.isMixedLanguageProject():
155 icon = EricPixmapCache.getIcon("projectSourcesRbMixed")
156 else:
157 icon = EricPixmapCache.getIcon("projectSourcesRb")
158 elif self.project.getProjectLanguage() == "JavaScript":
159 icon = EricPixmapCache.getIcon("projectSourcesJavaScript")
160 else:
161 icon = EricPixmapCache.getIcon("projectSources")
162
163 return icon
88 164
89 def __closeAllWindows(self): 165 def __closeAllWindows(self):
90 """ 166 """
91 Private method to close all project related windows. 167 Private method to close all project related windows.
92 """ 168 """
145 ) 221 )
146 self.formattingMenu.addAction( 222 self.formattingMenu.addAction(
147 self.tr("Formatting Diff"), 223 self.tr("Formatting Diff"),
148 lambda: self.__performFormatWithBlack(BlackFormattingAction.Diff), 224 lambda: self.__performFormatWithBlack(BlackFormattingAction.Diff),
149 ) 225 )
226 self.formattingMenu.addSeparator()
227 act = self.formattingMenu.addAction(self.tr("isort"), aboutIsort)
228 font = act.font()
229 font.setBold(True)
230 act.setFont(font)
231 self.formattingMenu.addAction(
232 self.tr("Sort Imports"),
233 lambda: self.__performImportSortingWithIsort(IsortFormattingAction.Sort),
234 )
235 self.formattingMenu.addAction(
236 self.tr("Imports Sorting Diff"),
237 lambda: self.__performImportSortingWithIsort(IsortFormattingAction.Diff),
238 )
239 self.formattingMenu.addSeparator()
150 self.formattingMenu.aboutToShow.connect(self.__showContextMenuFormatting) 240 self.formattingMenu.aboutToShow.connect(self.__showContextMenuFormatting)
151 241
152 self.menuShow = QMenu(self.tr("Show")) 242 self.menuShow = QMenu(self.tr("Show"))
153 self.menuShow.addAction(self.tr("Code metrics..."), self.__showCodeMetrics) 243 self.menuShow.addAction(self.tr("Code metrics..."), self.__showCodeMetrics)
154 self.coverageMenuAction = self.menuShow.addAction( 244 self.coverageMenuAction = self.menuShow.addAction(
261 self.attributeMenu = QMenu(self) 351 self.attributeMenu = QMenu(self)
262 self.attributeMenu.addMenu(self.gotoMenu) 352 self.attributeMenu.addMenu(self.gotoMenu)
263 self.attributeMenu.addSeparator() 353 self.attributeMenu.addSeparator()
264 self.attributeMenu.addAction(self.tr("New package..."), self.__addNewPackage) 354 self.attributeMenu.addAction(self.tr("New package..."), self.__addNewPackage)
265 self.attributeMenu.addAction( 355 self.attributeMenu.addAction(
266 self.tr("Add source files..."), self.project.addSourceFiles 356 self.tr("Add source files..."),
357 lambda: self.project.addFiles("SOURCES"),
267 ) 358 )
268 self.attributeMenu.addAction( 359 self.attributeMenu.addAction(
269 self.tr("Add source directory..."), self.project.addSourceDir 360 self.tr("Add source directory..."),
361 lambda: self.project.addDirectory("SOURCES"),
270 ) 362 )
271 self.attributeMenu.addSeparator() 363 self.attributeMenu.addSeparator()
272 self.attributeMenu.addAction( 364 self.attributeMenu.addAction(
273 self.tr("Expand all directories"), self._expandAllDirs 365 self.tr("Expand all directories"), self._expandAllDirs
274 ) 366 )
279 self.attributeMenu.addAction(self.tr("Configure..."), self._configure) 371 self.attributeMenu.addAction(self.tr("Configure..."), self._configure)
280 372
281 self.backMenu = QMenu(self) 373 self.backMenu = QMenu(self)
282 self.backMenu.addAction(self.tr("New package..."), self.__addNewPackage) 374 self.backMenu.addAction(self.tr("New package..."), self.__addNewPackage)
283 self.backMenu.addAction( 375 self.backMenu.addAction(
284 self.tr("Add source files..."), self.project.addSourceFiles 376 self.tr("Add source files..."),
377 lambda: self.project.addFiles("SOURCES"),
285 ) 378 )
286 self.backMenu.addAction( 379 self.backMenu.addAction(
287 self.tr("Add source directory..."), self.project.addSourceDir 380 self.tr("Add source directory..."),
381 lambda: self.project.addDirectory("SOURCES"),
288 ) 382 )
289 self.backMenu.addSeparator() 383 self.backMenu.addSeparator()
290 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs) 384 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
291 self.backMenu.addAction( 385 self.backMenu.addAction(
292 self.tr("Collapse all directories"), self._collapseAllDirs 386 self.tr("Collapse all directories"), self._collapseAllDirs
418 512
419 self.attributeMenu = QMenu(self) 513 self.attributeMenu = QMenu(self)
420 self.attributeMenu.addMenu(self.gotoMenu) 514 self.attributeMenu.addMenu(self.gotoMenu)
421 self.attributeMenu.addSeparator() 515 self.attributeMenu.addSeparator()
422 self.attributeMenu.addAction( 516 self.attributeMenu.addAction(
423 self.tr("Add source files..."), self.project.addSourceFiles 517 self.tr("Add source files..."),
518 lambda: self.project.addFiles("SOURCES"),
424 ) 519 )
425 self.attributeMenu.addAction( 520 self.attributeMenu.addAction(
426 self.tr("Add source directory..."), self.project.addSourceDir 521 self.tr("Add source directory..."),
522 lambda: self.project.addDirectory("SOURCES"),
427 ) 523 )
428 self.attributeMenu.addSeparator() 524 self.attributeMenu.addSeparator()
429 self.attributeMenu.addAction( 525 self.attributeMenu.addAction(
430 self.tr("Expand all directories"), self._expandAllDirs 526 self.tr("Expand all directories"), self._expandAllDirs
431 ) 527 )
435 self.attributeMenu.addSeparator() 531 self.attributeMenu.addSeparator()
436 self.attributeMenu.addAction(self.tr("Configure..."), self._configure) 532 self.attributeMenu.addAction(self.tr("Configure..."), self._configure)
437 533
438 self.backMenu = QMenu(self) 534 self.backMenu = QMenu(self)
439 self.backMenu.addAction( 535 self.backMenu.addAction(
440 self.tr("Add source files..."), self.project.addSourceFiles 536 self.tr("Add source files..."),
537 lambda: self.project.addFiles("SOURCES"),
441 ) 538 )
442 self.backMenu.addAction( 539 self.backMenu.addAction(
443 self.tr("Add source directory..."), self.project.addSourceDir 540 self.tr("Add source directory..."),
541 lambda: self.project.addDirectory("SOURCES"),
444 ) 542 )
445 self.backMenu.addSeparator() 543 self.backMenu.addSeparator()
446 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs) 544 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
447 self.backMenu.addAction( 545 self.backMenu.addAction(
448 self.tr("Collapse all directories"), self._collapseAllDirs 546 self.tr("Collapse all directories"), self._collapseAllDirs
554 652
555 self.attributeMenu = QMenu(self) 653 self.attributeMenu = QMenu(self)
556 self.attributeMenu.addMenu(self.gotoMenu) 654 self.attributeMenu.addMenu(self.gotoMenu)
557 self.attributeMenu.addSeparator() 655 self.attributeMenu.addSeparator()
558 self.attributeMenu.addAction( 656 self.attributeMenu.addAction(
559 self.tr("Add source files..."), self.project.addSourceFiles 657 self.tr("Add source files..."),
658 lambda: self.project.addFiles("SOURCES"),
560 ) 659 )
561 self.attributeMenu.addAction( 660 self.attributeMenu.addAction(
562 self.tr("Add source directory..."), self.project.addSourceDir 661 self.tr("Add source directory..."),
662 lambda: self.project.addDirectory("SOURCES"),
563 ) 663 )
564 self.attributeMenu.addSeparator() 664 self.attributeMenu.addSeparator()
565 self.attributeMenu.addAction( 665 self.attributeMenu.addAction(
566 self.tr("Expand all directories"), self._expandAllDirs 666 self.tr("Expand all directories"), self._expandAllDirs
567 ) 667 )
571 self.attributeMenu.addSeparator() 671 self.attributeMenu.addSeparator()
572 self.attributeMenu.addAction(self.tr("Configure..."), self._configure) 672 self.attributeMenu.addAction(self.tr("Configure..."), self._configure)
573 673
574 self.backMenu = QMenu(self) 674 self.backMenu = QMenu(self)
575 self.backMenu.addAction( 675 self.backMenu.addAction(
576 self.tr("Add source files..."), self.project.addSourceFiles 676 self.tr("Add source files..."),
677 lambda: self.project.addFiles("SOURCES"),
577 ) 678 )
578 self.backMenu.addAction( 679 self.backMenu.addAction(
579 self.tr("Add source directory..."), self.project.addSourceDir 680 self.tr("Add source directory..."),
681 lambda: self.project.addDirectory("SOURCES"),
580 ) 682 )
581 self.backMenu.addSeparator() 683 self.backMenu.addSeparator()
582 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs) 684 self.backMenu.addAction(self.tr("Expand all directories"), self._expandAllDirs)
583 self.backMenu.addAction( 685 self.backMenu.addAction(
584 self.tr("Collapse all directories"), self._collapseAllDirs 686 self.tr("Collapse all directories"), self._collapseAllDirs
648 @param coord the position of the mouse pointer (QPoint) 750 @param coord the position of the mouse pointer (QPoint)
649 """ 751 """
650 if not self.project.isOpen(): 752 if not self.project.isOpen():
651 return 753 return
652 754
653 with contextlib.suppress(Exception): 755 with contextlib.suppress(Exception): # secok
654 categories = self.getSelectedItemsCountCategorized( 756 categories = self.getSelectedItemsCountCategorized(
655 [ 757 [
656 ProjectBrowserFileItem, 758 ProjectBrowserFileItem,
657 BrowserClassItem, 759 BrowserClassItem,
658 BrowserMethodItem, 760 BrowserMethodItem,
864 966
865 def __addNewPackage(self): 967 def __addNewPackage(self):
866 """ 968 """
867 Private method to add a new package to the project. 969 Private method to add a new package to the project.
868 """ 970 """
971 from .NewPythonPackageDialog import NewPythonPackageDialog
972
869 itm = self.model().item(self.currentIndex()) 973 itm = self.model().item(self.currentIndex())
870 if isinstance( 974 if isinstance(
871 itm, (ProjectBrowserFileItem, BrowserClassItem, BrowserMethodItem) 975 itm, (ProjectBrowserFileItem, BrowserClassItem, BrowserMethodItem)
872 ): 976 ):
873 dn = os.path.dirname(itm.fileName()) 977 dn = os.path.dirname(itm.fileName())
879 dn = "" 983 dn = ""
880 984
881 dn = self.project.getRelativePath(dn) 985 dn = self.project.getRelativePath(dn)
882 if dn.startswith(os.sep): 986 if dn.startswith(os.sep):
883 dn = dn[1:] 987 dn = dn[1:]
884 from .NewPythonPackageDialog import NewPythonPackageDialog
885
886 dlg = NewPythonPackageDialog(dn, self) 988 dlg = NewPythonPackageDialog(dn, self)
887 if dlg.exec() == QDialog.DialogCode.Accepted: 989 if dlg.exec() == QDialog.DialogCode.Accepted:
888 packageName = dlg.getData() 990 packageName = dlg.getData()
889 nameParts = packageName.split(".") 991 nameParts = packageName.split(".")
890 packagePath = self.project.ppath 992 packagePath = self.project.ppath
971 fn2 = itm.fileName() 1073 fn2 = itm.fileName()
972 fullNames.append(fn2) 1074 fullNames.append(fn2)
973 fn = self.project.getRelativePath(fn2) 1075 fn = self.project.getRelativePath(fn2)
974 files.append(fn) 1076 files.append(fn)
975 1077
976 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog
977
978 dlg = DeleteFilesConfirmationDialog( 1078 dlg = DeleteFilesConfirmationDialog(
979 self.parent(), 1079 self.parent(),
980 self.tr("Delete files"), 1080 self.tr("Delete files"),
981 self.tr("Do you really want to delete these files from the project?"), 1081 self.tr("Do you really want to delete these files from the project?"),
982 files, 1082 files,
1003 1103
1004 def __showCodeMetrics(self): 1104 def __showCodeMetrics(self):
1005 """ 1105 """
1006 Private method to handle the code metrics context menu action. 1106 Private method to handle the code metrics context menu action.
1007 """ 1107 """
1108 from eric7.DataViews.CodeMetricsDialog import CodeMetricsDialog
1109
1008 itm = self.model().item(self.currentIndex()) 1110 itm = self.model().item(self.currentIndex())
1009 fn = itm.fileName() 1111 fn = itm.fileName()
1010
1011 from eric7.DataViews.CodeMetricsDialog import CodeMetricsDialog
1012 1112
1013 self.codemetrics = CodeMetricsDialog() 1113 self.codemetrics = CodeMetricsDialog()
1014 self.codemetrics.show() 1114 self.codemetrics.show()
1015 self.codemetrics.start(fn) 1115 self.codemetrics.start(fn)
1016 1116
1017 def __showCodeCoverage(self): 1117 def __showCodeCoverage(self):
1018 """ 1118 """
1019 Private method to handle the code coverage context menu action. 1119 Private method to handle the code coverage context menu action.
1020 """ 1120 """
1121 from eric7.DataViews.PyCoverageDialog import PyCoverageDialog
1122
1021 itm = self.model().item(self.currentIndex()) 1123 itm = self.model().item(self.currentIndex())
1022 fn = itm.fileName() 1124 fn = itm.fileName()
1023 pfn = self.project.getMainScript(True) 1125 pfn = self.project.getMainScript(True)
1024 1126
1025 files = set() 1127 files = []
1026 1128
1027 if pfn is not None: 1129 if pfn is not None:
1028 files |= set(Utilities.getCoverageFileNames(pfn)) 1130 files.extend(
1131 [f for f in Utilities.getCoverageFileNames(pfn) if f not in files]
1132 )
1029 1133
1030 if fn is not None: 1134 if fn is not None:
1031 files |= set(Utilities.getCoverageFileNames(fn)) 1135 files.extend(
1032 1136 [f for f in Utilities.getCoverageFileNames(fn) if f not in files]
1033 if list(files): 1137 )
1138
1139 if files:
1034 if len(files) > 1: 1140 if len(files) > 1:
1035 cfn, ok = QInputDialog.getItem( 1141 cfn, ok = QInputDialog.getItem(
1036 None, 1142 None,
1037 self.tr("Code Coverage"), 1143 self.tr("Code Coverage"),
1038 self.tr("Please select a coverage file"), 1144 self.tr("Please select a coverage file"),
1045 else: 1151 else:
1046 cfn = files[0] 1152 cfn = files[0]
1047 else: 1153 else:
1048 return 1154 return
1049 1155
1050 from eric7.DataViews.PyCoverageDialog import PyCoverageDialog
1051
1052 self.codecoverage = PyCoverageDialog() 1156 self.codecoverage = PyCoverageDialog()
1053 self.codecoverage.show() 1157 self.codecoverage.show()
1054 self.codecoverage.start(cfn, fn) 1158 self.codecoverage.start(cfn, fn)
1055 1159
1056 def __showProfileData(self): 1160 def __showProfileData(self):
1057 """ 1161 """
1058 Private method to handle the show profile data context menu action. 1162 Private method to handle the show profile data context menu action.
1059 """ 1163 """
1164 from eric7.DataViews.PyProfileDialog import PyProfileDialog
1165
1060 itm = self.model().item(self.currentIndex()) 1166 itm = self.model().item(self.currentIndex())
1061 fn = itm.fileName() 1167 fn = itm.fileName()
1062 pfn = self.project.getMainScript(True) 1168 pfn = self.project.getMainScript(True)
1063 1169
1064 files = set() 1170 files = []
1065 1171
1066 if pfn is not None: 1172 if pfn is not None:
1067 files |= set(Utilities.getProfileFileNames(pfn)) 1173 files.extend(
1174 [f for f in Utilities.getProfileFileNames(pfn) if f not in files]
1175 )
1068 1176
1069 if fn is not None: 1177 if fn is not None:
1070 files |= set(Utilities.getProfileFileNames(fn)) 1178 files.extend(
1071 1179 [f for f in Utilities.getProfileFileNames(fn) if f not in files]
1072 if list(files): 1180 )
1181
1182 if files:
1073 if len(files) > 1: 1183 if len(files) > 1:
1074 pfn, ok = QInputDialog.getItem( 1184 pfn, ok = QInputDialog.getItem(
1075 None, 1185 None,
1076 self.tr("Profile Data"), 1186 self.tr("Profile Data"),
1077 self.tr("Please select a profile file"), 1187 self.tr("Please select a profile file"),
1084 else: 1194 else:
1085 pfn = files[0] 1195 pfn = files[0]
1086 else: 1196 else:
1087 return 1197 return
1088 1198
1089 from eric7.DataViews.PyProfileDialog import PyProfileDialog
1090
1091 self.profiledata = PyProfileDialog() 1199 self.profiledata = PyProfileDialog()
1092 self.profiledata.show() 1200 self.profiledata.show()
1093 self.profiledata.start(pfn, fn) 1201 self.profiledata.start(pfn, fn)
1094 1202
1095 ########################################################################### 1203 ###########################################################################
1116 self.tr("Class Diagram"), 1224 self.tr("Class Diagram"),
1117 self.tr("""Include class attributes?"""), 1225 self.tr("""Include class attributes?"""),
1118 yesDefault=True, 1226 yesDefault=True,
1119 ) 1227 )
1120 1228
1121 from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType
1122
1123 self.classDiagram = UMLDialog( 1229 self.classDiagram = UMLDialog(
1124 UMLDialogType.CLASS_DIAGRAM, self.project, fn, self, noAttrs=not res 1230 UMLDialogType.CLASS_DIAGRAM, self.project, fn, self, noAttrs=not res
1125 ) 1231 )
1126 self.classDiagram.show() 1232 self.classDiagram.show()
1127 1233
1138 res = EricMessageBox.yesNo( 1244 res = EricMessageBox.yesNo(
1139 self, 1245 self,
1140 self.tr("Imports Diagram"), 1246 self.tr("Imports Diagram"),
1141 self.tr("""Include imports from external modules?"""), 1247 self.tr("""Include imports from external modules?"""),
1142 ) 1248 )
1143
1144 from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType
1145 1249
1146 self.importsDiagram = UMLDialog( 1250 self.importsDiagram = UMLDialog(
1147 UMLDialogType.IMPORTS_DIAGRAM, 1251 UMLDialogType.IMPORTS_DIAGRAM,
1148 self.project, 1252 self.project,
1149 package, 1253 package,
1167 self.tr("Package Diagram"), 1271 self.tr("Package Diagram"),
1168 self.tr("""Include class attributes?"""), 1272 self.tr("""Include class attributes?"""),
1169 yesDefault=True, 1273 yesDefault=True,
1170 ) 1274 )
1171 1275
1172 from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType
1173
1174 self.packageDiagram = UMLDialog( 1276 self.packageDiagram = UMLDialog(
1175 UMLDialogType.PACKAGE_DIAGRAM, self.project, package, self, noAttrs=not res 1277 UMLDialogType.PACKAGE_DIAGRAM, self.project, package, self, noAttrs=not res
1176 ) 1278 )
1177 self.packageDiagram.show() 1279 self.packageDiagram.show()
1178 1280
1184 self, 1286 self,
1185 self.tr("Application Diagram"), 1287 self.tr("Application Diagram"),
1186 self.tr("""Include module names?"""), 1288 self.tr("""Include module names?"""),
1187 yesDefault=True, 1289 yesDefault=True,
1188 ) 1290 )
1189
1190 from eric7.Graphics.UMLDialog import UMLDialog, UMLDialogType
1191 1291
1192 self.applicationDiagram = UMLDialog( 1292 self.applicationDiagram = UMLDialog(
1193 UMLDialogType.APPLICATION_DIAGRAM, self.project, self, noModules=not res 1293 UMLDialogType.APPLICATION_DIAGRAM, self.project, self, noModules=not res
1194 ) 1294 )
1195 self.applicationDiagram.show() 1295 self.applicationDiagram.show()
1269 ) 1369 )
1270 from eric7.CodeFormatting.BlackFormattingDialog import BlackFormattingDialog 1370 from eric7.CodeFormatting.BlackFormattingDialog import BlackFormattingDialog
1271 1371
1272 files = [ 1372 files = [
1273 itm.fileName() 1373 itm.fileName()
1274 for itm in self.getSelectedItems( 1374 for itm in self.getSelectedItems([BrowserFileItem])
1275 [
1276 BrowserFileItem,
1277 BrowserClassItem,
1278 BrowserMethodItem,
1279 BrowserClassAttributeItem,
1280 BrowserImportItem,
1281 ]
1282 )
1283 if itm.isPython3File() 1375 if itm.isPython3File()
1284 ] 1376 ]
1285 if not files: 1377 if not files:
1286 # called for a directory 1378 # called for a directory
1287 itm = self.model().item(self.currentIndex()) 1379 itm = self.model().item(self.currentIndex())
1308 EricMessageBox.information( 1400 EricMessageBox.information(
1309 self, 1401 self,
1310 self.tr("Code Formatting"), 1402 self.tr("Code Formatting"),
1311 self.tr("""There are no files left for reformatting."""), 1403 self.tr("""There are no files left for reformatting."""),
1312 ) 1404 )
1405
1406 def __performImportSortingWithIsort(self, action):
1407 """
1408 Private method to sort the import statements of the selected project sources
1409 using the 'isort' tool.
1410
1411 Following actions are supported.
1412 <ul>
1413 <li>IsortFormattingAction.Sort - the import statement sorting is performed</li>
1414 <li>IsortFormattingAction.Check - a check is performed, if import statement
1415 resorting is necessary</li>
1416 <li>IsortFormattingAction.Diff - a unified diff of potential import statement
1417 changes is generated</li>
1418 </ul>
1419
1420 @param action sorting operation to be performed
1421 @type IsortFormattingAction
1422 """
1423 from eric7.CodeFormatting.IsortConfigurationDialog import (
1424 IsortConfigurationDialog,
1425 )
1426 from eric7.CodeFormatting.IsortFormattingDialog import IsortFormattingDialog
1427
1428 files = [
1429 itm.fileName()
1430 for itm in self.getSelectedItems([BrowserFileItem])
1431 if itm.isPython3File()
1432 ]
1433 if not files:
1434 # called for a directory
1435 itm = self.model().item(self.currentIndex())
1436 dirName = itm.dirName()
1437 files = [
1438 f
1439 for f in self.project.getProjectFiles("SOURCES", normalized=True)
1440 if f.startswith(dirName)
1441 ]
1442
1443 vm = ericApp().getObject("ViewManager")
1444 files = [fn for fn in files if vm.checkFileDirty(fn)]
1445
1446 if files:
1447 dlg = IsortConfigurationDialog(withProject=True)
1448 if dlg.exec() == QDialog.DialogCode.Accepted:
1449 config = dlg.getConfiguration()
1450
1451 formattingDialog = IsortFormattingDialog(
1452 config, files, project=self.project, action=action
1453 )
1454 formattingDialog.exec()
1455 else:
1456 EricMessageBox.information(
1457 self,
1458 self.tr("Import Sorting"),
1459 self.tr("""There are no files left for import statement sorting."""),
1460 )

eric ide

mercurial