Debian Codegraph @

plyer/facades/filechooser.py

raw symbols SCIP
1 '''
2 Native filechooser dialog facade.
3 =================================
4
5 open_file, save_file and choose_dir accept a number of arguments
6 listed below. They return either a list of paths (normally
7 absolute), or None if no file was selected or the operation was
8 canceled and no result is available.
9
10 Arguments:
11 * **path** *(string or None)*: a path that will be selected
12 by default, or None
13 * **multiple** *(bool)*: True if you want the dialog to
14 allow multiple file selection. (Note: Windows doesn't
15 support multiple directory selection)
16 * **filters** *(iterable)*: either a list of wildcard patterns
17 or of sequences that contain the name of the filter and any
18 number of wildcards that will be grouped under that name
19 (e.g. [["Music", "*mp3", "*ogg", "*aac"], "*jpg", "*py"])
20 * **preview** *(bool)*: True if you want the file chooser to
21 show a preview of the selected file, if supported by the
22 back-end.
23 * **title** *(string or None)*: The title of the file chooser
24 window, or None for the default title.
25 * **icon** *(string or None)*: Path to the icon of the file
26 chooser window (where supported), or None for the back-end's
27 default.
28 * **show_hidden** *(bool)*: Force showing hidden files (currently
29 supported only on Windows)
30 * **on_selection** *(func)*: Callback for fetching the selection.
31
32 Important: these methods will return only after user interaction.
33 Use threads or you will stop the mainloop if your app has one.
34
35 .. versionchanged:: 1.4.0
36 Added Android implementation for open_file()
37 Added ``on_selection`` kwarg for callback function
38
39 Supported Plaforms
40 ------------------
41 Android, iOS, macOS, Linux, Windows
42 '''
43
44
45 class FileChooser:
46 '''
47 File Chooser facade.
48 '''
49
50 def open_file(self, *args, **kwargs):
51 """
52 Open the file chooser in "open" mode.
53 """
54 return self._file_selection_dialog(mode="open", *args, **kwargs)
55
56 def save_file(self, *args, **kwargs):
57 """
58 Open the file chooser in "save" mode. Confirmation will be asked
59 when a file with the same name already exists.
60 """
61 return self._file_selection_dialog(mode="save", *args, **kwargs)
62
63 def choose_dir(self, *args, **kwargs):
64 """
65 Open the directory chooser. Note that on Windows this is very
66 limited. Consider writing your own chooser if you target that
67 platform and are planning on using unsupported features.
68 """
69 return self._file_selection_dialog(mode="dir", *args, **kwargs)
70
71 # private
72
73 def _file_selection_dialog(self, **kwargs):
74 raise NotImplementedError()