Project/AddFileDialog.py

changeset 4582
3a1d1d4c6f4f
parent 4021
195a471c327b
child 4601
0017e7cb67ae
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 15 from PyQt5.QtWidgets import QDialog
16 16
17 from E5Gui.E5Completers import E5DirCompleter, E5FileCompleter 17 from E5Gui.E5PathPicker import E5PathPickerModes
18 from E5Gui import E5FileDialog
19 18
20 from .Ui_AddFileDialog import Ui_AddFileDialog 19 from .Ui_AddFileDialog import Ui_AddFileDialog
21
22 import Utilities
23 import UI.PixmapCache
24 20
25 21
26 class AddFileDialog(QDialog, Ui_AddFileDialog): 22 class AddFileDialog(QDialog, Ui_AddFileDialog):
27 """ 23 """
28 Class implementing a dialog to add a file to the project. 24 Class implementing a dialog to add a file to the project.
41 super(AddFileDialog, self).__init__(parent) 37 super(AddFileDialog, self).__init__(parent)
42 if name: 38 if name:
43 self.setObjectName(name) 39 self.setObjectName(name)
44 self.setupUi(self) 40 self.setupUi(self)
45 41
46 self.targetDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) 42 self.sourceFilesPicker.setMode(E5PathPickerModes.OpenFilesMode)
47 self.sourceFileButton.setIcon(UI.PixmapCache.getIcon("open.png")) 43 self.targetDirPicker.setMode(E5PathPickerModes.DirectoryMode)
44 self.targetDirPicker.setDefaultDirectory(startdir)
48 45
49 self.targetDirCompleter = E5DirCompleter(self.targetDirEdit) 46 self.targetDirPicker.setText(pro.ppath)
50 self.sourceFileCompleter = E5FileCompleter(self.sourceFileEdit)
51
52 self.targetDirEdit.setText(pro.ppath)
53 self.filter = filter 47 self.filter = filter
54 self.ppath = pro.ppath 48 self.ppath = pro.ppath
55 self.startdir = startdir 49 self.startdir = startdir
56 self.filetypes = pro.pdata["FILETYPES"] 50 self.filetypes = pro.pdata["FILETYPES"]
57 # save a reference to the filetypes dict 51 # save a reference to the filetypes dict
61 55
62 msh = self.minimumSizeHint() 56 msh = self.minimumSizeHint()
63 self.resize(max(self.width(), msh.width()), msh.height()) 57 self.resize(max(self.width(), msh.width()), msh.height())
64 58
65 @pyqtSlot() 59 @pyqtSlot()
66 def on_targetDirButton_clicked(self): 60 def on_sourceFilesPicker_aboutToShowPathPickerDialog(self):
67 """ 61 """
68 Private slot to display a directory selection dialog. 62 Private slot to perform actions before the source files selection
63 dialog is shown.
69 """ 64 """
70 startdir = self.targetDirEdit.text() 65 path = self.targetDirPicker.text()
71 if not startdir and self.startdir is not None: 66 if not path:
72 startdir = self.startdir 67 path = self.startdir
73 directory = E5FileDialog.getExistingDirectory( 68 self.sourceFilesPicker.setDefaultDirectory(path)
74 self,
75 self.tr("Select target directory"),
76 startdir)
77
78 if directory:
79 self.targetDirEdit.setText(Utilities.toNativeSeparators(directory))
80 69
81 @pyqtSlot()
82 def on_sourceFileButton_clicked(self):
83 """
84 Private slot to display a file selection dialog.
85 """
86 dir = self.sourceFileEdit.text().split(os.pathsep, 1)[0]
87 if not dir:
88 if self.startdir is not None:
89 dir = self.startdir
90 else:
91 dir = self.targetDirEdit.text()
92 if self.filter is None: 70 if self.filter is None:
93 patterns = { 71 patterns = {
94 "SOURCES": [], 72 "SOURCES": [],
95 "FORMS": [], 73 "FORMS": [],
96 "RESOURCES": [], 74 "RESOURCES": [],
156 caption = self.tr("Select translation files") 134 caption = self.tr("Select translation files")
157 elif self.filter == 'others': 135 elif self.filter == 'others':
158 dfilter = self.tr("All Files (*)") 136 dfilter = self.tr("All Files (*)")
159 caption = self.tr("Select files") 137 caption = self.tr("Select files")
160 else: 138 else:
161 return 139 dfilter = ""
140 caption = ""
162 141
163 fnames = E5FileDialog.getOpenFileNames(self, caption, dir, dfilter) 142 self.sourceFilesPicker.setWindowTitle(caption)
164 143 self.sourceFilesPicker.setFilters(dfilter)
165 if len(fnames):
166 self.sourceFileEdit.setText(Utilities.toNativeSeparators(
167 os.pathsep.join(fnames)))
168 144
169 @pyqtSlot(str) 145 @pyqtSlot(str)
170 def on_sourceFileEdit_textChanged(self, sfile): 146 def on_sourceFilesPicker_textChanged(self, sfile):
171 """ 147 """
172 Private slot to handle the source file text changed. 148 Private slot to handle the source file text changed.
173 149
174 If the entered source directory is a subdirectory of the current 150 If the entered source directory is a subdirectory of the current
175 projects main directory, the target directory path is synchronized. 151 projects main directory, the target directory path is synchronized.
176 It is assumed, that the user wants to add a bunch of files to 152 It is assumed, that the user wants to add a bunch of files to
177 the project in place. 153 the project in place.
178 154
179 @param sfile the text of the source file line edit (string) 155 @param sfile the text of the source file picker (string)
180 """ 156 """
181 sfile = sfile.split(os.pathsep, 1)[0] 157 sfile = self.sourceFilesPicker.firstPath()
182 if sfile.startswith(self.ppath): 158 if sfile.startswith(self.ppath):
183 if os.path.isdir(sfile): 159 if os.path.isdir(sfile):
184 dir = sfile 160 dir = sfile
185 else: 161 else:
186 dir = os.path.dirname(sfile) 162 dir = os.path.dirname(sfile)
187 self.targetDirEdit.setText(dir) 163 self.targetDirPicker.setText(dir)
188 164
189 def getData(self): 165 def getData(self):
190 """ 166 """
191 Public slot to retrieve the dialogs data. 167 Public slot to retrieve the dialogs data.
192 168
193 @return tuple of three values (list of string, string, boolean) 169 @return tuple of three values (list of string, string, boolean)
194 giving the source files, the target directory and a flag 170 giving the source files, the target directory and a flag
195 telling, whether the files shall be added as source code 171 telling, whether the files shall be added as source code
196 """ 172 """
197 return ( 173 return (
198 [Utilities.toNativeSeparators(f) for f in 174 self.sourceFilesPicker.paths(),
199 self.sourceFileEdit.text().split(os.pathsep)], 175 self.targetDirPicker.text(),
200 Utilities.toNativeSeparators(self.targetDirEdit.text()),
201 self.sourcecodeCheckBox.isChecked()) 176 self.sourcecodeCheckBox.isChecked())

eric ide

mercurial