bastd.ui.telnet

UI functionality for telnet access.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""UI functionality for telnet access."""
 4
 5from __future__ import annotations
 6
 7import ba
 8import ba.internal
 9
10
11class TelnetAccessRequestWindow(ba.Window):
12    """Window asking the user whether to allow a telnet connection."""
13
14    def __init__(self) -> None:
15        width = 400
16        height = 100
17        text = ba.Lstr(resource='telnetAccessText')
18
19        uiscale = ba.app.ui.uiscale
20        super().__init__(
21            root_widget=ba.containerwidget(
22                size=(width, height + 40),
23                transition='in_right',
24                scale=(
25                    1.7
26                    if uiscale is ba.UIScale.SMALL
27                    else 1.3
28                    if uiscale is ba.UIScale.MEDIUM
29                    else 1.0
30                ),
31            )
32        )
33        padding = 20
34        ba.textwidget(
35            parent=self._root_widget,
36            position=(padding, padding + 33),
37            size=(width - 2 * padding, height - 2 * padding),
38            h_align='center',
39            v_align='top',
40            text=text,
41        )
42        btn = ba.buttonwidget(
43            parent=self._root_widget,
44            position=(20, 20),
45            size=(140, 50),
46            label=ba.Lstr(resource='denyText'),
47            on_activate_call=self._cancel,
48        )
49        ba.containerwidget(edit=self._root_widget, cancel_button=btn)
50        ba.containerwidget(edit=self._root_widget, selected_child=btn)
51
52        ba.buttonwidget(
53            parent=self._root_widget,
54            position=(width - 155, 20),
55            size=(140, 50),
56            label=ba.Lstr(resource='allowText'),
57            on_activate_call=self._ok,
58        )
59
60    def _cancel(self) -> None:
61        ba.containerwidget(edit=self._root_widget, transition='out_right')
62        ba.internal.set_telnet_access_enabled(False)
63
64    def _ok(self) -> None:
65        ba.containerwidget(edit=self._root_widget, transition='out_left')
66        ba.internal.set_telnet_access_enabled(True)
67        ba.screenmessage(ba.Lstr(resource='telnetAccessGrantedText'))
class TelnetAccessRequestWindow(ba.ui.Window):
12class TelnetAccessRequestWindow(ba.Window):
13    """Window asking the user whether to allow a telnet connection."""
14
15    def __init__(self) -> None:
16        width = 400
17        height = 100
18        text = ba.Lstr(resource='telnetAccessText')
19
20        uiscale = ba.app.ui.uiscale
21        super().__init__(
22            root_widget=ba.containerwidget(
23                size=(width, height + 40),
24                transition='in_right',
25                scale=(
26                    1.7
27                    if uiscale is ba.UIScale.SMALL
28                    else 1.3
29                    if uiscale is ba.UIScale.MEDIUM
30                    else 1.0
31                ),
32            )
33        )
34        padding = 20
35        ba.textwidget(
36            parent=self._root_widget,
37            position=(padding, padding + 33),
38            size=(width - 2 * padding, height - 2 * padding),
39            h_align='center',
40            v_align='top',
41            text=text,
42        )
43        btn = ba.buttonwidget(
44            parent=self._root_widget,
45            position=(20, 20),
46            size=(140, 50),
47            label=ba.Lstr(resource='denyText'),
48            on_activate_call=self._cancel,
49        )
50        ba.containerwidget(edit=self._root_widget, cancel_button=btn)
51        ba.containerwidget(edit=self._root_widget, selected_child=btn)
52
53        ba.buttonwidget(
54            parent=self._root_widget,
55            position=(width - 155, 20),
56            size=(140, 50),
57            label=ba.Lstr(resource='allowText'),
58            on_activate_call=self._ok,
59        )
60
61    def _cancel(self) -> None:
62        ba.containerwidget(edit=self._root_widget, transition='out_right')
63        ba.internal.set_telnet_access_enabled(False)
64
65    def _ok(self) -> None:
66        ba.containerwidget(edit=self._root_widget, transition='out_left')
67        ba.internal.set_telnet_access_enabled(True)
68        ba.screenmessage(ba.Lstr(resource='telnetAccessGrantedText'))

Window asking the user whether to allow a telnet connection.

TelnetAccessRequestWindow()
15    def __init__(self) -> None:
16        width = 400
17        height = 100
18        text = ba.Lstr(resource='telnetAccessText')
19
20        uiscale = ba.app.ui.uiscale
21        super().__init__(
22            root_widget=ba.containerwidget(
23                size=(width, height + 40),
24                transition='in_right',
25                scale=(
26                    1.7
27                    if uiscale is ba.UIScale.SMALL
28                    else 1.3
29                    if uiscale is ba.UIScale.MEDIUM
30                    else 1.0
31                ),
32            )
33        )
34        padding = 20
35        ba.textwidget(
36            parent=self._root_widget,
37            position=(padding, padding + 33),
38            size=(width - 2 * padding, height - 2 * padding),
39            h_align='center',
40            v_align='top',
41            text=text,
42        )
43        btn = ba.buttonwidget(
44            parent=self._root_widget,
45            position=(20, 20),
46            size=(140, 50),
47            label=ba.Lstr(resource='denyText'),
48            on_activate_call=self._cancel,
49        )
50        ba.containerwidget(edit=self._root_widget, cancel_button=btn)
51        ba.containerwidget(edit=self._root_widget, selected_child=btn)
52
53        ba.buttonwidget(
54            parent=self._root_widget,
55            position=(width - 155, 20),
56            size=(140, 50),
57            label=ba.Lstr(resource='allowText'),
58            on_activate_call=self._ok,
59        )
Inherited Members
ba.ui.Window
get_root_widget