File: exceptions.py

package info (click to toggle)
python-asciimatics 1.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,488 kB
  • sloc: python: 15,713; sh: 8; makefile: 2
file content (108 lines) | stat: -rw-r--r-- 2,842 bytes parent folder | download
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
"""
This module defines the exceptions used by asciimatics.
"""


class ResizeScreenError(Exception):
    """
    Asciimatics raises this Exception if the terminal is resized while playing
    a Scene (and the Screen has been told not to ignore a resizing event).
    """

    def __init__(self, message, scene=None):
        """
        :param message: Error message for this exception.
        :param scene: Scene that was active at time of resize.
        """
        super().__init__()
        self._scene = scene
        self._message = message

    def __str__(self):
        """
        Printable form of the exception.
        """
        return self._message

    @property
    def scene(self):
        """
        The Scene that was running when the Screen resized.
        """
        return self._scene


class StopApplication(Exception):
    """
    Any component can raise this exception to tell Asciimatics to stop running.
    If playing a Scene (i.e. inside `Screen.play()`) the Screen will return
    to the calling function.  When used at any other time, the exception will
    need to be caught by the application using Asciimatics.
    """

    def __init__(self, message):
        """
        :param message: Error message for this exception.
        """
        super().__init__()
        self._message = message

    def __str__(self):
        """
        Printable form of the exception.
        """
        return self._message


class NextScene(Exception):
    """
    Any component can raise this exception to tell Asciimatics to move to the
    next Scene being played.  Only effective inside `Screen.play()`.
    """

    def __init__(self, name=None):
        """
        :param name: Next Scene to invoke.  Defaults to next in the list.
        """
        super().__init__()
        self._name = name

    @property
    def name(self):
        """
        The name of the next Scene to invoke.
        """
        return self._name


class InvalidFields(Exception):
    """
    When saving data from a Frame, you can ask the Frame to validate the data
    before saving.  This is the exception that gets thrwn if any invalid data
    is found.
    """

    def __init__(self, fields):
        """
        :param fields: The list of the fields that are invalid.
        """
        super().__init__()
        self._fields = fields

    @property
    def fields(self):
        """
        The list of fields that are invalid.
        """
        return self._fields


class Highlander(Exception):
    """
    There can be only one Layout or Widget with certain options set (designed
    to fill the rest of the screen).  If you hit this exception you have
    a bug in your application.

    If you don't get the name, take a look at `this link
    <https://en.wikipedia.org/wiki/Highlander_(film)>`__.
    """