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. |
8 to cope with distributor's usage of KDE wrapper dialogs for Qt file dialogs. |
9 """ |
9 """ |
10 |
10 |
11 from PyQt5.QtWidgets import QFileDialog |
11 from PyQt6.QtWidgets import QFileDialog |
12 |
12 |
13 import Globals |
13 import Globals |
14 |
14 |
15 Options = QFileDialog.Options |
15 ##Options = QFileDialog.Options |
16 Option = QFileDialog.Option |
16 Option = QFileDialog.Option |
17 |
17 |
18 ShowDirsOnly = QFileDialog.Option.ShowDirsOnly |
18 ShowDirsOnly = QFileDialog.Option.ShowDirsOnly |
19 DontResolveSymlinks = QFileDialog.Option.DontResolveSymlinks |
19 DontResolveSymlinks = QFileDialog.Option.DontResolveSymlinks |
20 DontConfirmOverwrite = QFileDialog.Option.DontConfirmOverwrite |
20 DontConfirmOverwrite = QFileDialog.Option.DontConfirmOverwrite |
21 DontUseNativeDialog = QFileDialog.Option.DontUseNativeDialog |
21 DontUseNativeDialog = QFileDialog.Option.DontUseNativeDialog |
22 ReadOnly = QFileDialog.Option.ReadOnly |
22 ReadOnly = QFileDialog.Option.ReadOnly |
23 HideNameFilterDetails = QFileDialog.Option.HideNameFilterDetails |
23 HideNameFilterDetails = QFileDialog.Option.HideNameFilterDetails |
24 DontUseSheet = QFileDialog.Option.DontUseSheet |
24 ##DontUseSheet = QFileDialog.Option.DontUseSheet |
25 DontUseCustomDirectoryIcons = QFileDialog.Option.DontUseCustomDirectoryIcons |
25 DontUseCustomDirectoryIcons = QFileDialog.Option.DontUseCustomDirectoryIcons |
26 |
26 |
27 |
27 |
28 def __reorderFilter(filterStr, initialFilter=""): |
28 def __reorderFilter(filterStr, initialFilter=""): |
29 """ |
29 """ |
54 @param directory working directory of the dialog (string) |
54 @param directory working directory of the dialog (string) |
55 @param filterStr filter string for the dialog (string) |
55 @param filterStr filter string for the dialog (string) |
56 @param options various options for the dialog (QFileDialog.Options) |
56 @param options various options for the dialog (QFileDialog.Options) |
57 @return name of file to be opened (string) |
57 @return name of file to be opened (string) |
58 """ |
58 """ |
59 if options is None: |
59 ## if options is None: |
60 options = QFileDialog.Options() |
60 ## options = QFileDialog.Options() |
61 if Globals.isLinuxPlatform(): |
61 if Globals.isLinuxPlatform(): |
62 options |= QFileDialog.Option.DontUseNativeDialog |
62 if options is None: |
|
63 options = QFileDialog.Option.DontUseNativeDialog |
|
64 else: |
|
65 options |= QFileDialog.Option.DontUseNativeDialog |
63 return QFileDialog.getOpenFileName( |
66 return QFileDialog.getOpenFileName( |
64 parent, caption, directory, filterStr, "", options)[0] |
67 parent, caption, directory, filterStr, "", options)[0] |
65 |
68 |
66 |
69 |
67 def getOpenFileNameAndFilter(parent=None, caption="", directory="", |
70 def getOpenFileNameAndFilter(parent=None, caption="", directory="", |
77 @param filterStr filter string for the dialog (string) |
80 @param filterStr filter string for the dialog (string) |
78 @param initialFilter initial filter for the dialog (string) |
81 @param initialFilter initial filter for the dialog (string) |
79 @param options various options for the dialog (QFileDialog.Options) |
82 @param options various options for the dialog (QFileDialog.Options) |
80 @return name of file to be opened and selected filter (string, string) |
83 @return name of file to be opened and selected filter (string, string) |
81 """ |
84 """ |
82 if options is None: |
85 ## if options is None: |
83 options = QFileDialog.Options() |
86 ## options = QFileDialog.Options() |
84 if Globals.isLinuxPlatform(): |
87 if Globals.isLinuxPlatform(): |
85 options |= QFileDialog.Option.DontUseNativeDialog |
88 if options is None: |
|
89 options = QFileDialog.Option.DontUseNativeDialog |
|
90 else: |
|
91 options |= QFileDialog.Option.DontUseNativeDialog |
86 newfilter = __reorderFilter(filterStr, initialFilter) |
92 newfilter = __reorderFilter(filterStr, initialFilter) |
87 return QFileDialog.getOpenFileName( |
93 return QFileDialog.getOpenFileName( |
88 parent, caption, directory, newfilter, initialFilter, options) |
94 parent, caption, directory, newfilter, initialFilter, options) |
89 |
95 |
90 |
96 |
98 @param directory working directory of the dialog (string) |
104 @param directory working directory of the dialog (string) |
99 @param filterStr filter string for the dialog (string) |
105 @param filterStr filter string for the dialog (string) |
100 @param options various options for the dialog (QFileDialog.Options) |
106 @param options various options for the dialog (QFileDialog.Options) |
101 @return list of file names to be opened (list of string) |
107 @return list of file names to be opened (list of string) |
102 """ |
108 """ |
103 if options is None: |
109 ## if options is None: |
104 options = QFileDialog.Options() |
110 ## options = QFileDialog.Options() |
105 if Globals.isLinuxPlatform(): |
111 if Globals.isLinuxPlatform(): |
106 options |= QFileDialog.Option.DontUseNativeDialog |
112 if options is None: |
|
113 options = QFileDialog.Option.DontUseNativeDialog |
|
114 else: |
|
115 options |= QFileDialog.Option.DontUseNativeDialog |
107 return QFileDialog.getOpenFileNames( |
116 return QFileDialog.getOpenFileNames( |
108 parent, caption, directory, filterStr, "", options)[0] |
117 parent, caption, directory, filterStr, "", options)[0] |
109 |
118 |
110 |
119 |
111 def getOpenFileNamesAndFilter(parent=None, caption="", directory="", |
120 def getOpenFileNamesAndFilter(parent=None, caption="", directory="", |
122 @param initialFilter initial filter for the dialog (string) |
131 @param initialFilter initial filter for the dialog (string) |
123 @param options various options for the dialog (QFileDialog.Options) |
132 @param options various options for the dialog (QFileDialog.Options) |
124 @return list of file names to be opened and selected filter |
133 @return list of file names to be opened and selected filter |
125 (list of string, string) |
134 (list of string, string) |
126 """ |
135 """ |
127 if options is None: |
136 ## if options is None: |
128 options = QFileDialog.Options() |
137 ## options = QFileDialog.Options() |
129 if Globals.isLinuxPlatform(): |
138 if Globals.isLinuxPlatform(): |
130 options |= QFileDialog.Option.DontUseNativeDialog |
139 if options is None: |
|
140 options = QFileDialog.Option.DontUseNativeDialog |
|
141 else: |
|
142 options |= QFileDialog.Option.DontUseNativeDialog |
131 newfilter = __reorderFilter(filterStr, initialFilter) |
143 newfilter = __reorderFilter(filterStr, initialFilter) |
132 return QFileDialog.getOpenFileNames( |
144 return QFileDialog.getOpenFileNames( |
133 parent, caption, directory, newfilter, initialFilter, options) |
145 parent, caption, directory, newfilter, initialFilter, options) |
134 |
146 |
135 |
147 |
143 @param directory working directory of the dialog (string) |
155 @param directory working directory of the dialog (string) |
144 @param filterStr filter string for the dialog (string) |
156 @param filterStr filter string for the dialog (string) |
145 @param options various options for the dialog (QFileDialog.Options) |
157 @param options various options for the dialog (QFileDialog.Options) |
146 @return name of file to be saved (string) |
158 @return name of file to be saved (string) |
147 """ |
159 """ |
148 if options is None: |
160 ## if options is None: |
149 options = QFileDialog.Options() |
161 ## options = QFileDialog.Options() |
150 if Globals.isLinuxPlatform(): |
162 if Globals.isLinuxPlatform(): |
151 options |= QFileDialog.Option.DontUseNativeDialog |
163 if options is None: |
|
164 options = QFileDialog.Option.DontUseNativeDialog |
|
165 else: |
|
166 options |= QFileDialog.Option.DontUseNativeDialog |
152 return QFileDialog.getSaveFileName( |
167 return QFileDialog.getSaveFileName( |
153 parent, caption, directory, filterStr, "", options)[0] |
168 parent, caption, directory, filterStr, "", options)[0] |
154 |
169 |
155 |
170 |
156 def getSaveFileNameAndFilter(parent=None, caption="", directory="", |
171 def getSaveFileNameAndFilter(parent=None, caption="", directory="", |
166 @param filterStr filter string for the dialog (string) |
181 @param filterStr filter string for the dialog (string) |
167 @param initialFilter initial filter for the dialog (string) |
182 @param initialFilter initial filter for the dialog (string) |
168 @param options various options for the dialog (QFileDialog.Options) |
183 @param options various options for the dialog (QFileDialog.Options) |
169 @return name of file to be saved and selected filter (string, string) |
184 @return name of file to be saved and selected filter (string, string) |
170 """ |
185 """ |
171 if options is None: |
186 ## if options is None: |
172 options = QFileDialog.Options() |
187 ## options = QFileDialog.Options() |
173 if Globals.isLinuxPlatform(): |
188 if Globals.isLinuxPlatform(): |
174 options |= QFileDialog.Option.DontUseNativeDialog |
189 if options is None: |
|
190 options = QFileDialog.Option.DontUseNativeDialog |
|
191 else: |
|
192 options |= QFileDialog.Option.DontUseNativeDialog |
175 newfilter = __reorderFilter(filterStr, initialFilter) |
193 newfilter = __reorderFilter(filterStr, initialFilter) |
176 return QFileDialog.getSaveFileName( |
194 return QFileDialog.getSaveFileName( |
177 parent, caption, directory, newfilter, initialFilter, options) |
195 parent, caption, directory, newfilter, initialFilter, options) |
178 |
196 |
179 |
197 |