src/eric7/Project/Project.py

branch
eric7
changeset 9453
e5065dde905d
parent 9436
731d146193e2
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9452:325c6de4b1f5 9453:e5065dde905d
56 56
57 from eric7.Tasks.TasksFile import TasksFile 57 from eric7.Tasks.TasksFile import TasksFile
58 58
59 from eric7.CodeFormatting.BlackFormattingAction import BlackFormattingAction 59 from eric7.CodeFormatting.BlackFormattingAction import BlackFormattingAction
60 from eric7.CodeFormatting.BlackUtilities import aboutBlack 60 from eric7.CodeFormatting.BlackUtilities import aboutBlack
61
62 from eric7.CodeFormatting.IsortFormattingAction import IsortFormattingAction
63 from eric7.CodeFormatting.IsortUtilities import aboutIsort
61 64
62 65
63 class Project(QObject): 66 class Project(QObject):
64 """ 67 """
65 Class implementing the project management functionality. 68 Class implementing the project management functionality.
4865 ) 4868 )
4866 self.createSBOMAct.triggered.connect(self.__createSBOMFile) 4869 self.createSBOMAct.triggered.connect(self.__createSBOMFile)
4867 self.actions.append(self.createSBOMAct) 4870 self.actions.append(self.createSBOMAct)
4868 4871
4869 ################################################################### 4872 ###################################################################
4870 ## Project Tools - code formatting actions 4873 ## Project Tools - code formatting actions - Black
4871 ################################################################### 4874 ###################################################################
4872 4875
4873 self.blackFormattingGrp = createActionGroup(self) 4876 self.blackFormattingGrp = createActionGroup(self)
4874 4877
4875 self.blackAboutAct = EricAction( 4878 self.blackAboutAct = EricAction(
4989 " project sources with 'Black'.</p>" 4992 " project sources with 'Black'.</p>"
4990 ) 4993 )
4991 ) 4994 )
4992 self.blackConfigureAct.triggered.connect(self.__configureBlack) 4995 self.blackConfigureAct.triggered.connect(self.__configureBlack)
4993 self.actions.append(self.blackConfigureAct) 4996 self.actions.append(self.blackConfigureAct)
4997
4998 ###################################################################
4999 ## Project Tools - code formatting actions - isort
5000 ###################################################################
5001
5002 self.isortFormattingGrp = createActionGroup(self)
5003
5004 self.isortAboutAct = EricAction(
5005 self.tr("About isort"),
5006 self.tr("&isort"),
5007 0,
5008 0,
5009 self.isortFormattingGrp,
5010 "project_isort_about",
5011 )
5012 self.isortAboutAct.setStatusTip(self.tr("Show some information about 'isort'."))
5013 self.isortAboutAct.setWhatsThis(
5014 self.tr(
5015 "<b>isort</b>"
5016 "<p>This shows some information about the installed 'isort' tool.</p>"
5017 )
5018 )
5019 self.isortAboutAct.triggered.connect(aboutIsort)
5020 self.actions.append(self.isortAboutAct)
5021 font = self.isortAboutAct.font()
5022 font.setBold(True)
5023 self.isortAboutAct.setFont(font)
5024
5025 self.isortSortImportsAct = EricAction(
5026 self.tr("Sort Imports"),
5027 self.tr("Sort Imports"),
5028 0,
5029 0,
5030 self.isortFormattingGrp,
5031 "project_isort_sort_imports",
5032 )
5033 self.isortSortImportsAct.setStatusTip(
5034 self.tr("Sort the import statements of the project sources with 'isort'.")
5035 )
5036 self.isortSortImportsAct.setWhatsThis(
5037 self.tr(
5038 "<b>Sort Imports</b>"
5039 "<p>This shows a dialog to enter parameters for the imports sorting"
5040 " run and sorts the import statements of the project sources using"
5041 " 'isort'.</p>"
5042 )
5043 )
5044 self.isortSortImportsAct.triggered.connect(
5045 lambda: self.__performImportSortingWithIsort(IsortFormattingAction.Sort)
5046 )
5047 self.actions.append(self.isortSortImportsAct)
5048
5049 self.isortDiffSortingAct = EricAction(
5050 self.tr("Imports Sorting Diff"),
5051 self.tr("Imports Sorting Diff"),
5052 0,
5053 0,
5054 self.isortFormattingGrp,
5055 "project_isort_diff_code",
5056 )
5057 self.isortDiffSortingAct.setStatusTip(
5058 self.tr(
5059 "Generate a unified diff of potential project source imports"
5060 " resorting with 'isort'."
5061 )
5062 )
5063 self.isortDiffSortingAct.setWhatsThis(
5064 self.tr(
5065 "<b>Imports Sorting Diff</b>"
5066 "<p>This shows a dialog to enter parameters for the imports sorting"
5067 " diff run and generates a unified diff of potential project source"
5068 " changes using 'isort'.</p>"
5069 )
5070 )
5071 self.isortDiffSortingAct.triggered.connect(
5072 lambda: self.__performImportSortingWithIsort(IsortFormattingAction.Diff)
5073 )
5074 self.actions.append(self.isortDiffSortingAct)
5075
5076 self.isortConfigureAct = EricAction(
5077 self.tr("Configure"),
5078 self.tr("Configure"),
5079 0,
5080 0,
5081 self.isortFormattingGrp,
5082 "project_isort_configure",
5083 )
5084 self.isortConfigureAct.setStatusTip(
5085 self.tr(
5086 "Enter the parameters for resorting the project sources import"
5087 " statements with 'isort'."
5088 )
5089 )
5090 self.isortConfigureAct.setWhatsThis(
5091 self.tr(
5092 "<b>Configure</b>"
5093 "<p>This shows a dialog to enter the parameters for resorting the"
5094 " import statements of the project sources with 'isort'.</p>"
5095 )
5096 )
5097 self.isortConfigureAct.triggered.connect(self.__configureIsort)
5098 self.actions.append(self.isortConfigureAct)
4994 5099
4995 ################################################################### 5100 ###################################################################
4996 ## Project - embedded environment actions 5101 ## Project - embedded environment actions
4997 ################################################################### 5102 ###################################################################
4998 5103
5202 self.othersMenu.addSeparator() 5307 self.othersMenu.addSeparator()
5203 5308
5204 # build the 'Code Formatting' menu 5309 # build the 'Code Formatting' menu
5205 self.formattingMenu.setTearOffEnabled(True) 5310 self.formattingMenu.setTearOffEnabled(True)
5206 self.formattingMenu.addActions(self.blackFormattingGrp.actions()) 5311 self.formattingMenu.addActions(self.blackFormattingGrp.actions())
5312 self.formattingMenu.addSeparator()
5313 self.formattingMenu.addActions(self.isortFormattingGrp.actions())
5207 self.formattingMenu.addSeparator() 5314 self.formattingMenu.addSeparator()
5208 5315
5209 # build the project main menu 5316 # build the project main menu
5210 menu.setTearOffEnabled(True) 5317 menu.setTearOffEnabled(True)
5211 menu.addActions(self.actGrp1.actions()) 5318 menu.addActions(self.actGrp1.actions())
6785 dlg = BlackConfigurationDialog(withProject=True, onlyProject=True) 6892 dlg = BlackConfigurationDialog(withProject=True, onlyProject=True)
6786 if dlg.exec() == QDialog.DialogCode.Accepted: 6893 if dlg.exec() == QDialog.DialogCode.Accepted:
6787 dlg.getConfiguration(saveToProject=True) 6894 dlg.getConfiguration(saveToProject=True)
6788 # The data is saved to the project as a side effect. 6895 # The data is saved to the project as a side effect.
6789 6896
6897 def __performImportSortingWithIsort(self, action):
6898 """
6899 Private method to format the project sources import statements using the
6900 'isort' tool.
6901
6902 Following actions are supported.
6903 <ul>
6904 <li>IsortFormattingAction.Format - the imports reformatting is performed</li>
6905 <li>IsortFormattingAction.Check - a check is performed, if imports formatting
6906 is necessary</li>
6907 <li>IsortFormattingAction.Diff - a unified diff of potential imports formatting
6908 changes is generated</li>
6909 </ul>
6910
6911 @param action formatting operation to be performed
6912 @type IsortFormattingAction
6913 """
6914 from eric7.CodeFormatting.IsortConfigurationDialog import (
6915 IsortConfigurationDialog,
6916 )
6917 from eric7.CodeFormatting.IsortFormattingDialog import IsortFormattingDialog
6918
6919 if ericApp().getObject("ViewManager").checkAllDirty():
6920 dlg = IsortConfigurationDialog(withProject=True)
6921 if dlg.exec() == QDialog.DialogCode.Accepted:
6922 config = dlg.getConfiguration(saveToProject=True)
6923
6924 isortDialog = IsortFormattingDialog(
6925 config,
6926 self.getProjectFiles("SOURCES", normalized=True),
6927 project=self,
6928 action=action,
6929 )
6930 isortDialog.exec()
6931
6932 @pyqtSlot()
6933 def __configureIsort(self):
6934 """
6935 Private slot to enter the parameters for formatting the import statements of the
6936 project sources with 'isort'.
6937 """
6938 from eric7.CodeFormatting.IsortConfigurationDialog import (
6939 IsortConfigurationDialog,
6940 )
6941
6942 dlg = IsortConfigurationDialog(withProject=True, onlyProject=True)
6943 if dlg.exec() == QDialog.DialogCode.Accepted:
6944 dlg.getConfiguration(saveToProject=True)
6945 # The data is saved to the project as a side effect.
6946
6790 ######################################################################### 6947 #########################################################################
6791 ## Below are methods implementing the 'Embedded Environment' support 6948 ## Below are methods implementing the 'Embedded Environment' support
6792 ######################################################################### 6949 #########################################################################
6793 6950
6794 def __showContextMenuEnvironment(self): 6951 def __showContextMenuEnvironment(self):

eric ide

mercurial