18 |
18 |
19 class EricFileCompleter(QCompleter): |
19 class EricFileCompleter(QCompleter): |
20 """ |
20 """ |
21 Class implementing a completer for file names. |
21 Class implementing a completer for file names. |
22 """ |
22 """ |
23 def __init__(self, parent=None, |
23 |
24 completionMode=QCompleter.CompletionMode.PopupCompletion, |
24 def __init__( |
25 showHidden=False): |
25 self, |
|
26 parent=None, |
|
27 completionMode=QCompleter.CompletionMode.PopupCompletion, |
|
28 showHidden=False, |
|
29 ): |
26 """ |
30 """ |
27 Constructor |
31 Constructor |
28 |
32 |
29 @param parent parent widget of the completer (QWidget) |
33 @param parent parent widget of the completer (QWidget) |
30 @param completionMode completion mode of the |
34 @param completionMode completion mode of the |
31 completer (QCompleter.CompletionMode) |
35 completer (QCompleter.CompletionMode) |
32 @param showHidden flag indicating to show hidden entries as well |
36 @param showHidden flag indicating to show hidden entries as well |
33 (boolean) |
37 (boolean) |
34 """ |
38 """ |
35 super().__init__(parent) |
39 super().__init__(parent) |
36 self.__model = QFileSystemModel(self) |
40 self.__model = QFileSystemModel(self) |
37 if showHidden: |
41 if showHidden: |
38 self.__model.setFilter( |
42 self.__model.setFilter( |
39 QDir.Filter.Dirs | |
43 QDir.Filter.Dirs |
40 QDir.Filter.Files | |
44 | QDir.Filter.Files |
41 QDir.Filter.Drives | |
45 | QDir.Filter.Drives |
42 QDir.Filter.AllDirs | |
46 | QDir.Filter.AllDirs |
43 QDir.Filter.Hidden) |
47 | QDir.Filter.Hidden |
|
48 ) |
44 else: |
49 else: |
45 self.__model.setFilter( |
50 self.__model.setFilter( |
46 QDir.Filter.Dirs | |
51 QDir.Filter.Dirs |
47 QDir.Filter.Files | |
52 | QDir.Filter.Files |
48 QDir.Filter.Drives | |
53 | QDir.Filter.Drives |
49 QDir.Filter.AllDirs) |
54 | QDir.Filter.AllDirs |
|
55 ) |
50 self.__model.setRootPath("") |
56 self.__model.setRootPath("") |
51 self.setModel(self.__model) |
57 self.setModel(self.__model) |
52 self.setCompletionMode(completionMode) |
58 self.setCompletionMode(completionMode) |
53 if isWindowsPlatform(): |
59 if isWindowsPlatform(): |
54 self.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) |
60 self.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) |
55 if parent: |
61 if parent: |
56 parent.setCompleter(self) |
62 parent.setCompleter(self) |
57 |
63 |
58 def setRootPath(self, path): |
64 def setRootPath(self, path): |
59 """ |
65 """ |
60 Public method to set the root path of the model. |
66 Public method to set the root path of the model. |
61 |
67 |
62 @param path root path for the model |
68 @param path root path for the model |
63 @type str |
69 @type str |
64 """ |
70 """ |
65 if not os.path.isdir(path): |
71 if not os.path.isdir(path): |
66 path = os.path.dirname(path) |
72 path = os.path.dirname(path) |
67 self.__model.setRootPath(path) |
73 self.__model.setRootPath(path) |
68 |
74 |
69 def rootPath(self): |
75 def rootPath(self): |
70 """ |
76 """ |
71 Public method to get the root path of the model. |
77 Public method to get the root path of the model. |
72 |
78 |
73 @return root path of the model |
79 @return root path of the model |
74 @rtype str |
80 @rtype str |
75 """ |
81 """ |
76 return self.__model.rootPath() |
82 return self.__model.rootPath() |
77 |
83 |
78 |
84 |
79 class EricDirCompleter(QCompleter): |
85 class EricDirCompleter(QCompleter): |
80 """ |
86 """ |
81 Class implementing a completer for directory names. |
87 Class implementing a completer for directory names. |
82 """ |
88 """ |
83 def __init__(self, parent=None, |
89 |
84 completionMode=QCompleter.CompletionMode.PopupCompletion, |
90 def __init__( |
85 showHidden=False): |
91 self, |
|
92 parent=None, |
|
93 completionMode=QCompleter.CompletionMode.PopupCompletion, |
|
94 showHidden=False, |
|
95 ): |
86 """ |
96 """ |
87 Constructor |
97 Constructor |
88 |
98 |
89 @param parent parent widget of the completer (QWidget) |
99 @param parent parent widget of the completer (QWidget) |
90 @param completionMode completion mode of the |
100 @param completionMode completion mode of the |
91 completer (QCompleter.CompletionMode) |
101 completer (QCompleter.CompletionMode) |
92 @param showHidden flag indicating to show hidden entries as well |
102 @param showHidden flag indicating to show hidden entries as well |
93 (boolean) |
103 (boolean) |
94 """ |
104 """ |
95 super().__init__(parent) |
105 super().__init__(parent) |
96 self.__model = QFileSystemModel(self) |
106 self.__model = QFileSystemModel(self) |
97 if showHidden: |
107 if showHidden: |
98 self.__model.setFilter( |
108 self.__model.setFilter( |
99 QDir.Filter.Drives | |
109 QDir.Filter.Drives | QDir.Filter.AllDirs | QDir.Filter.Hidden |
100 QDir.Filter.AllDirs | |
110 ) |
101 QDir.Filter.Hidden) |
|
102 else: |
111 else: |
103 self.__model.setFilter( |
112 self.__model.setFilter(QDir.Filter.Drives | QDir.Filter.AllDirs) |
104 QDir.Filter.Drives | QDir.Filter.AllDirs) |
|
105 self.__model.setRootPath("") |
113 self.__model.setRootPath("") |
106 self.setModel(self.__model) |
114 self.setModel(self.__model) |
107 self.setCompletionMode(completionMode) |
115 self.setCompletionMode(completionMode) |
108 if isWindowsPlatform(): |
116 if isWindowsPlatform(): |
109 self.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) |
117 self.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) |
110 if parent: |
118 if parent: |
111 parent.setCompleter(self) |
119 parent.setCompleter(self) |
112 |
120 |
113 def setRootPath(self, path): |
121 def setRootPath(self, path): |
114 """ |
122 """ |
115 Public method to set the root path of the model. |
123 Public method to set the root path of the model. |
116 |
124 |
117 @param path root path for the model |
125 @param path root path for the model |
118 @type str |
126 @type str |
119 """ |
127 """ |
120 if not os.path.isdir(path): |
128 if not os.path.isdir(path): |
121 path = os.path.dirname(path) |
129 path = os.path.dirname(path) |
122 self.__model.setRootPath(path) |
130 self.__model.setRootPath(path) |
123 |
131 |
124 def rootPath(self): |
132 def rootPath(self): |
125 """ |
133 """ |
126 Public method to get the root path of the model. |
134 Public method to get the root path of the model. |
127 |
135 |
128 @return root path of the model |
136 @return root path of the model |
129 @rtype str |
137 @rtype str |
130 """ |
138 """ |
131 return self.__model.rootPath() |
139 return self.__model.rootPath() |
132 |
140 |
133 |
141 |
134 class EricStringListCompleter(QCompleter): |
142 class EricStringListCompleter(QCompleter): |
135 """ |
143 """ |
136 Class implementing a completer for string lists. |
144 Class implementing a completer for string lists. |
137 """ |
145 """ |
138 def __init__(self, parent=None, strings=None, |
146 |
139 completionMode=QCompleter.CompletionMode.PopupCompletion): |
147 def __init__( |
|
148 self, |
|
149 parent=None, |
|
150 strings=None, |
|
151 completionMode=QCompleter.CompletionMode.PopupCompletion, |
|
152 ): |
140 """ |
153 """ |
141 Constructor |
154 Constructor |
142 |
155 |
143 @param parent parent widget of the completer (QWidget) |
156 @param parent parent widget of the completer (QWidget) |
144 @param strings list of string to load into the completer |
157 @param strings list of string to load into the completer |
145 (list of strings) |
158 (list of strings) |
146 @param completionMode completion mode of the |
159 @param completionMode completion mode of the |
147 completer (QCompleter.CompletionMode) |
160 completer (QCompleter.CompletionMode) |
148 """ |
161 """ |
149 super().__init__(parent) |
162 super().__init__(parent) |
150 self.__model = QStringListModel( |
163 self.__model = QStringListModel([] if strings is None else strings[:], parent) |
151 [] if strings is None else strings[:], |
|
152 parent) |
|
153 self.setModel(self.__model) |
164 self.setModel(self.__model) |
154 self.setCompletionMode(completionMode) |
165 self.setCompletionMode(completionMode) |
155 if parent: |
166 if parent: |
156 parent.setCompleter(self) |
167 parent.setCompleter(self) |