eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py

branch
eric7
changeset 9202
81388c6065e8
parent 9201
2f1ccadee231
child 9205
b75da2ba2a1a
diff -r 2f1ccadee231 -r 81388c6065e8 eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py
--- a/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py	Sat Jul 02 18:53:56 2022 +0200
+++ b/eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py	Sun Jul 03 13:52:59 2022 +0200
@@ -41,12 +41,14 @@
     It displays a dialog for entering the parameters for the setup.py code
     generator.
     """
-    def __init__(self, category, parent=None):
+    def __init__(self, category, editor, parent=None):
         """
         Constructor
         
         @param category category of setup file to create
         @type str
+        @param editor reference to the editor object to receive the code
+        @type Editor
         @param parent reference to the parent widget (defaults to None)
         @type QWidget (optional)
         @exception ValueError raised for an illegal setup file category
@@ -57,8 +59,11 @@
         super().__init__(parent)
         self.setupUi(self)
         
+        self.setWindowTitle(self.tr("{0} Wizard").format(category))
+        
         self.__replies = []
         self.__category = category
+        self.__editor = editor
         
         if category != "setup.py":
             self.introCheckBox.setVisible(False)
@@ -260,7 +265,7 @@
         if self.descriptionFromFilesCheckBox.isChecked():
             sourceCode += 'def get_long_description():{0}'.format(os.linesep)
             sourceCode += '{0}descr = []{1}'.format(istring, os.linesep)
-            sourceCode += '{0}for fname in ("{1})":{2}'.format(
+            sourceCode += '{0}for fname in ("{1}"):{2}'.format(
                 istring,
                 '", "'.join(self.descriptionEdit.toPlainText().splitlines()),
                 os.linesep)
@@ -755,26 +760,36 @@
         sourceCode = tomlkit.dumps(doc)
         return sourceCode
     
-    def getCode(self, indLevel, indString):
+    @pyqtSlot()
+    def accept(self):
+        """
+        Public slot to handle pressing the OK button.
         """
-        Public method to get the source code.
+        line, index = self.__editor.getCursorPosition()
+        indLevel = self.__editor.indentation(line) // self.__editor.indentationWidth()
+        if self.__editor.indentationsUseTabs():
+            indString = '\t'
+        else:
+            indString = self.__editor.indentationWidth() * ' '
         
-        @param indLevel indentation level
-        @type int
-        @param indString string used for indentation (space or tab)
-        @type str
-        @return generated code
-        @rtype str
-        """
         if self.__category == "setup.py":
-            return self.__getSetupPyCode(indLevel, indString)
+            sourceCode = self.__getSetupPyCode(indLevel, indString)
         elif self.__category == "setup.cfg":
-            return self.__getSetupCfgCode()
+            sourceCode = self.__getSetupCfgCode()
         elif self.__category == "pyproject.toml":
-            return self.__getPyprojectCode()
+            sourceCode = self.__getPyprojectCode()
         else:
             # should not happen, but play it safe
-            return ""
+            sourceCode = ""
+        
+        if sourceCode:
+            line, index = self.__editor.getCursorPosition()
+            # It should be done this way to allow undo
+            self.__editor.beginUndoAction()
+            self.__editor.insertAt(sourceCode, line, index)
+            self.__editor.endUndoAction()
+        
+        super().accept()
     
     @pyqtSlot()
     def on_projectButton_clicked(self):

eric ide

mercurial