25 ReadOnly = QFileDialog.ReadOnly |
25 ReadOnly = QFileDialog.ReadOnly |
26 HideNameFilterDetails = QFileDialog.HideNameFilterDetails |
26 HideNameFilterDetails = QFileDialog.HideNameFilterDetails |
27 DontUseSheet = QFileDialog.DontUseSheet |
27 DontUseSheet = QFileDialog.DontUseSheet |
28 |
28 |
29 |
29 |
30 def __reorderFilter(filter, initialFilter=""): |
30 def __reorderFilter(filterStr, initialFilter=""): |
31 """ |
31 """ |
32 Private function to reorder the file filter to cope with a KDE issue |
32 Private function to reorder the file filter to cope with a KDE issue |
33 introduced by distributor's usage of KDE file dialogs. |
33 introduced by distributor's usage of KDE file dialogs. |
34 |
34 |
35 @param filter Qt file filter (string) |
35 @param filterStr Qt file filter (string) |
36 @param initialFilter initial filter (string) |
36 @param initialFilter initial filter (string) |
37 @return the rearranged Qt file filter (string) |
37 @return the rearranged Qt file filter (string) |
38 """ |
38 """ |
39 if initialFilter and not Globals.isMacPlatform(): |
39 if initialFilter and not Globals.isMacPlatform(): |
40 fileFilters = filter.split(';;') |
40 fileFilters = filterStr.split(';;') |
41 if len(fileFilters) < 10 and initialFilter in fileFilters: |
41 if len(fileFilters) < 10 and initialFilter in fileFilters: |
42 fileFilters.remove(initialFilter) |
42 fileFilters.remove(initialFilter) |
43 fileFilters.insert(0, initialFilter) |
43 fileFilters.insert(0, initialFilter) |
44 return ";;".join(fileFilters) |
44 return ";;".join(fileFilters) |
45 else: |
45 else: |
46 return filter |
46 return filterStr |
47 |
47 |
48 |
48 |
49 def getOpenFileName(parent=None, caption="", directory="", |
49 def getOpenFileName(parent=None, caption="", directory="", |
50 filter="", options=QFileDialog.Options()): |
50 filterStr="", options=QFileDialog.Options()): |
51 """ |
51 """ |
52 Module function to get the name of a file for opening it. |
52 Module function to get the name of a file for opening it. |
53 |
53 |
54 @param parent parent widget of the dialog (QWidget) |
54 @param parent parent widget of the dialog (QWidget) |
55 @param caption window title of the dialog (string) |
55 @param caption window title of the dialog (string) |
56 @param directory working directory of the dialog (string) |
56 @param directory working directory of the dialog (string) |
57 @param filter filter string for the dialog (string) |
57 @param filterStr filter string for the dialog (string) |
58 @param options various options for the dialog (QFileDialog.Options) |
58 @param options various options for the dialog (QFileDialog.Options) |
59 @return name of file to be opened (string) |
59 @return name of file to be opened (string) |
60 """ |
60 """ |
61 if Globals.isLinuxPlatform(): |
61 if Globals.isLinuxPlatform(): |
62 options |= QFileDialog.DontUseNativeDialog |
62 options |= QFileDialog.DontUseNativeDialog |
63 if PYQT_VERSION_STR >= "5.0.0": |
63 if PYQT_VERSION_STR >= "5.0.0": |
64 return QFileDialog.getOpenFileName( |
64 return QFileDialog.getOpenFileName( |
65 parent, caption, directory, filter, "", options)[0] |
65 parent, caption, directory, filterStr, "", options)[0] |
66 else: |
66 else: |
67 return QFileDialog.getOpenFileName( |
67 return QFileDialog.getOpenFileName( |
68 parent, caption, directory, filter, options) |
68 parent, caption, directory, filterStr, options) |
69 |
69 |
70 |
70 |
71 def getOpenFileNameAndFilter(parent=None, caption="", directory="", |
71 def getOpenFileNameAndFilter(parent=None, caption="", directory="", |
72 filter="", initialFilter="", |
72 filterStr="", initialFilter="", |
73 options=QFileDialog.Options()): |
73 options=QFileDialog.Options()): |
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 (QWidget) |
78 @param parent parent widget of the dialog (QWidget) |
79 @param caption window title of the dialog (string) |
79 @param caption window title of the dialog (string) |
80 @param directory working directory of the dialog (string) |
80 @param directory working directory of the dialog (string) |
81 @param filter filter string for the dialog (string) |
81 @param filterStr filter string for the dialog (string) |
82 @param initialFilter initial filter for the dialog (string) |
82 @param initialFilter initial filter for the dialog (string) |
83 @param options various options for the dialog (QFileDialog.Options) |
83 @param options various options for the dialog (QFileDialog.Options) |
84 @return name of file to be opened and selected filter (string, string) |
84 @return name of file to be opened and selected filter (string, string) |
85 """ |
85 """ |
86 if Globals.isLinuxPlatform(): |
86 if Globals.isLinuxPlatform(): |
87 options |= QFileDialog.DontUseNativeDialog |
87 options |= QFileDialog.DontUseNativeDialog |
88 newfilter = __reorderFilter(filter, initialFilter) |
88 newfilter = __reorderFilter(filterStr, initialFilter) |
89 if PYQT_VERSION_STR >= "5.0.0": |
89 if PYQT_VERSION_STR >= "5.0.0": |
90 return QFileDialog.getOpenFileName( |
90 return QFileDialog.getOpenFileName( |
91 parent, caption, directory, newfilter, initialFilter, options) |
91 parent, caption, directory, newfilter, initialFilter, options) |
92 else: |
92 else: |
93 return QFileDialog.getOpenFileNameAndFilter( |
93 return QFileDialog.getOpenFileNameAndFilter( |
94 parent, caption, directory, newfilter, initialFilter, options) |
94 parent, caption, directory, newfilter, initialFilter, options) |
95 |
95 |
96 |
96 |
97 def getOpenFileNames(parent=None, caption="", directory="", |
97 def getOpenFileNames(parent=None, caption="", directory="", |
98 filter="", options=QFileDialog.Options()): |
98 filterStr="", options=QFileDialog.Options()): |
99 """ |
99 """ |
100 Module function to get a list of names of files for opening. |
100 Module function to get a list of names of files for opening. |
101 |
101 |
102 @param parent parent widget of the dialog (QWidget) |
102 @param parent parent widget of the dialog (QWidget) |
103 @param caption window title of the dialog (string) |
103 @param caption window title of the dialog (string) |
104 @param directory working directory of the dialog (string) |
104 @param directory working directory of the dialog (string) |
105 @param filter filter string for the dialog (string) |
105 @param filterStr filter string for the dialog (string) |
106 @param options various options for the dialog (QFileDialog.Options) |
106 @param options various options for the dialog (QFileDialog.Options) |
107 @return list of file names to be opened (list of string) |
107 @return list of file names to be opened (list of string) |
108 """ |
108 """ |
109 if Globals.isLinuxPlatform(): |
109 if Globals.isLinuxPlatform(): |
110 options |= QFileDialog.DontUseNativeDialog |
110 options |= QFileDialog.DontUseNativeDialog |
111 if PYQT_VERSION_STR >= "5.0.0": |
111 if PYQT_VERSION_STR >= "5.0.0": |
112 return QFileDialog.getOpenFileNames( |
112 return QFileDialog.getOpenFileNames( |
113 parent, caption, directory, filter, "", options)[0] |
113 parent, caption, directory, filterStr, "", options)[0] |
114 else: |
114 else: |
115 return QFileDialog.getOpenFileNames( |
115 return QFileDialog.getOpenFileNames( |
116 parent, caption, directory, filter, options) |
116 parent, caption, directory, filterStr, options) |
117 |
117 |
118 |
118 |
119 def getOpenFileNamesAndFilter(parent=None, caption="", directory="", |
119 def getOpenFileNamesAndFilter(parent=None, caption="", directory="", |
120 filter="", initialFilter="", |
120 filterStr="", initialFilter="", |
121 options=QFileDialog.Options()): |
121 options=QFileDialog.Options()): |
122 """ |
122 """ |
123 Module function to get a list of names of files for opening and the |
123 Module function to get a list of names of files for opening and the |
124 selected file name filter. |
124 selected file name filter. |
125 |
125 |
126 @param parent parent widget of the dialog (QWidget) |
126 @param parent parent widget of the dialog (QWidget) |
127 @param caption window title of the dialog (string) |
127 @param caption window title of the dialog (string) |
128 @param directory working directory of the dialog (string) |
128 @param directory working directory of the dialog (string) |
129 @param filter filter string for the dialog (string) |
129 @param filterStr filter string for the dialog (string) |
130 @param initialFilter initial filter for the dialog (string) |
130 @param initialFilter initial filter for the dialog (string) |
131 @param options various options for the dialog (QFileDialog.Options) |
131 @param options various options for the dialog (QFileDialog.Options) |
132 @return list of file names to be opened and selected filter |
132 @return list of file names to be opened and selected filter |
133 (list of string, string) |
133 (list of string, string) |
134 """ |
134 """ |
135 if Globals.isLinuxPlatform(): |
135 if Globals.isLinuxPlatform(): |
136 options |= QFileDialog.DontUseNativeDialog |
136 options |= QFileDialog.DontUseNativeDialog |
137 newfilter = __reorderFilter(filter, initialFilter) |
137 newfilter = __reorderFilter(filterStr, initialFilter) |
138 if PYQT_VERSION_STR >= "5.0.0": |
138 if PYQT_VERSION_STR >= "5.0.0": |
139 return QFileDialog.getOpenFileNames( |
139 return QFileDialog.getOpenFileNames( |
140 parent, caption, directory, newfilter, initialFilter, options) |
140 parent, caption, directory, newfilter, initialFilter, options) |
141 else: |
141 else: |
142 return QFileDialog.getOpenFileNamesAndFilter( |
142 return QFileDialog.getOpenFileNamesAndFilter( |
143 parent, caption, directory, newfilter, initialFilter, options) |
143 parent, caption, directory, newfilter, initialFilter, options) |
144 |
144 |
145 |
145 |
146 def getSaveFileName(parent=None, caption="", directory="", |
146 def getSaveFileName(parent=None, caption="", directory="", |
147 filter="", options=QFileDialog.Options()): |
147 filterStr="", options=QFileDialog.Options()): |
148 """ |
148 """ |
149 Module function to get the name of a file for saving it. |
149 Module function to get the name of a file for saving it. |
150 |
150 |
151 @param parent parent widget of the dialog (QWidget) |
151 @param parent parent widget of the dialog (QWidget) |
152 @param caption window title of the dialog (string) |
152 @param caption window title of the dialog (string) |
153 @param directory working directory of the dialog (string) |
153 @param directory working directory of the dialog (string) |
154 @param filter filter string for the dialog (string) |
154 @param filterStr filter string for the dialog (string) |
155 @param options various options for the dialog (QFileDialog.Options) |
155 @param options various options for the dialog (QFileDialog.Options) |
156 @return name of file to be saved (string) |
156 @return name of file to be saved (string) |
157 """ |
157 """ |
158 if Globals.isLinuxPlatform(): |
158 if Globals.isLinuxPlatform(): |
159 options |= QFileDialog.DontUseNativeDialog |
159 options |= QFileDialog.DontUseNativeDialog |
160 if PYQT_VERSION_STR >= "5.0.0": |
160 if PYQT_VERSION_STR >= "5.0.0": |
161 return QFileDialog.getSaveFileName( |
161 return QFileDialog.getSaveFileName( |
162 parent, caption, directory, filter, "", options)[0] |
162 parent, caption, directory, filterStr, "", options)[0] |
163 else: |
163 else: |
164 return QFileDialog.getSaveFileName( |
164 return QFileDialog.getSaveFileName( |
165 parent, caption, directory, filter, options) |
165 parent, caption, directory, filterStr, options) |
166 |
166 |
167 |
167 |
168 def getSaveFileNameAndFilter(parent=None, caption="", directory="", |
168 def getSaveFileNameAndFilter(parent=None, caption="", directory="", |
169 filter="", initialFilter="", |
169 filterStr="", initialFilter="", |
170 options=QFileDialog.Options()): |
170 options=QFileDialog.Options()): |
171 """ |
171 """ |
172 Module function to get the name of a file for saving it and the selected |
172 Module function to get the name of a file for saving it and the selected |
173 file name filter. |
173 file name filter. |
174 |
174 |
175 @param parent parent widget of the dialog (QWidget) |
175 @param parent parent widget of the dialog (QWidget) |
176 @param caption window title of the dialog (string) |
176 @param caption window title of the dialog (string) |
177 @param directory working directory of the dialog (string) |
177 @param directory working directory of the dialog (string) |
178 @param filter filter string for the dialog (string) |
178 @param filterStr filter string for the dialog (string) |
179 @param initialFilter initial filter for the dialog (string) |
179 @param initialFilter initial filter for the dialog (string) |
180 @param options various options for the dialog (QFileDialog.Options) |
180 @param options various options for the dialog (QFileDialog.Options) |
181 @return name of file to be saved and selected filter (string, string) |
181 @return name of file to be saved and selected filter (string, string) |
182 """ |
182 """ |
183 if Globals.isLinuxPlatform(): |
183 if Globals.isLinuxPlatform(): |
184 options |= QFileDialog.DontUseNativeDialog |
184 options |= QFileDialog.DontUseNativeDialog |
185 newfilter = __reorderFilter(filter, initialFilter) |
185 newfilter = __reorderFilter(filterStr, initialFilter) |
186 if PYQT_VERSION_STR >= "5.0.0": |
186 if PYQT_VERSION_STR >= "5.0.0": |
187 return QFileDialog.getSaveFileName( |
187 return QFileDialog.getSaveFileName( |
188 parent, caption, directory, newfilter, initialFilter, options) |
188 parent, caption, directory, newfilter, initialFilter, options) |
189 else: |
189 else: |
190 return QFileDialog.getSaveFileNameAndFilter( |
190 return QFileDialog.getSaveFileNameAndFilter( |