2
"""module with interfaces to define contracts"""
3
__docformat__ = "restructuredtext"
4
from mrv.interface import Interface
6
__all__ = ('iFinderProvider', 'iOptions', 'iFinderFilter')
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.
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.
16
The base implementation of the memorization feature already. """
18
__slots__ = '_mem_items'
21
# if True, items of urls will be memorized, if False, this information
23
memorize_urlItems = True
26
def __init__(self, root):
28
self._mem_items = dict()
32
def urlItems(self, url):
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")
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
47
:param url_index: index representing the position of the url_item within the
49
:param url_item: item which is to be formatted.
50
:return: string representing the formatted url."""
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
58
:param url_item: the string item to store at the given index"""
59
if not self.memorize_urlItems:
61
# END ignore store call
62
self._mem_items[url_index] = url_item
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)
70
""":return: string representing the file root"""
75
class iFinderFilter(Interface):
76
"""Filter interface suitable to perform item filter operations for Finder controls"""
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"""
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