24 |
24 |
25 def __reorderFilter(filterStr, initialFilter=""): |
25 def __reorderFilter(filterStr, initialFilter=""): |
26 """ |
26 """ |
27 Private function to reorder the file filter to cope with a KDE issue |
27 Private function to reorder the file filter to cope with a KDE issue |
28 introduced by distributor's usage of KDE file dialogs. |
28 introduced by distributor's usage of KDE file dialogs. |
29 |
29 |
30 @param filterStr Qt file filter |
30 @param filterStr Qt file filter |
31 @type str |
31 @type str |
32 @param initialFilter initial filter |
32 @param initialFilter initial filter |
33 @type str |
33 @type str |
34 @return the rearranged Qt file filter |
34 @return the rearranged Qt file filter |
35 @rtype str |
35 @rtype str |
36 """ |
36 """ |
37 if initialFilter and not Globals.isMacPlatform(): |
37 if initialFilter and not Globals.isMacPlatform(): |
38 fileFilters = filterStr.split(';;') |
38 fileFilters = filterStr.split(";;") |
39 if len(fileFilters) < 10 and initialFilter in fileFilters: |
39 if len(fileFilters) < 10 and initialFilter in fileFilters: |
40 fileFilters.remove(initialFilter) |
40 fileFilters.remove(initialFilter) |
41 fileFilters.insert(0, initialFilter) |
41 fileFilters.insert(0, initialFilter) |
42 return ";;".join(fileFilters) |
42 return ";;".join(fileFilters) |
43 else: |
43 else: |
44 return filterStr |
44 return filterStr |
45 |
45 |
46 |
46 |
47 def getOpenFileName(parent=None, caption="", directory="", |
47 def getOpenFileName(parent=None, caption="", directory="", filterStr="", options=None): |
48 filterStr="", options=None): |
|
49 """ |
48 """ |
50 Module function to get the name of a file for opening it. |
49 Module function to get the name of a file for opening it. |
51 |
50 |
52 @param parent parent widget of the dialog |
51 @param parent parent widget of the dialog |
53 @type QWidget |
52 @type QWidget |
54 @param caption window title of the dialog |
53 @param caption window title of the dialog |
55 @type str |
54 @type str |
56 @param directory working directory of the dialog |
55 @param directory working directory of the dialog |
63 @rtype str |
62 @rtype str |
64 """ |
63 """ |
65 if options is None: |
64 if options is None: |
66 options = QFileDialog.Option(0) |
65 options = QFileDialog.Option(0) |
67 return QFileDialog.getOpenFileName( |
66 return QFileDialog.getOpenFileName( |
68 parent, caption, directory, filterStr, "", options)[0] |
67 parent, caption, directory, filterStr, "", options |
69 |
68 )[0] |
70 |
69 |
71 def getOpenFileNameAndFilter(parent=None, caption="", directory="", |
70 |
72 filterStr="", initialFilter="", |
71 def getOpenFileNameAndFilter( |
73 options=None): |
72 parent=None, caption="", directory="", filterStr="", initialFilter="", options=None |
|
73 ): |
74 """ |
74 """ |
75 Module function to get the name of a file for opening it and the selected |
75 Module function to get the name of a file for opening it and the selected |
76 file name filter. |
76 file name filter. |
77 |
77 |
78 @param parent parent widget of the dialog |
78 @param parent parent widget of the dialog |
79 @type QWidget |
79 @type QWidget |
80 @param caption window title of the dialog |
80 @param caption window title of the dialog |
81 @type str |
81 @type str |
82 @param directory working directory of the dialog |
82 @param directory working directory of the dialog |
92 """ |
92 """ |
93 if options is None: |
93 if options is None: |
94 options = QFileDialog.Option(0) |
94 options = QFileDialog.Option(0) |
95 newfilter = __reorderFilter(filterStr, initialFilter) |
95 newfilter = __reorderFilter(filterStr, initialFilter) |
96 return QFileDialog.getOpenFileName( |
96 return QFileDialog.getOpenFileName( |
97 parent, caption, directory, newfilter, initialFilter, options) |
97 parent, caption, directory, newfilter, initialFilter, options |
98 |
98 ) |
99 |
99 |
100 def getOpenFileNames(parent=None, caption="", directory="", |
100 |
101 filterStr="", options=None): |
101 def getOpenFileNames(parent=None, caption="", directory="", filterStr="", options=None): |
102 """ |
102 """ |
103 Module function to get a list of names of files for opening. |
103 Module function to get a list of names of files for opening. |
104 |
104 |
105 @param parent parent widget of the dialog |
105 @param parent parent widget of the dialog |
106 @type QWidget |
106 @type QWidget |
107 @param caption window title of the dialog |
107 @param caption window title of the dialog |
108 @type str |
108 @type str |
109 @param directory working directory of the dialog |
109 @param directory working directory of the dialog |
116 @rtype list of str |
116 @rtype list of str |
117 """ |
117 """ |
118 if options is None: |
118 if options is None: |
119 options = QFileDialog.Option(0) |
119 options = QFileDialog.Option(0) |
120 return QFileDialog.getOpenFileNames( |
120 return QFileDialog.getOpenFileNames( |
121 parent, caption, directory, filterStr, "", options)[0] |
121 parent, caption, directory, filterStr, "", options |
122 |
122 )[0] |
123 |
123 |
124 def getOpenFileNamesAndFilter(parent=None, caption="", directory="", |
124 |
125 filterStr="", initialFilter="", |
125 def getOpenFileNamesAndFilter( |
126 options=None): |
126 parent=None, caption="", directory="", filterStr="", initialFilter="", options=None |
|
127 ): |
127 """ |
128 """ |
128 Module function to get a list of names of files for opening and the |
129 Module function to get a list of names of files for opening and the |
129 selected file name filter. |
130 selected file name filter. |
130 |
131 |
131 @param parent parent widget of the dialog |
132 @param parent parent widget of the dialog |
132 @type QWidget |
133 @type QWidget |
133 @param caption window title of the dialog |
134 @param caption window title of the dialog |
134 @type str |
135 @type str |
135 @param directory working directory of the dialog |
136 @param directory working directory of the dialog |
145 """ |
146 """ |
146 if options is None: |
147 if options is None: |
147 options = QFileDialog.Option(0) |
148 options = QFileDialog.Option(0) |
148 newfilter = __reorderFilter(filterStr, initialFilter) |
149 newfilter = __reorderFilter(filterStr, initialFilter) |
149 return QFileDialog.getOpenFileNames( |
150 return QFileDialog.getOpenFileNames( |
150 parent, caption, directory, newfilter, initialFilter, options) |
151 parent, caption, directory, newfilter, initialFilter, options |
151 |
152 ) |
152 |
153 |
153 def getOpenFileAndDirNames(parent=None, caption="", directory="", |
154 |
154 filterStr="", options=None): |
155 def getOpenFileAndDirNames( |
|
156 parent=None, caption="", directory="", filterStr="", options=None |
|
157 ): |
155 """ |
158 """ |
156 Module function to get the names of files and directories for opening. |
159 Module function to get the names of files and directories for opening. |
157 |
160 |
158 @param parent parent widget of the dialog |
161 @param parent parent widget of the dialog |
159 @type QWidget |
162 @type QWidget |
160 @param caption window title of the dialog |
163 @param caption window title of the dialog |
161 @type str |
164 @type str |
162 @param directory working directory of the dialog |
165 @param directory working directory of the dialog |
167 @type QFileDialog.Options |
170 @type QFileDialog.Options |
168 @return names of the selected files and folders |
171 @return names of the selected files and folders |
169 @rtype list of str |
172 @rtype list of str |
170 """ |
173 """ |
171 from .EricDirFileDialog import EricDirFileDialog |
174 from .EricDirFileDialog import EricDirFileDialog |
|
175 |
172 return EricDirFileDialog.getOpenFileAndDirNames( |
176 return EricDirFileDialog.getOpenFileAndDirNames( |
173 parent, caption, directory, filterStr, options |
177 parent, caption, directory, filterStr, options |
174 ) |
178 ) |
175 |
179 |
176 |
180 |
177 def getSaveFileName(parent=None, caption="", directory="", |
181 def getSaveFileName(parent=None, caption="", directory="", filterStr="", options=None): |
178 filterStr="", options=None): |
|
179 """ |
182 """ |
180 Module function to get the name of a file for saving it. |
183 Module function to get the name of a file for saving it. |
181 |
184 |
182 @param parent parent widget of the dialog |
185 @param parent parent widget of the dialog |
183 @type QWidget |
186 @type QWidget |
184 @param caption window title of the dialog |
187 @param caption window title of the dialog |
185 @type str |
188 @type str |
186 @param directory working directory of the dialog |
189 @param directory working directory of the dialog |
193 @rtype str |
196 @rtype str |
194 """ |
197 """ |
195 if options is None: |
198 if options is None: |
196 options = QFileDialog.Option(0) |
199 options = QFileDialog.Option(0) |
197 return QFileDialog.getSaveFileName( |
200 return QFileDialog.getSaveFileName( |
198 parent, caption, directory, filterStr, "", options)[0] |
201 parent, caption, directory, filterStr, "", options |
199 |
202 )[0] |
200 |
203 |
201 def getSaveFileNameAndFilter(parent=None, caption="", directory="", |
204 |
202 filterStr="", initialFilter="", |
205 def getSaveFileNameAndFilter( |
203 options=None): |
206 parent=None, caption="", directory="", filterStr="", initialFilter="", options=None |
|
207 ): |
204 """ |
208 """ |
205 Module function to get the name of a file for saving it and the selected |
209 Module function to get the name of a file for saving it and the selected |
206 file name filter. |
210 file name filter. |
207 |
211 |
208 @param parent parent widget of the dialog |
212 @param parent parent widget of the dialog |
209 @type QWidget |
213 @type QWidget |
210 @param caption window title of the dialog |
214 @param caption window title of the dialog |
211 @type str |
215 @type str |
212 @param directory working directory of the dialog |
216 @param directory working directory of the dialog |
222 """ |
226 """ |
223 if options is None: |
227 if options is None: |
224 options = QFileDialog.Option(0) |
228 options = QFileDialog.Option(0) |
225 newfilter = __reorderFilter(filterStr, initialFilter) |
229 newfilter = __reorderFilter(filterStr, initialFilter) |
226 return QFileDialog.getSaveFileName( |
230 return QFileDialog.getSaveFileName( |
227 parent, caption, directory, newfilter, initialFilter, options) |
231 parent, caption, directory, newfilter, initialFilter, options |
228 |
232 ) |
229 |
233 |
230 def getExistingDirectory(parent=None, caption="", |
234 |
231 directory="", |
235 def getExistingDirectory( |
232 options=QFileDialog.Option.ShowDirsOnly): |
236 parent=None, caption="", directory="", options=QFileDialog.Option.ShowDirsOnly |
|
237 ): |
233 """ |
238 """ |
234 Module function to get the name of a directory. |
239 Module function to get the name of a directory. |
235 |
240 |
236 @param parent parent widget of the dialog |
241 @param parent parent widget of the dialog |
237 @type QWidget |
242 @type QWidget |
238 @param caption window title of the dialog |
243 @param caption window title of the dialog |
239 @type str |
244 @type str |
240 @param directory working directory of the dialog |
245 @param directory working directory of the dialog |