]> git.wh0rd.org - gnudebbugs.git/blob - src/gnudebbugs/ui/__init__.py
initial release
[gnudebbugs.git] / src / gnudebbugs / ui / __init__.py
1 # Copyright (C) 2021 Free Software Foundation, Inc.
2 #
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16 """Common UI settings."""
17
18 import abc
19
20 from .. import BaseError
21
22
23 class Error(BaseError):
24 """Base UI error class."""
25
26
27 class MissingUrwidError(Error):
28 """The urwid module is unavailable."""
29
30
31 class UIBase(abc.ABC):
32 """Base class for all UI implementations."""
33
34 def __init__(self):
35 pass
36
37 def start(self) -> None:
38 pass
39
40 def stop(self) -> None:
41 pass
42
43 def status(self, text: str) -> None:
44 """Print status information."""
45
46 def interface_query(self, client, statuses, bug_width, summary_tags, tags_width, summary_states, states_width) -> None:
47 """Run the query interface."""
48
49
50 def get_backend(backend: str) -> UIBase:
51 """Helper to dynamically load the right backend."""
52 if backend == "cli":
53 from . import cli
54
55 return cli.UI
56 elif backend == "urwid":
57 try:
58 from . import urwid
59 except ImportError as e:
60 raise MissingUrwidError(f'Unable to import urwid: {e}')
61
62 return urwid.UI