1
2 """Contains ui modules to build a finder-like browser for items of any kind"""
3 __docformat__ = "restructuredtext"
4
5 from interface import (iFinderProvider, iFinderFilter)
6
7 import mrv.maya.ui as ui
8 from mrv.maya.util import (OptionVarDict, logException )
9 from util import concat_url
10
11 from mrv.path import Path
12 opts = OptionVarDict()
13
14 __all__ = ( 'FileProvider', 'BookmarkControl',
15 'FilePathControl', 'FileFilterControl', 'FinderElement',
16 'FileStack', 'FileRootSelectorControl', 'FilePathControlEditable')
23 """Implements a provider for a file system"""
24 __slots__ = "_root"
25
29
32
52
56 """stack base implementation. A stack keeps multiple items which can be added
57 and removed. Additionally, it allows to remap the items, effectively showing
58 a formatted item, which is kept in sync with an unformatted item.
59 :note: for now, only adding items, format will be applied. All other methods
60 operate on the formatted items."""
61
62
67
68
69
73
80
90
91
92
93
94
96 """Remove the given formatted item from the list, as well as the corresponding
97 unformtted item. Its not an error if the item does not exist"""
98 try:
99 index = self.items().index(item)
100 del(self.base_items[index])
101 super(StackControlBase, self).removeItem(item)
102 except (ValueError, IndexError):
103 pass
104
105 return self
106
110
115 """Element with special abilities to suite the finder better. This involves
116 keeping a list of unformatted items which can be used as unique item identifiers.
117
118 Set the items to a list of unique identifiers which represent the possibly different
119 items actually present in the list."""
120
123 """Implements a stack which shows only the base names of files"""
124
125
126
129
134 """Control displaying a relative url. If it is ediable, a filepath may be
135 entered and queried"""
136
137
139 """:return: string representing the currently active path"""
140 return self.p_text
141
143 """Set the control to display the given path"""
144 if path is None:
145 path = ''
146 self.p_text = str(path)
147
149 self.p_editable = state
150
152 """:return: True if the control can be edited by the user"""
153 return self.p_editable
154
158 """A filepath control which tries to maintain changes applied by the user.
159 It assumes that the system will use setPath to adjust the path, and checks
160 for changes in the path string which will be reapplied to the newly set path
161 if possible"""
162
166
175
178 """Control allowing to display a set of custom bookmarks, which are stored
179 in optionVars"""
180
181
182
183 k_bookmark_store = "MRV_bookmarks"
184
185
186
187
188 bookmark_changed = ui.Signal()
189
190
197
211
213 """:return: list of tuples of root,path pairs"""
214 miter = iter(opts.get(self.k_bookmark_store, list()))
215 return [item for item in zip(miter, miter)]
216
218 """Store a list of pairs"""
219 flattened_list = list()
220 for pair in items:
221 flattened_list.extend(pair)
222
223 opts[self.k_bookmark_store] = flattened_list
224
226 """Store the given path under the given root
227 :param add: if True, the path will be added to the bookmarks of the given
228 root, otherwise it will be removed"""
229 items = self._unpack_stored_bookmarks()
230 index_to_remove = None
231 for index, (oroot, opath) in enumerate(items):
232 if oroot == root and opath == path:
233 if add:
234 return
235 else:
236 index_to_remove = index
237 break
238
239
240
241
242 if add:
243 items.append((root, path))
244 else:
245 if index_to_remove is None:
246 return
247
248 del(items[index_to_remove])
249
250
251 self._store_item_list(items)
252
253 @logException
262
263
269
270
271
284
285
287 """Set this control to a list of bookmarks
288 :param bookmarks: list of either tuples of (root, path) pairs or absolute paths
289 whose root will be chosen automatically"""
290 bms = list()
291 self.base_items = list()
292 for item in bookmarks:
293 self.base_items.append(self._parse_bookmark(item))
294 bms.append(self.formatItem(self.base_items[-1]))
295
296 super(BookmarkControl, self).setItems(bms)
297
298
299 del(opts[self.k_bookmark_store])
300 self._store_item_list(self.base_items)
301
303 """Remove the given bookmark from the list of bookmarks
304 :param bookmark: full path to the bookmark to remove. Its not an error
305 if it doesn't exist in the first place"""
306 items = self.items()
307 try:
308 index = self.items().index(bookmark)
309 root, path = self.base_items[index]
310 super(BookmarkControl, self).removeItem(bookmark)
311 self._store_bookmark(root, path, add=False)
312 except (ValueError, IndexError):
313 return
314
318 """Keeps a list of possible roots which can be chosen. Each root is represented
319 by a Provider instance."""
320
321
322
323 root_changed = ui.Signal()
324
325
329
331 """:return: provider instance having the given root, or None"""
332 for p in self._providers:
333 if p.root() == root:
334 return p
335
336
337 return None
338
349
354
372
373
382
383
384
385
387 """:return: list of currently used providers"""
388 return list(self._providers)
389
390
391
392
393
397
404 """Control providing a filter for finder urls which are file paths"""
405
406
407
408
409
410