~ubuntu-branches/ubuntu/vivid/gedit-plugins/vivid-proposed

« back to all changes in this revision

Viewing changes to plugins/commander/commander/commands/result.py

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-08-20 11:28:57 UTC
  • mfrom: (1.4.9)
  • Revision ID: package-import@ubuntu.com-20120820112857-b9o0cpx9enivzy8u
Tags: 3.5.1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#  Boston, MA 02111-1307, USA.
21
21
 
22
22
class Result(object):
23
 
        HIDE = 1
24
 
        DONE = 2
25
 
        PROMPT = 3
26
 
        SUSPEND = 4
27
 
 
28
 
        def __init__(self, value):
29
 
                self._value = value
30
 
 
31
 
        def __int__(self):
32
 
                return self._value
33
 
 
34
 
        def __cmp__(self, other):
35
 
                if isinstance(other, int) or isinstance(other, Result):
36
 
                        return cmp(int(self), int(other))
37
 
                else:
38
 
                        return 1
 
23
    HIDE = 1
 
24
    DONE = 2
 
25
    PROMPT = 3
 
26
    SUSPEND = 4
 
27
 
 
28
    def __init__(self, value):
 
29
        self._value = value
 
30
 
 
31
    def __int__(self):
 
32
        return self._value
 
33
 
 
34
    def __cmp__(self, other):
 
35
        if isinstance(other, int) or isinstance(other, Result):
 
36
            return cmp(int(self), int(other))
 
37
        else:
 
38
            return 1
39
39
 
40
40
# Easy shortcuts
41
41
HIDE = Result(Result.HIDE)
42
42
DONE = Result(Result.DONE)
43
43
 
44
44
class Prompt(Result):
45
 
        def __init__(self, prompt, autocomplete={}):
46
 
                Result.__init__(self, Result.PROMPT)
 
45
    def __init__(self, prompt, autocomplete={}):
 
46
        Result.__init__(self, Result.PROMPT)
47
47
 
48
 
                self.prompt = prompt
49
 
                self.autocomplete = autocomplete
 
48
        self.prompt = prompt
 
49
        self.autocomplete = autocomplete
50
50
 
51
51
class Suspend(Result):
52
 
        def __init__(self):
53
 
                Result.__init__(self, Result.SUSPEND)
54
 
                self._callbacks = []
55
 
 
56
 
        def register(self, cb, *args):
57
 
                self._callbacks.append([cb, args])
58
 
 
59
 
        def resume(self):
60
 
                for cb in self._callbacks:
61
 
                        args = cb[1]
62
 
                        cb[0](*args)
 
52
    def __init__(self):
 
53
        Result.__init__(self, Result.SUSPEND)
 
54
        self._callbacks = []
 
55
 
 
56
    def register(self, cb, *args):
 
57
        self._callbacks.append([cb, args])
 
58
 
 
59
    def resume(self):
 
60
        for cb in self._callbacks:
 
61
            args = cb[1]
 
62
            cb[0](*args)
 
63
 
 
64
# vi:ex:ts=4:et