Project/PropertiesDialog.py

changeset 4582
3a1d1d4c6f4f
parent 4021
195a471c327b
child 4601
0017e7cb67ae
equal deleted inserted replaced
4581:76999ca7bbf1 4582:3a1d1d4c6f4f
13 13
14 from PyQt5.QtCore import QDir, pyqtSlot 14 from PyQt5.QtCore import QDir, pyqtSlot
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox 15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
16 16
17 from E5Gui.E5Application import e5App 17 from E5Gui.E5Application import e5App
18 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter 18 from E5Gui.E5PathPicker import E5PathPickerModes
19 from E5Gui import E5FileDialog
20 19
21 from .Ui_PropertiesDialog import Ui_PropertiesDialog 20 from .Ui_PropertiesDialog import Ui_PropertiesDialog
22 21
23 import Utilities 22 import Utilities
24 import Preferences 23 import Preferences
25 import UI.PixmapCache
26 24
27 25
28 class PropertiesDialog(QDialog, Ui_PropertiesDialog): 26 class PropertiesDialog(QDialog, Ui_PropertiesDialog):
29 """ 27 """
30 Class implementing the project properties dialog. 28 Class implementing the project properties dialog.
41 super(PropertiesDialog, self).__init__(parent) 39 super(PropertiesDialog, self).__init__(parent)
42 if name: 40 if name:
43 self.setObjectName(name) 41 self.setObjectName(name)
44 self.setupUi(self) 42 self.setupUi(self)
45 43
46 self.dirButton.setIcon(UI.PixmapCache.getIcon("open.png")) 44 self.dirPicker.setMode(E5PathPickerModes.DirectoryMode)
47 self.mainscriptButton.setIcon(UI.PixmapCache.getIcon("open.png")) 45 self.mainscriptPicker.setMode(E5PathPickerModes.OpenFileMode)
48 46
49 self.project = project 47 self.project = project
50 self.newProject = new 48 self.newProject = new
51 self.transPropertiesDlg = None 49 self.transPropertiesDlg = None
52 self.spellPropertiesDlg = None 50 self.spellPropertiesDlg = None
53 51
54 self.dirCompleter = E5DirCompleter(self.dirEdit) 52 patterns = []
55 self.mainscriptCompleter = E5FileCompleter(self.mainscriptEdit) 53 for pattern, filetype in self.project.pdata["FILETYPES"].items():
54 if filetype == "SOURCES":
55 patterns.append(pattern)
56 filters = self.tr("Source Files ({0});;All Files (*)")\
57 .format(" ".join(sorted(patterns)))
58 self.mainscriptPicker.setFilters(filters)
56 59
57 self.languageComboBox.addItems(project.getProgrammingLanguages()) 60 self.languageComboBox.addItems(project.getProgrammingLanguages())
58 61
59 projectTypes = project.getProjectTypes() 62 projectTypes = project.getProjectTypes()
60 self.projectTypeComboBox.clear() 63 self.projectTypeComboBox.clear()
80 curIndex = self.projectTypeComboBox.findData( 83 curIndex = self.projectTypeComboBox.findData(
81 self.project.pdata["PROJECTTYPE"][0]) 84 self.project.pdata["PROJECTTYPE"][0])
82 if curIndex == -1: 85 if curIndex == -1:
83 curIndex = self.projectTypeComboBox.findData("Qt4") 86 curIndex = self.projectTypeComboBox.findData("Qt4")
84 self.projectTypeComboBox.setCurrentIndex(curIndex) 87 self.projectTypeComboBox.setCurrentIndex(curIndex)
85 self.dirEdit.setText(self.project.ppath) 88 self.dirPicker.setText(self.project.ppath)
86 try: 89 try:
87 self.versionEdit.setText(self.project.pdata["VERSION"][0]) 90 self.versionEdit.setText(self.project.pdata["VERSION"][0])
88 except IndexError: 91 except IndexError:
89 pass 92 pass
90 try: 93 try:
91 self.mainscriptEdit.setText( 94 self.mainscriptPicker.setText(
92 self.project.pdata["MAINSCRIPT"][0]) 95 self.project.pdata["MAINSCRIPT"][0])
93 except IndexError: 96 except IndexError:
94 pass 97 pass
95 try: 98 try:
96 self.authorEdit.setText(self.project.pdata["AUTHOR"][0]) 99 self.authorEdit.setText(self.project.pdata["AUTHOR"][0])
131 else: 134 else:
132 self.languageComboBox.setCurrentIndex( 135 self.languageComboBox.setCurrentIndex(
133 self.languageComboBox.findText("Python3")) 136 self.languageComboBox.findText("Python3"))
134 self.projectTypeComboBox.setCurrentIndex( 137 self.projectTypeComboBox.setCurrentIndex(
135 self.projectTypeComboBox.findData("PyQt5")) 138 self.projectTypeComboBox.findData("PyQt5"))
136 self.dirEdit.setText(self.__initPaths[0]) 139 self.dirPicker.setText(self.__initPaths[0])
137 self.versionEdit.setText('0.1') 140 self.versionEdit.setText('0.1')
138 self.vcsLabel.hide() 141 self.vcsLabel.hide()
139 self.vcsInfoButton.hide() 142 self.vcsInfoButton.hide()
140 if not self.project.vcsSoftwareAvailable(): 143 if not self.project.vcsSoftwareAvailable():
141 self.vcsCheckBox.hide() 144 self.vcsCheckBox.hide()
142 145
143 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( 146 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
144 bool(self.dirEdit.text()) and 147 bool(self.dirPicker.text()) and
145 Utilities.fromNativeSeparators(self.dirEdit.text()) not in 148 self.dirPicker.text() not in
146 self.__initPaths) 149 self.__initPaths)
147 150
148 @pyqtSlot(str) 151 @pyqtSlot(str)
149 def on_languageComboBox_currentIndexChanged(self, language): 152 def on_languageComboBox_currentIndexChanged(self, language):
150 """ 153 """
164 if index == -1: 167 if index == -1:
165 index = 0 168 index = 0
166 self.projectTypeComboBox.setCurrentIndex(index) 169 self.projectTypeComboBox.setCurrentIndex(index)
167 170
168 @pyqtSlot(str) 171 @pyqtSlot(str)
169 def on_dirEdit_textChanged(self, txt): 172 def on_dirPicker_textChanged(self, txt):
170 """ 173 """
171 Private slot to handle a change of the project directory. 174 Private slot to handle a change of the project directory.
172 175
173 @param txt name of the project directory (string) 176 @param txt name of the project directory (string)
174 """ 177 """
175 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( 178 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
176 bool(txt) and 179 bool(txt) and
177 Utilities.fromNativeSeparators(txt) not in self.__initPaths) 180 Utilities.fromNativeSeparators(txt) not in self.__initPaths)
178
179 @pyqtSlot()
180 def on_dirButton_clicked(self):
181 """
182 Private slot to display a directory selection dialog.
183 """
184 directory = E5FileDialog.getExistingDirectory(
185 self,
186 self.tr("Select project directory"),
187 self.dirEdit.text(),
188 E5FileDialog.Options(E5FileDialog.ShowDirsOnly))
189
190 if directory:
191 self.dirEdit.setText(Utilities.toNativeSeparators(directory))
192 181
193 @pyqtSlot() 182 @pyqtSlot()
194 def on_spellPropertiesButton_clicked(self): 183 def on_spellPropertiesButton_clicked(self):
195 """ 184 """
196 Private slot to display the spelling properties dialog. 185 Private slot to display the spelling properties dialog.
218 self.transPropertiesDlg.initFilters() 207 self.transPropertiesDlg.initFilters()
219 res = self.transPropertiesDlg.exec_() 208 res = self.transPropertiesDlg.exec_()
220 if res == QDialog.Rejected: 209 if res == QDialog.Rejected:
221 self.transPropertiesDlg.initDialog() # reset the dialogs contents 210 self.transPropertiesDlg.initDialog() # reset the dialogs contents
222 211
223 @pyqtSlot() 212 @pyqtSlot(str)
224 def on_mainscriptButton_clicked(self): 213 def on_mainscriptPicker_pathSelected(self, script):
225 """ 214 """
226 Private slot to display a file selection dialog. 215 Private slot to check the selected main script name.
227 """ 216
228 dir = self.dirEdit.text() 217 @param script name of the main script
229 if not dir: 218 @type str
230 dir = QDir.currentPath() 219 """
231 patterns = [] 220 if script:
232 for pattern, filetype in list(self.project.pdata["FILETYPES"].items()): 221 ppath = self.dirPicker.text()
233 if filetype == "SOURCES":
234 patterns.append(pattern)
235 filters = self.tr("Source Files ({0});;All Files (*)")\
236 .format(" ".join(patterns))
237 fn = E5FileDialog.getOpenFileName(
238 self,
239 self.tr("Select main script file"),
240 dir,
241 filters)
242
243 if fn:
244 ppath = self.dirEdit.text()
245 if ppath: 222 if ppath:
246 ppath = QDir(ppath).absolutePath() + QDir.separator() 223 ppath = QDir(ppath).absolutePath() + QDir.separator()
247 fn = fn.replace(ppath, "") 224 script = script.replace(ppath, "")
248 self.mainscriptEdit.setText(Utilities.toNativeSeparators(fn)) 225 self.mainscriptPicker.setText(script)
226
227 @pyqtSlot()
228 def on_mainscriptPicker_aboutToShowPathPickerDialog(self):
229 """
230 Private slot to perform actions before the main script selection dialog
231 is shown.
232 """
233 path = self.dirPicker.text()
234 if not path:
235 path = QDir.currentPath()
236 self.mainscriptPicker.setDefaultDirectory(path)
249 237
250 @pyqtSlot() 238 @pyqtSlot()
251 def on_vcsInfoButton_clicked(self): 239 def on_vcsInfoButton_clicked(self):
252 """ 240 """
253 Private slot to display a vcs information dialog. 241 Private slot to display a vcs information dialog.
273 """ 261 """
274 Public method to get the project path. 262 Public method to get the project path.
275 263
276 @return data of the project directory edit (string) 264 @return data of the project directory edit (string)
277 """ 265 """
278 return os.path.abspath(self.dirEdit.text()) 266 return os.path.abspath(self.dirPicker.text())
279 267
280 def storeData(self): 268 def storeData(self):
281 """ 269 """
282 Public method to store the entered/modified data. 270 Public method to store the entered/modified data.
283 """ 271 """
284 self.project.ppath = os.path.abspath(self.dirEdit.text()) 272 self.project.ppath = os.path.abspath(self.dirPicker.text())
285 fn = self.nameEdit.text() 273 fn = self.nameEdit.text()
286 if fn: 274 if fn:
287 self.project.name = fn 275 self.project.name = fn
288 fn = "{0}.e4p".format(fn) 276 fn = "{0}.e4p".format(fn)
289 self.project.pfile = os.path.join(self.project.ppath, fn) 277 self.project.pfile = os.path.join(self.project.ppath, fn)
290 else: 278 else:
291 self.project.pfile = "" 279 self.project.pfile = ""
292 self.project.pdata["VERSION"] = [self.versionEdit.text()] 280 self.project.pdata["VERSION"] = [self.versionEdit.text()]
293 fn = self.mainscriptEdit.text() 281 fn = self.mainscriptPicker.text()
294 if fn: 282 if fn:
295 fn = self.project.getRelativePath(fn) 283 fn = self.project.getRelativePath(fn)
296 self.project.pdata["MAINSCRIPT"] = [fn] 284 self.project.pdata["MAINSCRIPT"] = [fn]
297 self.project.translationsRoot = os.path.splitext(fn)[0] 285 self.project.translationsRoot = os.path.splitext(fn)[0]
298 else: 286 else:

eric ide

mercurial