3 # Copyright (c) 2010 - 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
3 # Copyright (c) 2010 - 2011 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 dustributor'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 PyQt4.QtGui import QFileDialog |
11 from PyQt4.QtGui import QFileDialog |
12 |
12 |
|
13 import Globals |
|
14 |
|
15 ShowDirsOnly = QFileDialog.ShowDirsOnly |
|
16 DontResolveSymlinks = QFileDialog.DontResolveSymlinks |
|
17 DontConfirmOverwrite = QFileDialog.DontConfirmOverwrite |
|
18 DontUseNativeDialog = QFileDialog.DontUseNativeDialog |
|
19 ReadOnly = QFileDialog.ReadOnly |
|
20 HideNameFilterDetails = QFileDialog.HideNameFilterDetails |
|
21 DontUseSheet = QFileDialog.DontUseSheet |
|
22 |
13 def __reorderFilter(filter, initialFilter = ""): |
23 def __reorderFilter(filter, initialFilter = ""): |
14 """ |
24 """ |
15 Private function to reorder the file filter to cope with a KDE issue introduced |
25 Private function to reorder the file filter to cope with a KDE issue |
16 by distributor's usage of KDE file dialogs. |
26 introduced by distributor's usage of KDE file dialogs. |
17 |
27 |
18 @param filter Qt file filter (string) |
28 @param filter Qt file filter (string) |
19 @param initialFilter initial filter (string) |
29 @param initialFilter initial filter (string) |
20 @return the rearranged Qt file filter (string) |
30 @return the rearranged Qt file filter (string) |
21 """ |
31 """ |
25 fileFilters.remove(initialFilter) |
35 fileFilters.remove(initialFilter) |
26 fileFilters.insert(0, initialFilter) |
36 fileFilters.insert(0, initialFilter) |
27 return ";;".join(fileFilters) |
37 return ";;".join(fileFilters) |
28 else: |
38 else: |
29 return filter |
39 return filter |
|
40 |
|
41 def getOpenFileName(parent = None, caption = "", directory = "", |
|
42 filter = "", options = QFileDialog.Options()): |
|
43 """ |
|
44 Module function to get the name of a file for opening it. |
|
45 |
|
46 @param parent parent widget of the dialog (QWidget) |
|
47 @param caption window title of the dialog (string) |
|
48 @param directory working directory of the dialog (string) |
|
49 @param filter filter string for the dialog (string) |
|
50 @param options various options for the dialog (QFileDialog.Options) |
|
51 @return name of file to be opened (string) |
|
52 """ |
|
53 if Globals.isLinuxPlatform(): |
|
54 options |= QFileDialog.DontUseNativeDialog |
|
55 return QFileDialog.getOpenFileName(parent, caption, directory, |
|
56 filter, options) |
30 |
57 |
31 def getOpenFileNameAndFilter(parent = None, caption = "", directory = "", |
58 def getOpenFileNameAndFilter(parent = None, caption = "", directory = "", |
32 filter = "", initialFilter = "", |
59 filter = "", initialFilter = "", |
33 options = QFileDialog.Options()): |
60 options = QFileDialog.Options()): |
34 """ |
61 """ |
41 @param filter filter string for the dialog (string) |
68 @param filter filter string for the dialog (string) |
42 @param initialFilter initial filter for the dialog (string) |
69 @param initialFilter initial filter for the dialog (string) |
43 @param options various options for the dialog (QFileDialog.Options) |
70 @param options various options for the dialog (QFileDialog.Options) |
44 @return name of file to be opened and selected filter (string, string) |
71 @return name of file to be opened and selected filter (string, string) |
45 """ |
72 """ |
|
73 if Globals.isLinuxPlatform(): |
|
74 options |= QFileDialog.DontUseNativeDialog |
46 newfilter = __reorderFilter(filter, initialFilter) |
75 newfilter = __reorderFilter(filter, initialFilter) |
47 return QFileDialog.getOpenFileNameAndFilter(parent, caption, directory, |
76 return QFileDialog.getOpenFileNameAndFilter(parent, caption, directory, |
48 newfilter, initialFilter, options) |
77 newfilter, initialFilter, |
|
78 options) |
|
79 |
|
80 def getOpenFileNames(parent = None, caption = "", directory = "", |
|
81 filter = "", options = QFileDialog.Options()): |
|
82 """ |
|
83 Module function to get a list of names of files for opening. |
|
84 |
|
85 @param parent parent widget of the dialog (QWidget) |
|
86 @param caption window title of the dialog (string) |
|
87 @param directory working directory of the dialog (string) |
|
88 @param filter filter string for the dialog (string) |
|
89 @param options various options for the dialog (QFileDialog.Options) |
|
90 @return list of file names to be opened (list of string) |
|
91 """ |
|
92 if Globals.isLinuxPlatform(): |
|
93 options |= QFileDialog.DontUseNativeDialog |
|
94 return QFileDialog.getOpenFileNames(parent, caption, directory, |
|
95 filter, options) |
49 |
96 |
50 def getOpenFileNamesAndFilter(parent = None, caption = "", directory = "", |
97 def getOpenFileNamesAndFilter(parent = None, caption = "", directory = "", |
51 filter = "", initialFilter = "", |
98 filter = "", initialFilter = "", |
52 options = QFileDialog.Options()): |
99 options = QFileDialog.Options()): |
53 """ |
100 """ |
54 Module function to get a list of names of files for opening and the selected |
101 Module function to get a list of names of files for opening and the |
55 file name filter. |
102 selected file name filter. |
56 |
103 |
57 @param parent parent widget of the dialog (QWidget) |
104 @param parent parent widget of the dialog (QWidget) |
58 @param caption window title of the dialog (string) |
105 @param caption window title of the dialog (string) |
59 @param directory working directory of the dialog (string) |
106 @param directory working directory of the dialog (string) |
60 @param filter filter string for the dialog (string) |
107 @param filter filter string for the dialog (string) |
61 @param initialFilter initial filter for the dialog (string) |
108 @param initialFilter initial filter for the dialog (string) |
62 @param options various options for the dialog (QFileDialog.Options) |
109 @param options various options for the dialog (QFileDialog.Options) |
63 @return list of file names to be opened and selected filter |
110 @return list of file names to be opened and selected filter |
64 (list of string, string) |
111 (list of string, string) |
65 """ |
112 """ |
|
113 if Globals.isLinuxPlatform(): |
|
114 options |= QFileDialog.DontUseNativeDialog |
66 newfilter = __reorderFilter(filter, initialFilter) |
115 newfilter = __reorderFilter(filter, initialFilter) |
67 return QFileDialog.getOpenFileNamesAndFilter(parent, caption, directory, |
116 return QFileDialog.getOpenFileNamesAndFilter(parent, caption, directory, |
68 newfilter, initialFilter, options) |
117 newfilter, initialFilter, |
|
118 options) |
|
119 |
|
120 def getSaveFileName(parent = None, caption = "", directory = "", |
|
121 filter = "", options = QFileDialog.Options()): |
|
122 """ |
|
123 Module function to get the name of a file for saving it. |
|
124 |
|
125 @param parent parent widget of the dialog (QWidget) |
|
126 @param caption window title of the dialog (string) |
|
127 @param directory working directory of the dialog (string) |
|
128 @param filter filter string for the dialog (string) |
|
129 @param options various options for the dialog (QFileDialog.Options) |
|
130 @return name of file to be saved (string) |
|
131 """ |
|
132 if Globals.isLinuxPlatform(): |
|
133 options |= QFileDialog.DontUseNativeDialog |
|
134 return QFileDialog.getSaveFileName(parent, caption, directory, |
|
135 filter, options) |
69 |
136 |
70 def getSaveFileNameAndFilter(parent = None, caption = "", directory = "", |
137 def getSaveFileNameAndFilter(parent = None, caption = "", directory = "", |
71 filter = "", initialFilter = "", |
138 filter = "", initialFilter = "", |
72 options = QFileDialog.Options()): |
139 options = QFileDialog.Options()): |
73 """ |
140 """ |
80 @param filter filter string for the dialog (string) |
147 @param filter filter string for the dialog (string) |
81 @param initialFilter initial filter for the dialog (string) |
148 @param initialFilter initial filter for the dialog (string) |
82 @param options various options for the dialog (QFileDialog.Options) |
149 @param options various options for the dialog (QFileDialog.Options) |
83 @return name of file to be saved and selected filter (string, string) |
150 @return name of file to be saved and selected filter (string, string) |
84 """ |
151 """ |
|
152 if Globals.isLinuxPlatform(): |
|
153 options |= QFileDialog.DontUseNativeDialog |
85 newfilter = __reorderFilter(filter, initialFilter) |
154 newfilter = __reorderFilter(filter, initialFilter) |
86 return QFileDialog.getSaveFileNameAndFilter(parent, caption, directory, |
155 return QFileDialog.getSaveFileNameAndFilter(parent, caption, directory, |
87 newfilter, initialFilter, options) |
156 newfilter, initialFilter, |
|
157 options) |
|
158 |
|
159 def getExistingDirectory(parent = None, caption = "", |
|
160 directory = "", options = QFileDialog.ShowDirsOnly): |
|
161 """ |
|
162 Module function to get the name of a directory. |
|
163 |
|
164 @param parent parent widget of the dialog (QWidget) |
|
165 @param caption window title of the dialog (string) |
|
166 @param directory working directory of the dialog (string) |
|
167 @param options various options for the dialog (QFileDialog.Options) |
|
168 @return name of selected directory (string) |
|
169 """ |
|
170 if Globals.isLinuxPlatform(): |
|
171 options |= QFileDialog.DontUseNativeDialog |
|
172 return QFileDialog.getExistingDirectory(parent, caption, directory, |
|
173 options) |