eric7/Plugins/WizardPlugins/SetupWizard/SetupWizardDialog.py

branch
eric7
changeset 9202
81388c6065e8
parent 9201
2f1ccadee231
child 9205
b75da2ba2a1a
equal deleted inserted replaced
9201:2f1ccadee231 9202:81388c6065e8
39 Class implementing the setup.py wizard dialog. 39 Class implementing the setup.py wizard dialog.
40 40
41 It displays a dialog for entering the parameters for the setup.py code 41 It displays a dialog for entering the parameters for the setup.py code
42 generator. 42 generator.
43 """ 43 """
44 def __init__(self, category, parent=None): 44 def __init__(self, category, editor, parent=None):
45 """ 45 """
46 Constructor 46 Constructor
47 47
48 @param category category of setup file to create 48 @param category category of setup file to create
49 @type str 49 @type str
50 @param editor reference to the editor object to receive the code
51 @type Editor
50 @param parent reference to the parent widget (defaults to None) 52 @param parent reference to the parent widget (defaults to None)
51 @type QWidget (optional) 53 @type QWidget (optional)
52 @exception ValueError raised for an illegal setup file category 54 @exception ValueError raised for an illegal setup file category
53 """ 55 """
54 if category not in ("setup.py", "setup.cfg", "pyproject.toml"): 56 if category not in ("setup.py", "setup.cfg", "pyproject.toml"):
55 raise ValueError("illegal setup file category given") 57 raise ValueError("illegal setup file category given")
56 58
57 super().__init__(parent) 59 super().__init__(parent)
58 self.setupUi(self) 60 self.setupUi(self)
59 61
62 self.setWindowTitle(self.tr("{0} Wizard").format(category))
63
60 self.__replies = [] 64 self.__replies = []
61 self.__category = category 65 self.__category = category
66 self.__editor = editor
62 67
63 if category != "setup.py": 68 if category != "setup.py":
64 self.introCheckBox.setVisible(False) 69 self.introCheckBox.setVisible(False)
65 self.importCheckBox.setVisible(False) 70 self.importCheckBox.setVisible(False)
66 self.metaDataCheckBox.setVisible(False) 71 self.metaDataCheckBox.setVisible(False)
258 sourceCode += "{0}{0}".format(os.linesep) 263 sourceCode += "{0}{0}".format(os.linesep)
259 264
260 if self.descriptionFromFilesCheckBox.isChecked(): 265 if self.descriptionFromFilesCheckBox.isChecked():
261 sourceCode += 'def get_long_description():{0}'.format(os.linesep) 266 sourceCode += 'def get_long_description():{0}'.format(os.linesep)
262 sourceCode += '{0}descr = []{1}'.format(istring, os.linesep) 267 sourceCode += '{0}descr = []{1}'.format(istring, os.linesep)
263 sourceCode += '{0}for fname in ("{1})":{2}'.format( 268 sourceCode += '{0}for fname in ("{1}"):{2}'.format(
264 istring, 269 istring,
265 '", "'.join(self.descriptionEdit.toPlainText().splitlines()), 270 '", "'.join(self.descriptionEdit.toPlainText().splitlines()),
266 os.linesep) 271 os.linesep)
267 sourceCode += ( 272 sourceCode += (
268 '{0}with open(fname, "r", encoding="utf-8") as f:{1}' 273 '{0}with open(fname, "r", encoding="utf-8") as f:{1}'
753 doc["tool"]["setuptools"] = setuptools 758 doc["tool"]["setuptools"] = setuptools
754 759
755 sourceCode = tomlkit.dumps(doc) 760 sourceCode = tomlkit.dumps(doc)
756 return sourceCode 761 return sourceCode
757 762
758 def getCode(self, indLevel, indString): 763 @pyqtSlot()
759 """ 764 def accept(self):
760 Public method to get the source code. 765 """
761 766 Public slot to handle pressing the OK button.
762 @param indLevel indentation level 767 """
763 @type int 768 line, index = self.__editor.getCursorPosition()
764 @param indString string used for indentation (space or tab) 769 indLevel = self.__editor.indentation(line) // self.__editor.indentationWidth()
765 @type str 770 if self.__editor.indentationsUseTabs():
766 @return generated code 771 indString = '\t'
767 @rtype str 772 else:
768 """ 773 indString = self.__editor.indentationWidth() * ' '
774
769 if self.__category == "setup.py": 775 if self.__category == "setup.py":
770 return self.__getSetupPyCode(indLevel, indString) 776 sourceCode = self.__getSetupPyCode(indLevel, indString)
771 elif self.__category == "setup.cfg": 777 elif self.__category == "setup.cfg":
772 return self.__getSetupCfgCode() 778 sourceCode = self.__getSetupCfgCode()
773 elif self.__category == "pyproject.toml": 779 elif self.__category == "pyproject.toml":
774 return self.__getPyprojectCode() 780 sourceCode = self.__getPyprojectCode()
775 else: 781 else:
776 # should not happen, but play it safe 782 # should not happen, but play it safe
777 return "" 783 sourceCode = ""
784
785 if sourceCode:
786 line, index = self.__editor.getCursorPosition()
787 # It should be done this way to allow undo
788 self.__editor.beginUndoAction()
789 self.__editor.insertAt(sourceCode, line, index)
790 self.__editor.endUndoAction()
791
792 super().accept()
778 793
779 @pyqtSlot() 794 @pyqtSlot()
780 def on_projectButton_clicked(self): 795 def on_projectButton_clicked(self):
781 """ 796 """
782 Private slot to populate some fields with data retrieved from the 797 Private slot to populate some fields with data retrieved from the

eric ide

mercurial