src/eric7/EricWidgets/EricFileDialog.py

branch
eric7
changeset 11035
e1e1d6e317c7
parent 10537
cd0fd14d09d5
child 11090
f5f5f5803935
equal deleted inserted replaced
11034:7b8a21fd2d58 11035:e1e1d6e317c7
7 Module implementing alternative functions for the QFileDialog static methods. 7 Module implementing alternative functions for the QFileDialog static methods.
8 """ 8 """
9 9
10 import pathlib 10 import pathlib
11 11
12 from PyQt6.QtCore import QCoreApplication
12 from PyQt6.QtWidgets import QFileDialog 13 from PyQt6.QtWidgets import QFileDialog
13 14
14 from eric7.SystemUtilities import OSUtilities 15 from eric7.SystemUtilities import OSUtilities
15 16
16 Option = QFileDialog.Option 17 Option = QFileDialog.Option
70 @param options various options for the dialog (defaults to None) 71 @param options various options for the dialog (defaults to None)
71 @type QFileDialog.Options ((optional) 72 @type QFileDialog.Options ((optional)
72 @return name of file to be opened 73 @return name of file to be opened
73 @rtype str 74 @rtype str
74 """ 75 """
76 if parent is None:
77 parent = QCoreApplication.instance().getMainWindow()
78
75 return getOpenFileNameAndFilter( 79 return getOpenFileNameAndFilter(
76 parent, caption, directory, filterStr, initialFilter, options 80 parent, caption, directory, filterStr, initialFilter, options
77 )[0] 81 )[0]
78 82
79 83
97 @param options various options for the dialog (defaults to None) 101 @param options various options for the dialog (defaults to None)
98 @type QFileDialog.Options ((optional) 102 @type QFileDialog.Options ((optional)
99 @return name of file to be opened and selected filter 103 @return name of file to be opened and selected filter
100 @rtype tuple of (str, str) 104 @rtype tuple of (str, str)
101 """ 105 """
106 if parent is None:
107 parent = QCoreApplication.instance().getMainWindow()
108
102 if options is None: 109 if options is None:
103 options = QFileDialog.Option(0) 110 options = QFileDialog.Option(0)
104 newfilter = __reorderFilter(filterStr, initialFilter) 111 newfilter = __reorderFilter(filterStr, initialFilter)
105 return QFileDialog.getOpenFileName( 112 return QFileDialog.getOpenFileName(
106 parent, caption, directory, newfilter, initialFilter, options 113 parent, caption, directory, newfilter, initialFilter, options
126 @param options various options for the dialog (defaults to None) 133 @param options various options for the dialog (defaults to None)
127 @type QFileDialog.Options ((optional) 134 @type QFileDialog.Options ((optional)
128 @return list of file names to be opened 135 @return list of file names to be opened
129 @rtype list of str 136 @rtype list of str
130 """ 137 """
138 if parent is None:
139 parent = QCoreApplication.instance().getMainWindow()
140
131 return getOpenFileNamesAndFilter( 141 return getOpenFileNamesAndFilter(
132 parent, caption, directory, filterStr, initialFilter, options 142 parent, caption, directory, filterStr, initialFilter, options
133 )[0] 143 )[0]
134 144
135 145
153 @param options various options for the dialog (defaults to None) 163 @param options various options for the dialog (defaults to None)
154 @type QFileDialog.Options ((optional) 164 @type QFileDialog.Options ((optional)
155 @return list of file names to be opened and selected filter 165 @return list of file names to be opened and selected filter
156 @rtype tuple of (list of str, str) 166 @rtype tuple of (list of str, str)
157 """ 167 """
168 if parent is None:
169 parent = QCoreApplication.instance().getMainWindow()
170
158 if options is None: 171 if options is None:
159 options = QFileDialog.Option(0) 172 options = QFileDialog.Option(0)
160 newfilter = __reorderFilter(filterStr, initialFilter) 173 newfilter = __reorderFilter(filterStr, initialFilter)
161 return QFileDialog.getOpenFileNames( 174 return QFileDialog.getOpenFileNames(
162 parent, caption, directory, newfilter, initialFilter, options 175 parent, caption, directory, newfilter, initialFilter, options
182 @return names of the selected files and folders 195 @return names of the selected files and folders
183 @rtype list of str 196 @rtype list of str
184 """ 197 """
185 from .EricDirFileDialog import EricDirFileDialog 198 from .EricDirFileDialog import EricDirFileDialog
186 199
200 if parent is None:
201 parent = QCoreApplication.instance().getMainWindow()
202
187 return EricDirFileDialog.getOpenFileAndDirNames( 203 return EricDirFileDialog.getOpenFileAndDirNames(
188 parent, caption, directory, filterStr, options 204 parent, caption, directory, filterStr, options
189 ) 205 )
190 206
191 207
208 @param options various options for the dialog (defaults to None) 224 @param options various options for the dialog (defaults to None)
209 @type QFileDialog.Options ((optional) 225 @type QFileDialog.Options ((optional)
210 @return name of file to be saved 226 @return name of file to be saved
211 @rtype str 227 @rtype str
212 """ 228 """
229 if parent is None:
230 parent = QCoreApplication.instance().getMainWindow()
231
213 return getSaveFileNameAndFilter( 232 return getSaveFileNameAndFilter(
214 parent, caption, directory, filterStr, initialFilter, options 233 parent, caption, directory, filterStr, initialFilter, options
215 )[0] 234 )[0]
216 235
217 236
235 @param options various options for the dialog (defaults to None) 254 @param options various options for the dialog (defaults to None)
236 @type QFileDialog.Options ((optional) 255 @type QFileDialog.Options ((optional)
237 @return name of file to be saved and selected filte 256 @return name of file to be saved and selected filte
238 @rtype tuple of (str, str) 257 @rtype tuple of (str, str)
239 """ 258 """
259 if parent is None:
260 parent = QCoreApplication.instance().getMainWindow()
261
240 if options is None: 262 if options is None:
241 options = QFileDialog.Option(0) 263 options = QFileDialog.Option(0)
242 newfilter = __reorderFilter(filterStr, initialFilter) 264 newfilter = __reorderFilter(filterStr, initialFilter)
243 return QFileDialog.getSaveFileName( 265 return QFileDialog.getSaveFileName(
244 parent, caption, directory, newfilter, initialFilter, options 266 parent, caption, directory, newfilter, initialFilter, options
261 QFileDialog.Option.ShowDirsOnly) 283 QFileDialog.Option.ShowDirsOnly)
262 @type QFileDialog.Options ((optional) 284 @type QFileDialog.Options ((optional)
263 @return name of selected directory 285 @return name of selected directory
264 @rtype str 286 @rtype str
265 """ 287 """
288 if parent is None:
289 parent = QCoreApplication.instance().getMainWindow()
290
266 if options is None: 291 if options is None:
267 options = QFileDialog.Option(0) 292 options = QFileDialog.Option(0)
268 return QFileDialog.getExistingDirectory(parent, caption, directory, options) 293 return QFileDialog.getExistingDirectory(parent, caption, directory, options)
269 294
270 295
292 @param options various options for the dialog (defaults to None) 317 @param options various options for the dialog (defaults to None)
293 @type QFileDialog.Options ((optional) 318 @type QFileDialog.Options ((optional)
294 @return path of file to be opened 319 @return path of file to be opened
295 @rtype pathlib.Path 320 @rtype pathlib.Path
296 """ 321 """
322 if parent is None:
323 parent = QCoreApplication.instance().getMainWindow()
324
297 return getOpenFilePathAndFilter( 325 return getOpenFilePathAndFilter(
298 parent, caption, directory, filterStr, initialFilter, options 326 parent, caption, directory, filterStr, initialFilter, options
299 )[0] 327 )[0]
300 328
301 329
319 @param options various options for the dialog (defaults to None) 347 @param options various options for the dialog (defaults to None)
320 @type QFileDialog.Options ((optional) 348 @type QFileDialog.Options ((optional)
321 @return path of file to be opened and selected filter 349 @return path of file to be opened and selected filter
322 @rtype tuple of (pathlib.Path, str) 350 @rtype tuple of (pathlib.Path, str)
323 """ 351 """
352 if parent is None:
353 parent = QCoreApplication.instance().getMainWindow()
354
324 if options is None: 355 if options is None:
325 options = QFileDialog.Option(0) 356 options = QFileDialog.Option(0)
326 newfilter = __reorderFilter(filterStr, initialFilter) 357 newfilter = __reorderFilter(filterStr, initialFilter)
327 filename, selectedFilter = QFileDialog.getOpenFileName( 358 filename, selectedFilter = QFileDialog.getOpenFileName(
328 parent, caption, str(directory), newfilter, initialFilter, options 359 parent, caption, str(directory), newfilter, initialFilter, options
349 @param options various options for the dialog (defaults to None) 380 @param options various options for the dialog (defaults to None)
350 @type QFileDialog.Options ((optional) 381 @type QFileDialog.Options ((optional)
351 @return list of file paths to be opened 382 @return list of file paths to be opened
352 @rtype list of pathlib.Path 383 @rtype list of pathlib.Path
353 """ 384 """
385 if parent is None:
386 parent = QCoreApplication.instance().getMainWindow()
387
354 return getOpenFilPathsAndFilter( 388 return getOpenFilPathsAndFilter(
355 parent, caption, directory, filterStr, initialFilter, options 389 parent, caption, directory, filterStr, initialFilter, options
356 )[0] 390 )[0]
357 391
358 392
376 @param options various options for the dialog (defaults to None) 410 @param options various options for the dialog (defaults to None)
377 @type QFileDialog.Options ((optional) 411 @type QFileDialog.Options ((optional)
378 @return list of file paths to be opened and selected filter 412 @return list of file paths to be opened and selected filter
379 @rtype tuple of (list of pathlib.Path, str) 413 @rtype tuple of (list of pathlib.Path, str)
380 """ 414 """
415 if parent is None:
416 parent = QCoreApplication.instance().getMainWindow()
417
381 if options is None: 418 if options is None:
382 options = QFileDialog.Option(0) 419 options = QFileDialog.Option(0)
383 newfilter = __reorderFilter(filterStr, initialFilter) 420 newfilter = __reorderFilter(filterStr, initialFilter)
384 filenames, selectedFilter = QFileDialog.getOpenFileNames( 421 filenames, selectedFilter = QFileDialog.getOpenFileNames(
385 parent, caption, str(directory), newfilter, initialFilter, options 422 parent, caption, str(directory), newfilter, initialFilter, options
406 @return paths of the selected files and folders 443 @return paths of the selected files and folders
407 @rtype list of pathlib.Path 444 @rtype list of pathlib.Path
408 """ 445 """
409 from .EricDirFileDialog import EricDirFileDialog 446 from .EricDirFileDialog import EricDirFileDialog
410 447
448 if parent is None:
449 parent = QCoreApplication.instance().getMainWindow()
450
411 return EricDirFileDialog.getOpenFileAndDirPaths( 451 return EricDirFileDialog.getOpenFileAndDirPaths(
412 parent, caption, directory, filterStr, options 452 parent, caption, directory, filterStr, options
413 ) 453 )
414 454
415 455
432 @param options various options for the dialog (defaults to None) 472 @param options various options for the dialog (defaults to None)
433 @type QFileDialog.Options ((optional) 473 @type QFileDialog.Options ((optional)
434 @return path of file to be saved 474 @return path of file to be saved
435 @rtype pathlib.Path 475 @rtype pathlib.Path
436 """ 476 """
477 if parent is None:
478 parent = QCoreApplication.instance().getMainWindow()
479
437 return getSaveFilePathAndFilter( 480 return getSaveFilePathAndFilter(
438 parent, caption, str(directory), filterStr, initialFilter, options 481 parent, caption, str(directory), filterStr, initialFilter, options
439 )[0] 482 )[0]
440 483
441 484
459 @param options various options for the dialog (defaults to None) 502 @param options various options for the dialog (defaults to None)
460 @type QFileDialog.Options ((optional) 503 @type QFileDialog.Options ((optional)
461 @return path of file to be saved and selected filte 504 @return path of file to be saved and selected filte
462 @rtype tuple of (pathlib.Path, str) 505 @rtype tuple of (pathlib.Path, str)
463 """ 506 """
507 if parent is None:
508 parent = QCoreApplication.instance().getMainWindow()
509
464 if options is None: 510 if options is None:
465 options = QFileDialog.Option(0) 511 options = QFileDialog.Option(0)
466 newfilter = __reorderFilter(filterStr, initialFilter) 512 newfilter = __reorderFilter(filterStr, initialFilter)
467 filename, selectedFilter = QFileDialog.getSaveFileName( 513 filename, selectedFilter = QFileDialog.getSaveFileName(
468 parent, caption, directory, newfilter, initialFilter, options 514 parent, caption, directory, newfilter, initialFilter, options
486 QFileDialog.Option.ShowDirsOnly) 532 QFileDialog.Option.ShowDirsOnly)
487 @type QFileDialog.Options ((optional) 533 @type QFileDialog.Options ((optional)
488 @return path of selected directory 534 @return path of selected directory
489 @rtype pathlib.Path 535 @rtype pathlib.Path
490 """ 536 """
537 if parent is None:
538 parent = QCoreApplication.instance().getMainWindow()
539
491 if options is None: 540 if options is None:
492 options = QFileDialog.Option(0) 541 options = QFileDialog.Option(0)
493 dirname = QFileDialog.getExistingDirectory(parent, caption, str(directory), options) 542 dirname = QFileDialog.getExistingDirectory(parent, caption, str(directory), options)
494 return pathlib.Path(dirname) 543 return pathlib.Path(dirname)
495 544

eric ide

mercurial