src/eric7/Plugins/WizardPlugins/SetupWizard/AddEntryPointDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
21 21
22 class AddEntryPointDialog(QDialog, Ui_AddEntryPointDialog): 22 class AddEntryPointDialog(QDialog, Ui_AddEntryPointDialog):
23 """ 23 """
24 Class implementing a dialog to enter the data for an entry point. 24 Class implementing a dialog to enter the data for an entry point.
25 """ 25 """
26
26 def __init__(self, rootDirectory, epType="", name="", script="", parent=None): 27 def __init__(self, rootDirectory, epType="", name="", script="", parent=None):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param rootDirectory root directory for selecting script modules via 31 @param rootDirectory root directory for selecting script modules via
31 a file selection dialog 32 a file selection dialog
32 @type str 33 @type str
33 @param epType type of the entry point (defaults to "") 34 @param epType type of the entry point (defaults to "")
34 @type str (optional) 35 @type str (optional)
39 @param parent reference to the parent widget (defaults to None) 40 @param parent reference to the parent widget (defaults to None)
40 @type QWidget (optional) 41 @type QWidget (optional)
41 """ 42 """
42 super().__init__(parent) 43 super().__init__(parent)
43 self.setupUi(self) 44 self.setupUi(self)
44 45
45 for typeStr, category in ( 46 for typeStr, category in (
46 ("", ""), 47 ("", ""),
47 (self.tr("Console"), "console_scripts"), 48 (self.tr("Console"), "console_scripts"),
48 (self.tr("GUI"), "gui_scripts"), 49 (self.tr("GUI"), "gui_scripts"),
49 ): 50 ):
50 self.typeComboBox.addItem(typeStr, category) 51 self.typeComboBox.addItem(typeStr, category)
51 52
52 self.scriptButton.setIcon(UI.PixmapCache.getIcon("open")) 53 self.scriptButton.setIcon(UI.PixmapCache.getIcon("open"))
53 54
54 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) 55 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
55 56
56 self.__rootDirectory = rootDirectory 57 self.__rootDirectory = rootDirectory
57 58
58 self.typeComboBox.currentTextChanged.connect(self.__updateOK) 59 self.typeComboBox.currentTextChanged.connect(self.__updateOK)
59 self.nameEdit.textChanged.connect(self.__updateOK) 60 self.nameEdit.textChanged.connect(self.__updateOK)
60 self.scriptEdit.textChanged.connect(self.__updateOK) 61 self.scriptEdit.textChanged.connect(self.__updateOK)
61 62
62 self.typeComboBox.setCurrentText(epType) 63 self.typeComboBox.setCurrentText(epType)
63 self.nameEdit.setText(name) 64 self.nameEdit.setText(name)
64 self.scriptEdit.setText(script) 65 self.scriptEdit.setText(script)
65 66
66 msh = self.minimumSizeHint() 67 msh = self.minimumSizeHint()
67 self.resize(max(self.width(), msh.width()), msh.height()) 68 self.resize(max(self.width(), msh.width()), msh.height())
68 69
69 @pyqtSlot() 70 @pyqtSlot()
70 def __updateOK(self): 71 def __updateOK(self):
71 """ 72 """
72 Private slot to update the enabled state of the OK button. 73 Private slot to update the enabled state of the OK button.
73 """ 74 """
74 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( 75 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
75 bool(self.typeComboBox.currentText()) and 76 bool(self.typeComboBox.currentText())
76 bool(self.nameEdit.text()) and 77 and bool(self.nameEdit.text())
77 bool(self.scriptEdit.text()) 78 and bool(self.scriptEdit.text())
78 ) 79 )
79 80
80 @pyqtSlot() 81 @pyqtSlot()
81 def on_scriptButton_clicked(self): 82 def on_scriptButton_clicked(self):
82 """ 83 """
83 Private slot to select a script via a file selection dialog. 84 Private slot to select a script via a file selection dialog.
84 """ 85 """
91 scriptFile = scriptFile.replace(".", "/") + ".py" 92 scriptFile = scriptFile.replace(".", "/") + ".py"
92 root = str(pathlib.Path(self.__rootDirectory) / scriptFile) 93 root = str(pathlib.Path(self.__rootDirectory) / scriptFile)
93 else: 94 else:
94 root = self.__rootDirectory 95 root = self.__rootDirectory
95 scriptFunction = "main" 96 scriptFunction = "main"
96 97
97 script = EricFileDialog.getOpenFileName( 98 script = EricFileDialog.getOpenFileName(
98 self, 99 self,
99 self.tr("Select Script File"), 100 self.tr("Select Script File"),
100 root, 101 root,
101 self.tr("Python Files (*.py);;All Files (*)") 102 self.tr("Python Files (*.py);;All Files (*)"),
102 ) 103 )
103 104
104 if script: 105 if script:
105 scriptPath = pathlib.Path(script) 106 scriptPath = pathlib.Path(script)
106 try: 107 try:
107 relativeScriptPath = scriptPath.relative_to(self.__rootDirectory) 108 relativeScriptPath = scriptPath.relative_to(self.__rootDirectory)
108 except ValueError: 109 except ValueError:
109 relativeScriptPath = scriptPath 110 relativeScriptPath = scriptPath
110 self.scriptEdit.setText("{0}:{1}".format( 111 self.scriptEdit.setText(
111 str(relativeScriptPath.with_suffix("")) 112 "{0}:{1}".format(
112 .replace("/", ".") 113 str(relativeScriptPath.with_suffix(""))
113 .replace("\\", "."), 114 .replace("/", ".")
114 scriptFunction 115 .replace("\\", "."),
115 )) 116 scriptFunction,
116 117 )
118 )
119
117 def getEntryPoint(self): 120 def getEntryPoint(self):
118 """ 121 """
119 Public method to get the data for the entry point. 122 Public method to get the data for the entry point.
120 123
121 @return tuple containing the entry point type, category, name and 124 @return tuple containing the entry point type, category, name and
122 script function 125 script function
123 @rtype tuple of (str, str, str) 126 @rtype tuple of (str, str, str)
124 """ 127 """
125 return ( 128 return (

eric ide

mercurial