eric7/EricWidgets/EricFileDialog.py

branch
eric7
changeset 8403
d9fd02e8c28b
parent 8360
2a91e0e05926
child 8881
54e42bc2437a
equal deleted inserted replaced
8399:0a80c37a868a 8403:d9fd02e8c28b
2 2
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing alternative functions for the QFileDialog static methods 7 Module implementing alternative functions for the QFileDialog static methods.
8 to cope with distributor's usage of KDE wrapper dialogs for Qt file dialogs.
9 """ 8 """
10 9
11 from PyQt6.QtWidgets import QFileDialog 10 from PyQt6.QtWidgets import QFileDialog
12 11
13 import Globals 12 import Globals
26 def __reorderFilter(filterStr, initialFilter=""): 25 def __reorderFilter(filterStr, initialFilter=""):
27 """ 26 """
28 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
29 introduced by distributor's usage of KDE file dialogs. 28 introduced by distributor's usage of KDE file dialogs.
30 29
31 @param filterStr Qt file filter (string) 30 @param filterStr Qt file filter
32 @param initialFilter initial filter (string) 31 @type str
33 @return the rearranged Qt file filter (string) 32 @param initialFilter initial filter
33 @type str
34 @return the rearranged Qt file filter
35 @rtype str
34 """ 36 """
35 if initialFilter and not Globals.isMacPlatform(): 37 if initialFilter and not Globals.isMacPlatform():
36 fileFilters = filterStr.split(';;') 38 fileFilters = filterStr.split(';;')
37 if len(fileFilters) < 10 and initialFilter in fileFilters: 39 if len(fileFilters) < 10 and initialFilter in fileFilters:
38 fileFilters.remove(initialFilter) 40 fileFilters.remove(initialFilter)
45 def getOpenFileName(parent=None, caption="", directory="", 47 def getOpenFileName(parent=None, caption="", directory="",
46 filterStr="", options=None): 48 filterStr="", options=None):
47 """ 49 """
48 Module function to get the name of a file for opening it. 50 Module function to get the name of a file for opening it.
49 51
50 @param parent parent widget of the dialog (QWidget) 52 @param parent parent widget of the dialog
51 @param caption window title of the dialog (string) 53 @type QWidget
52 @param directory working directory of the dialog (string) 54 @param caption window title of the dialog
53 @param filterStr filter string for the dialog (string) 55 @type str
54 @param options various options for the dialog (QFileDialog.Options) 56 @param directory working directory of the dialog
55 @return name of file to be opened (string) 57 @type str
58 @param filterStr filter string for the dialog
59 @type str
60 @param options various options for the dialog
61 @type QFileDialog.Options
62 @return name of file to be opened
63 @rtype str
56 """ 64 """
57 if options is None: 65 if options is None:
58 options = QFileDialog.Option(0) 66 options = QFileDialog.Option(0)
59 if Globals.isLinuxPlatform(): 67 if Globals.isLinuxPlatform():
60 options |= QFileDialog.Option.DontUseNativeDialog 68 options |= QFileDialog.Option.DontUseNativeDialog
67 options=None): 75 options=None):
68 """ 76 """
69 Module function to get the name of a file for opening it and the selected 77 Module function to get the name of a file for opening it and the selected
70 file name filter. 78 file name filter.
71 79
72 @param parent parent widget of the dialog (QWidget) 80 @param parent parent widget of the dialog
73 @param caption window title of the dialog (string) 81 @type QWidget
74 @param directory working directory of the dialog (string) 82 @param caption window title of the dialog
75 @param filterStr filter string for the dialog (string) 83 @type str
76 @param initialFilter initial filter for the dialog (string) 84 @param directory working directory of the dialog
77 @param options various options for the dialog (QFileDialog.Options) 85 @type str
78 @return name of file to be opened and selected filter (string, string) 86 @param filterStr filter string for the dialog
87 @type str
88 @param initialFilter initial filter for the dialog
89 @type str
90 @param options various options for the dialog
91 @type QFileDialog.Options
92 @return name of file to be opened and selected filter
93 @rtype tuple of (str, str)
79 """ 94 """
80 if options is None: 95 if options is None:
81 options = QFileDialog.Option(0) 96 options = QFileDialog.Option(0)
82 if Globals.isLinuxPlatform(): 97 if Globals.isLinuxPlatform():
83 options |= QFileDialog.Option.DontUseNativeDialog 98 options |= QFileDialog.Option.DontUseNativeDialog
89 def getOpenFileNames(parent=None, caption="", directory="", 104 def getOpenFileNames(parent=None, caption="", directory="",
90 filterStr="", options=None): 105 filterStr="", options=None):
91 """ 106 """
92 Module function to get a list of names of files for opening. 107 Module function to get a list of names of files for opening.
93 108
94 @param parent parent widget of the dialog (QWidget) 109 @param parent parent widget of the dialog
95 @param caption window title of the dialog (string) 110 @type QWidget
96 @param directory working directory of the dialog (string) 111 @param caption window title of the dialog
97 @param filterStr filter string for the dialog (string) 112 @type str
98 @param options various options for the dialog (QFileDialog.Options) 113 @param directory working directory of the dialog
99 @return list of file names to be opened (list of string) 114 @type str
115 @param filterStr filter string for the dialog
116 @type str
117 @param options various options for the dialog
118 @type QFileDialog.Options
119 @return list of file names to be opened
120 @rtype list of str
100 """ 121 """
101 if options is None: 122 if options is None:
102 options = QFileDialog.Option(0) 123 options = QFileDialog.Option(0)
103 if Globals.isLinuxPlatform(): 124 if Globals.isLinuxPlatform():
104 options |= QFileDialog.Option.DontUseNativeDialog 125 options |= QFileDialog.Option.DontUseNativeDialog
111 options=None): 132 options=None):
112 """ 133 """
113 Module function to get a list of names of files for opening and the 134 Module function to get a list of names of files for opening and the
114 selected file name filter. 135 selected file name filter.
115 136
116 @param parent parent widget of the dialog (QWidget) 137 @param parent parent widget of the dialog
117 @param caption window title of the dialog (string) 138 @type QWidget
118 @param directory working directory of the dialog (string) 139 @param caption window title of the dialog
119 @param filterStr filter string for the dialog (string) 140 @type str
120 @param initialFilter initial filter for the dialog (string) 141 @param directory working directory of the dialog
121 @param options various options for the dialog (QFileDialog.Options) 142 @type str
143 @param filterStr filter string for the dialog
144 @type str
145 @param initialFilter initial filter for the dialog
146 @type str
147 @param options various options for the dialog
148 @type QFileDialog.Options
122 @return list of file names to be opened and selected filter 149 @return list of file names to be opened and selected filter
123 (list of string, string) 150 @rtype tuple of (list of str, str)
124 """ 151 """
125 if options is None: 152 if options is None:
126 options = QFileDialog.Option(0) 153 options = QFileDialog.Option(0)
127 if Globals.isLinuxPlatform(): 154 if Globals.isLinuxPlatform():
128 options |= QFileDialog.Option.DontUseNativeDialog 155 options |= QFileDialog.Option.DontUseNativeDialog
129 newfilter = __reorderFilter(filterStr, initialFilter) 156 newfilter = __reorderFilter(filterStr, initialFilter)
130 return QFileDialog.getOpenFileNames( 157 return QFileDialog.getOpenFileNames(
131 parent, caption, directory, newfilter, initialFilter, options) 158 parent, caption, directory, newfilter, initialFilter, options)
132 159
133 160
161 def getOpenFileAndDirNames(parent=None, caption="", directory="",
162 filterStr="", options=None):
163 """
164 Module function to get the names of files and directories for opening.
165
166 @param parent parent widget of the dialog
167 @type QWidget
168 @param caption window title of the dialog
169 @type str
170 @param directory working directory of the dialog
171 @type str
172 @param filterStr filter string for the dialog
173 @type str
174 @param options various options for the dialog
175 @type QFileDialog.Options
176 @return names of the selected files and folders
177 @rtype list of str
178 """
179 from .EricDirFileDialog import EricDirFileDialog
180 return EricDirFileDialog.getOpenFileAndDirNames(
181 parent, caption, directory, filterStr, options
182 )
183
184
134 def getSaveFileName(parent=None, caption="", directory="", 185 def getSaveFileName(parent=None, caption="", directory="",
135 filterStr="", options=None): 186 filterStr="", options=None):
136 """ 187 """
137 Module function to get the name of a file for saving it. 188 Module function to get the name of a file for saving it.
138 189
139 @param parent parent widget of the dialog (QWidget) 190 @param parent parent widget of the dialog
140 @param caption window title of the dialog (string) 191 @type QWidget
141 @param directory working directory of the dialog (string) 192 @param caption window title of the dialog
142 @param filterStr filter string for the dialog (string) 193 @type str
143 @param options various options for the dialog (QFileDialog.Options) 194 @param directory working directory of the dialog
144 @return name of file to be saved (string) 195 @type str
196 @param filterStr filter string for the dialog
197 @type str
198 @param options various options for the dialog
199 @type QFileDialog.Options
200 @return name of file to be saved
201 @rtype str
145 """ 202 """
146 if options is None: 203 if options is None:
147 options = QFileDialog.Option(0) 204 options = QFileDialog.Option(0)
148 if Globals.isLinuxPlatform(): 205 if Globals.isLinuxPlatform():
149 options |= QFileDialog.Option.DontUseNativeDialog 206 options |= QFileDialog.Option.DontUseNativeDialog
156 options=None): 213 options=None):
157 """ 214 """
158 Module function to get the name of a file for saving it and the selected 215 Module function to get the name of a file for saving it and the selected
159 file name filter. 216 file name filter.
160 217
161 @param parent parent widget of the dialog (QWidget) 218 @param parent parent widget of the dialog
162 @param caption window title of the dialog (string) 219 @type QWidget
163 @param directory working directory of the dialog (string) 220 @param caption window title of the dialog
164 @param filterStr filter string for the dialog (string) 221 @type str
165 @param initialFilter initial filter for the dialog (string) 222 @param directory working directory of the dialog
166 @param options various options for the dialog (QFileDialog.Options) 223 @type str
167 @return name of file to be saved and selected filter (string, string) 224 @param filterStr filter string for the dialog
225 @type str
226 @param initialFilter initial filter for the dialog
227 @type str
228 @param options various options for the dialog
229 @type QFileDialog.Options
230 @return name of file to be saved and selected filte
231 @rtype tuple of (str, str)
168 """ 232 """
169 if options is None: 233 if options is None:
170 options = QFileDialog.Option(0) 234 options = QFileDialog.Option(0)
171 if Globals.isLinuxPlatform(): 235 if Globals.isLinuxPlatform():
172 options |= QFileDialog.Option.DontUseNativeDialog 236 options |= QFileDialog.Option.DontUseNativeDialog
179 directory="", 243 directory="",
180 options=QFileDialog.Option.ShowDirsOnly): 244 options=QFileDialog.Option.ShowDirsOnly):
181 """ 245 """
182 Module function to get the name of a directory. 246 Module function to get the name of a directory.
183 247
184 @param parent parent widget of the dialog (QWidget) 248 @param parent parent widget of the dialog
185 @param caption window title of the dialog (string) 249 @type QWidget
186 @param directory working directory of the dialog (string) 250 @param caption window title of the dialog
187 @param options various options for the dialog (QFileDialog.Options) 251 @type str
188 @return name of selected directory (string) 252 @param directory working directory of the dialog
253 @type str
254 @param options various options for the dialog
255 @type QFileDialog.Options
256 @return name of selected directory
257 @rtype str
189 """ 258 """
190 if options is None: 259 if options is None:
191 options = QFileDialog.Option(0) 260 options = QFileDialog.Option(0)
192 if Globals.isLinuxPlatform(): 261 if Globals.isLinuxPlatform():
193 options |= QFileDialog.Option.DontUseNativeDialog 262 options |= QFileDialog.Option.DontUseNativeDialog

eric ide

mercurial