MultiProject/AddProjectDialog.py

changeset 4582
3a1d1d4c6f4f
parent 4021
195a471c327b
child 4631
5c1a96925da4
equal deleted inserted replaced
4581:76999ca7bbf1 4582:3a1d1d4c6f4f
12 import os 12 import os
13 13
14 from PyQt5.QtCore import pyqtSlot 14 from PyQt5.QtCore import pyqtSlot
15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox 15 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
16 16
17 from E5Gui.E5Completers import E5FileCompleter 17 from E5Gui.E5PathPicker import E5PathPickerModes
18 from E5Gui import E5FileDialog
19 18
20 from .Ui_AddProjectDialog import Ui_AddProjectDialog 19 from .Ui_AddProjectDialog import Ui_AddProjectDialog
21 20
22 import Utilities 21 import Utilities
23 import UI.PixmapCache
24 22
25 23
26 class AddProjectDialog(QDialog, Ui_AddProjectDialog): 24 class AddProjectDialog(QDialog, Ui_AddProjectDialog):
27 """ 25 """
28 Class implementing the add project dialog. 26 Class implementing the add project dialog.
38 @param categories list of already used categories (list of string) 36 @param categories list of already used categories (list of string)
39 """ 37 """
40 super(AddProjectDialog, self).__init__(parent) 38 super(AddProjectDialog, self).__init__(parent)
41 self.setupUi(self) 39 self.setupUi(self)
42 40
43 self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) 41 self.filenamePicker.setMode(E5PathPickerModes.OpenFileMode)
44 42 self.filenamePicker.setFilters(self.tr("Project Files (*.e4p)"))
45 self.fileCompleter = E5FileCompleter(self.filenameEdit)
46 43
47 if categories: 44 if categories:
48 self.categoryComboBox.addItem("") 45 self.categoryComboBox.addItem("")
49 self.categoryComboBox.addItems(sorted(categories)) 46 self.categoryComboBox.addItems(sorted(categories))
50 47
56 53
57 if project is not None: 54 if project is not None:
58 self.setWindowTitle(self.tr("Project Properties")) 55 self.setWindowTitle(self.tr("Project Properties"))
59 56
60 self.nameEdit.setText(project['name']) 57 self.nameEdit.setText(project['name'])
61 self.filenameEdit.setText(project['file']) 58 self.filenamePicker.setText(project['file'])
62 self.descriptionEdit.setPlainText(project['description']) 59 self.descriptionEdit.setPlainText(project['description'])
63 self.masterCheckBox.setChecked(project['master']) 60 self.masterCheckBox.setChecked(project['master'])
64 index = self.categoryComboBox.findText(project['category']) 61 index = self.categoryComboBox.findText(project['category'])
65 if index == -1: 62 if index == -1:
66 index = 0 63 index = 0
67 self.categoryComboBox.setCurrentIndex(index) 64 self.categoryComboBox.setCurrentIndex(index)
68 self.uid = project["uid"] 65 self.uid = project["uid"]
69
70 @pyqtSlot()
71 def on_fileButton_clicked(self):
72 """
73 Private slot to display a file selection dialog.
74 """
75 startdir = self.filenameEdit.text()
76 if startdir or self.startdir is not None:
77 if not startdir:
78 startdir = self.startdir
79 projectFile = E5FileDialog.getOpenFileName(
80 self,
81 self.tr("Add Project"),
82 startdir,
83 self.tr("Project Files (*.e4p)"))
84
85 if projectFile:
86 self.filenameEdit.setText(
87 Utilities.toNativeSeparators(projectFile))
88 66
89 def getData(self): 67 def getData(self):
90 """ 68 """
91 Public slot to retrieve the dialogs data. 69 Public slot to retrieve the dialogs data.
92 70
98 if not self.uid: 76 if not self.uid:
99 # new project entry 77 # new project entry
100 from PyQt5.QtCore import QUuid 78 from PyQt5.QtCore import QUuid
101 self.uid = QUuid.createUuid().toString() 79 self.uid = QUuid.createUuid().toString()
102 80
103 filename = Utilities.toNativeSeparators(self.filenameEdit.text()) 81 filename = self.filenamePicker.text()
104 if not os.path.isabs(filename): 82 if not os.path.isabs(filename):
105 filename = Utilities.toNativeSeparators( 83 filename = Utilities.toNativeSeparators(
106 os.path.join(self.startdir, filename)) 84 os.path.join(self.startdir, filename))
107 return (self.nameEdit.text(), 85 return (self.nameEdit.text(),
108 filename, 86 filename,
119 @param txt text of the edit (string) 97 @param txt text of the edit (string)
120 """ 98 """
121 self.__updateUi() 99 self.__updateUi()
122 100
123 @pyqtSlot(str) 101 @pyqtSlot(str)
124 def on_filenameEdit_textChanged(self, txt): 102 def on_filenamePicker_textChanged(self, txt):
125 """ 103 """
126 Private slot called when the project filename has changed. 104 Private slot called when the project filename has changed.
127 105
128 @param txt text of the edit (string) 106 @param txt text of the edit (string)
129 """ 107 """
132 def __updateUi(self): 110 def __updateUi(self):
133 """ 111 """
134 Private method to update the dialog. 112 Private method to update the dialog.
135 """ 113 """
136 self.__okButton.setEnabled(self.nameEdit.text() != "" and 114 self.__okButton.setEnabled(self.nameEdit.text() != "" and
137 self.filenameEdit.text() != "") 115 self.filenamePicker.text() != "")

eric ide

mercurial