From e4f37e51e91cc45b7660e3572a275c8dae6dbec9 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 2 Aug 2012 04:27:16 +0200 Subject: container.settingobject: fixed type of hidden_filter --- ranger/container/settingobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ranger/container/settingobject.py b/ranger/container/settingobject.py index cbc56278..92af0a95 100644 --- a/ranger/container/settingobject.py +++ b/ranger/container/settingobject.py @@ -19,7 +19,7 @@ ALLOWED_SETTINGS = { 'draw_bookmark_borders': bool, 'draw_borders': bool, 'flushinput': bool, - 'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'), + 'hidden_filter': str, 'init_function': (type(None), type(lambda:0)), 'load_default_rc': (bool, type(None)), 'max_console_history_size': (int, type(None)), -- cgit 1.4.1-2-gfad0 l='branches'> mirror of ranger - a simple, vim-like file managerakspecs <akspecs@tilde.institute>
summary refs log tree commit diff stats
path: root/ranger/ext/direction.py
blob: 3de7e1c3c041e43389f295ef4dfffa275347eb7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

"""This class provides convenient methods for movement operations.

Direction objects are handled just like dicts but provide
methods like up() and down() which give you the correct value
for the vertical direction, even if only the "up" or "down" key
has been defined.


>>> d = Direction(down=5)
>>> d.down()
5
>>> d.up()
-5
>>> bool(d.horizontal())
False
"""


class Direction(dict):

    def __init__(self, dictionary=None, **keywords):
        if dictionary is not None:
            dict.__init__(self, dictionary)
        else:
            dict.__init__(self, keywords)
        if 'to' in self:
            self['down'] = self['to']
            self['absolute'] = True

    def copy(self):
        return Direction(**self)

    def _get_bool(self, first, second, fallback=None):
        try:
            return self[first]
        except Exception:
            try:
                return not self[second]
            except Exception:
                return fallback

    def _get_direction(self, first, second, fallback=0):
        try:
            return self[first]
        except Exception:
            try:
                return -self[second]
            except Exception:
                return fallback

    def up(self):  # pylint: disable=invalid-name
        return -Direction.down(self)

    def down(self):
        return Direction._get_direction(self, 'down', 'up')

    def right(self):
        return Direction._get_direction(self, 'right', 'left')

    def absolute(self):
        return Direction._get_bool(self, 'absolute', 'relative')

    def left(self):
        return -Direction.right(self)

    def relative(self):
        return not Direction.absolute(self)

    def vertical_direction(self):
        down = Direction.down(self)
        return (down > 0) - (down < 0)

    def horizontal_direction(self):
        right = Direction.right(self)
        return (right > 0) - (right < 0)

    def vertical(self):
        return set(self) & set(['up', 'down'])

    def horizontal(self):
        return set(self) & set(['left', 'right'])

    def pages(self):
        return 'pages' in self and self['pages']

    def percentage(self):
        return 'percentage' in self and self['percentage']

    def cycle(self):
        return self.get('cycle') in ('true', 'on', 'yes')

    def multiply(self, n):
        for key in ('up', 'right', 'down', 'left'):
            try:
                self[key] *= n
            except Exception:
                pass

    def set(self, n):
        for key in ('up', 'right', 'down', 'left'):
            if key in self:
                self[key] = n

    def move(self, direction, override=None, minimum=0,  # pylint: disable=too-many-arguments
             maximum=9999, current=0, pagesize=1, offset=0):
        """Calculates the new position in a given boundary.

        Example:
        >>> d = Direction(pages=True)
        >>> d.move(direction=3)
        3
        >>> d.move(direction=3, current=2)
        5
        >>> d.move(direction=3, pagesize=5)
        15
        >>> # Note: we start to count at zero.
        >>> d.move(direction=3, pagesize=5, maximum=10)
        9
        >>> d.move(direction=9, override=2)
        18
        """
        pos = direction
        if override is not None:
            if self.absolute():
                pos = override
            else:
                pos *= override
        if self.pages():
            pos *= pagesize
        elif self.percentage():
            pos *= maximum / 100.0
        if self.absolute():
            if pos < minimum:
                pos += maximum
        else:
            pos += current
        if self.cycle():
            return minimum + pos % (maximum + offset - minimum)
        return int(max(min(pos, maximum + offset - 1), minimum))

    def select(self, lst, current, pagesize, override=None, offset=1):
        dest = self.move(direction=self.down(), override=override,
                         current=current, pagesize=pagesize, minimum=0, maximum=len(lst) + 1)
        selection = lst[min(current, dest):max(current, dest) + offset]
        return dest + offset - 1, selection


if __name__ == '__main__':
    import doctest
    doctest.testmod()