--- a/eric7/Plugins/PluginWizardSetup.py Sat Jul 02 17:22:06 2022 +0200 +++ b/eric7/Plugins/PluginWizardSetup.py Sat Jul 02 18:53:56 2022 +0200 @@ -7,6 +7,8 @@ Module implementing the setup.py wizard plug-in. """ +import functools + from PyQt6.QtCore import QObject from PyQt6.QtWidgets import QDialog @@ -44,25 +46,21 @@ """ Constructor - @param ui reference to the user interface object (UI.UserInterface) + @param ui reference to the user interface object + @type UI.UserInterface """ super().__init__(ui) self.__ui = ui - self.__action = None - - def __initialize(self): - """ - Private slot to (re)initialize the plug-in. - """ - self.__act = None + self.__actions = [] def activate(self): """ Public method to activate this plug-in. - @return tuple of None and activation status (boolean) + @return tuple of None and activation status + @rtype tuple of (None, boolean) """ - self.__initAction() + self.__initActions() self.__initMenu() return None, True @@ -73,29 +71,66 @@ """ menu = self.__ui.getMenu("wizards") if menu: - menu.removeAction(self.__action) - self.__ui.removeEricActions([self.__action], 'wizards') + for act in self.__actions: + menu.removeAction(act) + self.__ui.removeEricActions(self.__actions, 'wizards') - def __initAction(self): + def __initActions(self): """ - Private method to initialize the action. + Private method to initialize the actions. """ - self.__action = EricAction( + # 1. action for 'setup.py' creation + act = EricAction( self.tr('setup.py Wizard'), self.tr('setup.py Wizard...'), 0, 0, self, 'wizards_setup_py') - self.__action.setStatusTip(self.tr('setup.py Wizard')) - self.__action.setWhatsThis(self.tr( + act.setStatusTip(self.tr('setup.py Wizard')) + act.setWhatsThis(self.tr( """<b>setup.py Wizard</b>""" """<p>This wizard opens a dialog for entering all the parameters""" """ needed to create the basic contents of a setup.py file. The""" """ generated code is inserted at the current cursor position.""" """</p>""" )) - self.__action.triggered.connect(self.__handle) + act.triggered.connect(functools.partial(self.__handle, "setup.py")) + self.__actions.append(act) - self.__ui.addEricActions([self.__action], 'wizards') + # 2. action for 'setup.cfg' creation + act = EricAction( + self.tr('setup.cfg Wizard'), + self.tr('setup.cfg Wizard...'), + 0, 0, self, + 'wizards_setup_cfg') + act.setStatusTip(self.tr('setup.cfg Wizard')) + act.setWhatsThis(self.tr( + """<b>setup.cfg Wizard</b>""" + """<p>This wizard opens a dialog for entering all the parameters""" + """ needed to create the basic contents of a setup.cfg file. The""" + """ generated code is inserted at the current cursor position.""" + """</p>""" + )) + act.triggered.connect(functools.partial(self.__handle, "setup.cfg")) + self.__actions.append(act) + + # 3. action for 'pyproject.toml' creation + act = EricAction( + self.tr('pyproject.toml Wizard'), + self.tr('pyproject.toml Wizard...'), + 0, 0, self, + 'wizards_pyproject_toml') + act.setStatusTip(self.tr('pyproject.toml Wizard')) + act.setWhatsThis(self.tr( + """<b>pyproject.toml Wizard</b>""" + """<p>This wizard opens a dialog for entering all the parameters""" + """ needed to create the basic contents of a pyproject.toml file. The""" + """ generated code is inserted at the current cursor position.""" + """</p>""" + )) + act.triggered.connect(functools.partial(self.__handle, "pyproject.toml")) + self.__actions.append(act) + + self.__ui.addEricActions(self.__actions, 'wizards') def __initMenu(self): """ @@ -103,19 +138,23 @@ """ menu = self.__ui.getMenu("wizards") if menu: - menu.addAction(self.__action) + menu.addActions(self.__actions) - def __callForm(self, editor): + def __callForm(self, editor, category): """ Private method to display a dialog and get the code. @param editor reference to the current editor - @return the generated code (string) + @type Editor + @param category category of setup file to create + @type str + @return tuple containing the generated code and a flag indicating an error + @rtype tuple of (str, bool) """ from WizardPlugins.SetupWizard.SetupWizardDialog import ( SetupWizardDialog ) - dlg = SetupWizardDialog(None) + dlg = SetupWizardDialog(category, self.__ui) if dlg.exec() == QDialog.DialogCode.Accepted: line, index = editor.getCursorPosition() indLevel = editor.indentation(line) // editor.indentationWidth() @@ -125,11 +164,14 @@ indString = editor.indentationWidth() * ' ' return (dlg.getCode(indLevel, indString), True) else: - return (None, False) + return ("", False) - def __handle(self): + def __handle(self, category): """ Private method to handle the wizards action. + + @param category category of setup file to create + @type str """ editor = ericApp().getObject("ViewManager").activeWindow() @@ -139,12 +181,12 @@ self.tr('No current editor'), self.tr('Please open or create a file first.')) else: - code, ok = self.__callForm(editor) + sourceCode, ok = self.__callForm(editor, category) if ok: line, index = editor.getCursorPosition() - # It should be done on this way to allow undo + # It should be done this way to allow undo editor.beginUndoAction() - editor.insertAt(code, line, index) + editor.insertAt(sourceCode, line, index) editor.endUndoAction() #