Package mrv :: Package maya :: Package ui :: Package browse :: Module interface
[hide private]
[frames] | no frames]

Source Code for Module mrv.maya.ui.browse.interface

  1  # -*- coding: utf-8 -*- 
  2  """module with interfaces to define contracts""" 
  3  __docformat__ = "restructuredtext" 
  4  from mrv.interface import Interface 
  5   
  6  __all__ = ('iFinderProvider', 'iOptions', 'iFinderFilter') 
  7   
8 -class iFinderProvider(Interface):
9 """Interface defining the capabilities of a provider to be usable by a Finder 10 control. Every finder as a root, which is used as basis for listing urls. 11 12 Besides its function to provide sub-items for given urls, it is also used 13 to store recently selected items on a given level of a url. This memory 14 allows the finder to restore common portions of URLs accordingly. 15 16 The base implementation of the memorization feature already. """ 17 18 __slots__ = '_mem_items' 19 20 #{ Configuration 21 # if True, items of urls will be memorized, if False, this information 22 # will be discarded 23 memorize_urlItems = True 24 #} END configuration 25
26 - def __init__(self, root):
27 self._root = root 28 self._mem_items = dict()
29 30 #{ Interface 31
32 - def urlItems(self, url):
33 """ 34 :return: list of string-like items which can be found at the given url. 35 If this url is combined with one of the returned items separated by a slash, 36 a valid url is formed, i.e. url/item 37 :param url: A given slash-separated url like base/subitem or '', which 38 requests items at the root of all urls""" 39 raise NotImplementedError("To be implemented by subclass")
40
41 - def formatItem(self, url_base, url_index, url_item):
42 """Given the url_item, as well as additional information such as its base 43 and its index inside of the url, this method encodes the item for presentation 44 in the user interface. 45 :param url_base: relative url at which the url_item resides. Is "" if url_index 46 is 0 47 :param url_index: index representing the position of the url_item within the 48 url 49 :param url_item: item which is to be formatted. 50 :return: string representing the formatted url.""" 51 return url_item
52
53 - def storeUrlItem(self, url_index, url_item):
54 """Stores and associates a given url_index with a url_item. Makes the stored 55 item queryable by the ``storedUrlItemByIndex`` method 56 :param url_index: index from 0 to n, where 0 corresponds to the first item 57 in the url 58 :param url_item: the string item to store at the given index""" 59 if not self.memorize_urlItems: 60 return 61 # END ignore store call 62 self._mem_items[url_index] = url_item
63
64 - def storedUrlItemByIndex(self, url_index):
65 """:return: string item previously stored at the given index, or None 66 if there is no information available""" 67 return self._mem_items.get(url_index, None)
68
69 - def root(self):
70 """:return: string representing the file root""" 71 return self._root
72 73 #} END interface 74
75 -class iFinderFilter(Interface):
76 """Filter interface suitable to perform item filter operations for Finder controls""" 77 78 #{ Interface 79
80 - def filtered(self, finder, element_index, base_url, items):
81 """:return: list of items which may be shown in the element at element_index 82 :param finder: finder instance issueing the call 83 :param element_index: index of the element which is to be filled with items 84 :param base_url: url at which the given items exist 85 :param items: list of relative item ids which are to be shown in the finder element""" 86 return items
87 88 #} END interface 89 90
91 -class iOptions(Interface):
92 """Interface for all custom options layouts to be used with the FinderLayout. 93 They take a weak-reference to their parent FinderLayout allowing them to 94 set themselves up if necessary. 95 The options they represent must be read by a custom implementation of the 96 FinderLayout"""
97 98 #{ Interface 99 100 #} END interface 101