bastd.ui.settings.keyboard

Keyboard settings related UI functionality.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Keyboard settings related UI functionality."""
  4
  5from __future__ import annotations
  6
  7from typing import TYPE_CHECKING
  8
  9import ba
 10import ba.internal
 11
 12if TYPE_CHECKING:
 13    from typing import Any
 14
 15
 16class ConfigKeyboardWindow(ba.Window):
 17    """Window for configuring keyboards."""
 18
 19    def __init__(self, c: ba.InputDevice, transition: str = 'in_right'):
 20        self._r = 'configKeyboardWindow'
 21        self._input = c
 22        self._name = self._input.name
 23        self._unique_id = self._input.unique_identifier
 24        dname_raw = self._name
 25        if self._unique_id != '#1':
 26            dname_raw += ' ' + self._unique_id.replace('#', 'P')
 27        self._displayname = ba.Lstr(translate=('inputDeviceNames', dname_raw))
 28        self._width = 700
 29        if self._unique_id != '#1':
 30            self._height = 480
 31        else:
 32            self._height = 375
 33        self._spacing = 40
 34        uiscale = ba.app.ui.uiscale
 35        super().__init__(
 36            root_widget=ba.containerwidget(
 37                size=(self._width, self._height),
 38                scale=(
 39                    1.6
 40                    if uiscale is ba.UIScale.SMALL
 41                    else 1.3
 42                    if uiscale is ba.UIScale.MEDIUM
 43                    else 1.0
 44                ),
 45                stack_offset=(0, 5) if uiscale is ba.UIScale.SMALL else (0, 0),
 46                transition=transition,
 47            )
 48        )
 49
 50        self._rebuild_ui()
 51
 52    def _rebuild_ui(self) -> None:
 53        from ba.internal import get_device_value
 54
 55        for widget in self._root_widget.get_children():
 56            widget.delete()
 57
 58        # Fill our temp config with present values.
 59        self._settings: dict[str, int] = {}
 60        for button in [
 61            'buttonJump',
 62            'buttonPunch',
 63            'buttonBomb',
 64            'buttonPickUp',
 65            'buttonStart',
 66            'buttonStart2',
 67            'buttonUp',
 68            'buttonDown',
 69            'buttonLeft',
 70            'buttonRight',
 71        ]:
 72            self._settings[button] = get_device_value(self._input, button)
 73
 74        cancel_button = ba.buttonwidget(
 75            parent=self._root_widget,
 76            autoselect=True,
 77            position=(38, self._height - 85),
 78            size=(170, 60),
 79            label=ba.Lstr(resource='cancelText'),
 80            scale=0.9,
 81            on_activate_call=self._cancel,
 82        )
 83        save_button = ba.buttonwidget(
 84            parent=self._root_widget,
 85            autoselect=True,
 86            position=(self._width - 190, self._height - 85),
 87            size=(180, 60),
 88            label=ba.Lstr(resource='saveText'),
 89            scale=0.9,
 90            text_scale=0.9,
 91            on_activate_call=self._save,
 92        )
 93        ba.containerwidget(
 94            edit=self._root_widget,
 95            cancel_button=cancel_button,
 96            start_button=save_button,
 97        )
 98
 99        ba.widget(edit=cancel_button, right_widget=save_button)
100        ba.widget(edit=save_button, left_widget=cancel_button)
101
102        v = self._height - 74.0
103        ba.textwidget(
104            parent=self._root_widget,
105            position=(self._width * 0.5, v + 15),
106            size=(0, 0),
107            text=ba.Lstr(
108                resource=self._r + '.configuringText',
109                subs=[('${DEVICE}', self._displayname)],
110            ),
111            color=ba.app.ui.title_color,
112            h_align='center',
113            v_align='center',
114            maxwidth=270,
115            scale=0.83,
116        )
117        v -= 20
118
119        if self._unique_id != '#1':
120            v -= 20
121            v -= self._spacing
122            ba.textwidget(
123                parent=self._root_widget,
124                position=(0, v + 19),
125                size=(self._width, 50),
126                text=ba.Lstr(resource=self._r + '.keyboard2NoteText'),
127                scale=0.7,
128                maxwidth=self._width * 0.75,
129                max_height=110,
130                color=ba.app.ui.infotextcolor,
131                h_align='center',
132                v_align='top',
133            )
134            v -= 40
135        v -= 10
136        v -= self._spacing * 2.2
137        v += 25
138        v -= 42
139        h_offs = 160
140        dist = 70
141        d_color = (0.4, 0.4, 0.8)
142        self._capture_button(
143            pos=(h_offs, v + 0.95 * dist),
144            color=d_color,
145            button='buttonUp',
146            texture=ba.gettexture('upButton'),
147            scale=1.0,
148        )
149        self._capture_button(
150            pos=(h_offs - 1.2 * dist, v),
151            color=d_color,
152            button='buttonLeft',
153            texture=ba.gettexture('leftButton'),
154            scale=1.0,
155        )
156        self._capture_button(
157            pos=(h_offs + 1.2 * dist, v),
158            color=d_color,
159            button='buttonRight',
160            texture=ba.gettexture('rightButton'),
161            scale=1.0,
162        )
163        self._capture_button(
164            pos=(h_offs, v - 0.95 * dist),
165            color=d_color,
166            button='buttonDown',
167            texture=ba.gettexture('downButton'),
168            scale=1.0,
169        )
170
171        if self._unique_id == '#2':
172            self._capture_button(
173                pos=(self._width * 0.5, v + 0.1 * dist),
174                color=(0.4, 0.4, 0.6),
175                button='buttonStart',
176                texture=ba.gettexture('startButton'),
177                scale=0.8,
178            )
179
180        h_offs = self._width - 160
181
182        self._capture_button(
183            pos=(h_offs, v + 0.95 * dist),
184            color=(0.6, 0.4, 0.8),
185            button='buttonPickUp',
186            texture=ba.gettexture('buttonPickUp'),
187            scale=1.0,
188        )
189        self._capture_button(
190            pos=(h_offs - 1.2 * dist, v),
191            color=(0.7, 0.5, 0.1),
192            button='buttonPunch',
193            texture=ba.gettexture('buttonPunch'),
194            scale=1.0,
195        )
196        self._capture_button(
197            pos=(h_offs + 1.2 * dist, v),
198            color=(0.5, 0.2, 0.1),
199            button='buttonBomb',
200            texture=ba.gettexture('buttonBomb'),
201            scale=1.0,
202        )
203        self._capture_button(
204            pos=(h_offs, v - 0.95 * dist),
205            color=(0.2, 0.5, 0.2),
206            button='buttonJump',
207            texture=ba.gettexture('buttonJump'),
208            scale=1.0,
209        )
210
211    def _capture_button(
212        self,
213        pos: tuple[float, float],
214        color: tuple[float, float, float],
215        texture: ba.Texture,
216        button: str,
217        scale: float = 1.0,
218    ) -> None:
219        base_size = 79
220        btn = ba.buttonwidget(
221            parent=self._root_widget,
222            autoselect=True,
223            position=(
224                pos[0] - base_size * 0.5 * scale,
225                pos[1] - base_size * 0.5 * scale,
226            ),
227            size=(base_size * scale, base_size * scale),
228            texture=texture,
229            label='',
230            color=color,
231        )
232
233        # Do this deferred so it shows up on top of other buttons. (ew.)
234        def doit() -> None:
235            if not self._root_widget:
236                return
237            uiscale = 0.66 * scale * 2.0
238            maxwidth = 76.0 * scale
239            txt = ba.textwidget(
240                parent=self._root_widget,
241                position=(pos[0] + 0.0 * scale, pos[1] - (57.0 - 18.0) * scale),
242                color=(1, 1, 1, 0.3),
243                size=(0, 0),
244                h_align='center',
245                v_align='top',
246                scale=uiscale,
247                maxwidth=maxwidth,
248                text=self._input.get_button_name(self._settings[button]),
249            )
250            ba.buttonwidget(
251                edit=btn,
252                autoselect=True,
253                on_activate_call=ba.Call(
254                    AwaitKeyboardInputWindow, button, txt, self._settings
255                ),
256            )
257
258        ba.pushcall(doit)
259
260    def _cancel(self) -> None:
261        from bastd.ui.settings.controls import ControlsSettingsWindow
262
263        ba.containerwidget(edit=self._root_widget, transition='out_right')
264        ba.app.ui.set_main_menu_window(
265            ControlsSettingsWindow(transition='in_left').get_root_widget()
266        )
267
268    def _save(self) -> None:
269        from bastd.ui.settings.controls import ControlsSettingsWindow
270        from ba.internal import (
271            get_input_device_config,
272            should_submit_debug_info,
273            master_server_post,
274        )
275
276        ba.containerwidget(edit=self._root_widget, transition='out_right')
277        ba.playsound(ba.getsound('gunCocking'))
278
279        # There's a chance the device disappeared; handle that gracefully.
280        if not self._input:
281            return
282
283        dst = get_input_device_config(self._input, default=False)
284        dst2: dict[str, Any] = dst[0][dst[1]]
285        dst2.clear()
286
287        # Store any values that aren't -1.
288        for key, val in list(self._settings.items()):
289            if val != -1:
290                dst2[key] = val
291
292        # If we're allowed to phone home, send this config so we can generate
293        # more defaults in the future.
294        if should_submit_debug_info():
295            master_server_post(
296                'controllerConfig',
297                {
298                    'ua': ba.app.user_agent_string,
299                    'name': self._name,
300                    'b': ba.app.build_number,
301                    'config': dst2,
302                    'v': 2,
303                },
304            )
305        ba.app.config.apply_and_commit()
306        ba.app.ui.set_main_menu_window(
307            ControlsSettingsWindow(transition='in_left').get_root_widget()
308        )
309
310
311class AwaitKeyboardInputWindow(ba.Window):
312    """Window for capturing a keypress."""
313
314    def __init__(self, button: str, ui: ba.Widget, settings: dict):
315
316        self._capture_button = button
317        self._capture_key_ui = ui
318        self._settings = settings
319
320        width = 400
321        height = 150
322        uiscale = ba.app.ui.uiscale
323        super().__init__(
324            root_widget=ba.containerwidget(
325                size=(width, height),
326                transition='in_right',
327                scale=(
328                    2.0
329                    if uiscale is ba.UIScale.SMALL
330                    else 1.5
331                    if uiscale is ba.UIScale.MEDIUM
332                    else 1.0
333                ),
334            )
335        )
336        ba.textwidget(
337            parent=self._root_widget,
338            position=(0, height - 60),
339            size=(width, 25),
340            text=ba.Lstr(resource='pressAnyKeyText'),
341            h_align='center',
342            v_align='top',
343        )
344
345        self._counter = 5
346        self._count_down_text = ba.textwidget(
347            parent=self._root_widget,
348            h_align='center',
349            position=(0, height - 110),
350            size=(width, 25),
351            color=(1, 1, 1, 0.3),
352            text=str(self._counter),
353        )
354        self._decrement_timer: ba.Timer | None = ba.Timer(
355            1.0, self._decrement, repeat=True, timetype=ba.TimeType.REAL
356        )
357        ba.internal.capture_keyboard_input(ba.WeakCall(self._button_callback))
358
359    def __del__(self) -> None:
360        ba.internal.release_keyboard_input()
361
362    def _die(self) -> None:
363        # This strong-refs us; killing it allows us to die now.
364        self._decrement_timer = None
365        if self._root_widget:
366            ba.containerwidget(edit=self._root_widget, transition='out_left')
367
368    def _button_callback(self, event: dict[str, Any]) -> None:
369        self._settings[self._capture_button] = event['button']
370        if event['type'] == 'BUTTONDOWN':
371            bname = event['input_device'].get_button_name(event['button'])
372            ba.textwidget(edit=self._capture_key_ui, text=bname)
373            ba.playsound(ba.getsound('gunCocking'))
374            self._die()
375
376    def _decrement(self) -> None:
377        self._counter -= 1
378        if self._counter >= 1:
379            ba.textwidget(edit=self._count_down_text, text=str(self._counter))
380        else:
381            self._die()
class ConfigKeyboardWindow(ba.ui.Window):
 17class ConfigKeyboardWindow(ba.Window):
 18    """Window for configuring keyboards."""
 19
 20    def __init__(self, c: ba.InputDevice, transition: str = 'in_right'):
 21        self._r = 'configKeyboardWindow'
 22        self._input = c
 23        self._name = self._input.name
 24        self._unique_id = self._input.unique_identifier
 25        dname_raw = self._name
 26        if self._unique_id != '#1':
 27            dname_raw += ' ' + self._unique_id.replace('#', 'P')
 28        self._displayname = ba.Lstr(translate=('inputDeviceNames', dname_raw))
 29        self._width = 700
 30        if self._unique_id != '#1':
 31            self._height = 480
 32        else:
 33            self._height = 375
 34        self._spacing = 40
 35        uiscale = ba.app.ui.uiscale
 36        super().__init__(
 37            root_widget=ba.containerwidget(
 38                size=(self._width, self._height),
 39                scale=(
 40                    1.6
 41                    if uiscale is ba.UIScale.SMALL
 42                    else 1.3
 43                    if uiscale is ba.UIScale.MEDIUM
 44                    else 1.0
 45                ),
 46                stack_offset=(0, 5) if uiscale is ba.UIScale.SMALL else (0, 0),
 47                transition=transition,
 48            )
 49        )
 50
 51        self._rebuild_ui()
 52
 53    def _rebuild_ui(self) -> None:
 54        from ba.internal import get_device_value
 55
 56        for widget in self._root_widget.get_children():
 57            widget.delete()
 58
 59        # Fill our temp config with present values.
 60        self._settings: dict[str, int] = {}
 61        for button in [
 62            'buttonJump',
 63            'buttonPunch',
 64            'buttonBomb',
 65            'buttonPickUp',
 66            'buttonStart',
 67            'buttonStart2',
 68            'buttonUp',
 69            'buttonDown',
 70            'buttonLeft',
 71            'buttonRight',
 72        ]:
 73            self._settings[button] = get_device_value(self._input, button)
 74
 75        cancel_button = ba.buttonwidget(
 76            parent=self._root_widget,
 77            autoselect=True,
 78            position=(38, self._height - 85),
 79            size=(170, 60),
 80            label=ba.Lstr(resource='cancelText'),
 81            scale=0.9,
 82            on_activate_call=self._cancel,
 83        )
 84        save_button = ba.buttonwidget(
 85            parent=self._root_widget,
 86            autoselect=True,
 87            position=(self._width - 190, self._height - 85),
 88            size=(180, 60),
 89            label=ba.Lstr(resource='saveText'),
 90            scale=0.9,
 91            text_scale=0.9,
 92            on_activate_call=self._save,
 93        )
 94        ba.containerwidget(
 95            edit=self._root_widget,
 96            cancel_button=cancel_button,
 97            start_button=save_button,
 98        )
 99
100        ba.widget(edit=cancel_button, right_widget=save_button)
101        ba.widget(edit=save_button, left_widget=cancel_button)
102
103        v = self._height - 74.0
104        ba.textwidget(
105            parent=self._root_widget,
106            position=(self._width * 0.5, v + 15),
107            size=(0, 0),
108            text=ba.Lstr(
109                resource=self._r + '.configuringText',
110                subs=[('${DEVICE}', self._displayname)],
111            ),
112            color=ba.app.ui.title_color,
113            h_align='center',
114            v_align='center',
115            maxwidth=270,
116            scale=0.83,
117        )
118        v -= 20
119
120        if self._unique_id != '#1':
121            v -= 20
122            v -= self._spacing
123            ba.textwidget(
124                parent=self._root_widget,
125                position=(0, v + 19),
126                size=(self._width, 50),
127                text=ba.Lstr(resource=self._r + '.keyboard2NoteText'),
128                scale=0.7,
129                maxwidth=self._width * 0.75,
130                max_height=110,
131                color=ba.app.ui.infotextcolor,
132                h_align='center',
133                v_align='top',
134            )
135            v -= 40
136        v -= 10
137        v -= self._spacing * 2.2
138        v += 25
139        v -= 42
140        h_offs = 160
141        dist = 70
142        d_color = (0.4, 0.4, 0.8)
143        self._capture_button(
144            pos=(h_offs, v + 0.95 * dist),
145            color=d_color,
146            button='buttonUp',
147            texture=ba.gettexture('upButton'),
148            scale=1.0,
149        )
150        self._capture_button(
151            pos=(h_offs - 1.2 * dist, v),
152            color=d_color,
153            button='buttonLeft',
154            texture=ba.gettexture('leftButton'),
155            scale=1.0,
156        )
157        self._capture_button(
158            pos=(h_offs + 1.2 * dist, v),
159            color=d_color,
160            button='buttonRight',
161            texture=ba.gettexture('rightButton'),
162            scale=1.0,
163        )
164        self._capture_button(
165            pos=(h_offs, v - 0.95 * dist),
166            color=d_color,
167            button='buttonDown',
168            texture=ba.gettexture('downButton'),
169            scale=1.0,
170        )
171
172        if self._unique_id == '#2':
173            self._capture_button(
174                pos=(self._width * 0.5, v + 0.1 * dist),
175                color=(0.4, 0.4, 0.6),
176                button='buttonStart',
177                texture=ba.gettexture('startButton'),
178                scale=0.8,
179            )
180
181        h_offs = self._width - 160
182
183        self._capture_button(
184            pos=(h_offs, v + 0.95 * dist),
185            color=(0.6, 0.4, 0.8),
186            button='buttonPickUp',
187            texture=ba.gettexture('buttonPickUp'),
188            scale=1.0,
189        )
190        self._capture_button(
191            pos=(h_offs - 1.2 * dist, v),
192            color=(0.7, 0.5, 0.1),
193            button='buttonPunch',
194            texture=ba.gettexture('buttonPunch'),
195            scale=1.0,
196        )
197        self._capture_button(
198            pos=(h_offs + 1.2 * dist, v),
199            color=(0.5, 0.2, 0.1),
200            button='buttonBomb',
201            texture=ba.gettexture('buttonBomb'),
202            scale=1.0,
203        )
204        self._capture_button(
205            pos=(h_offs, v - 0.95 * dist),
206            color=(0.2, 0.5, 0.2),
207            button='buttonJump',
208            texture=ba.gettexture('buttonJump'),
209            scale=1.0,
210        )
211
212    def _capture_button(
213        self,
214        pos: tuple[float, float],
215        color: tuple[float, float, float],
216        texture: ba.Texture,
217        button: str,
218        scale: float = 1.0,
219    ) -> None:
220        base_size = 79
221        btn = ba.buttonwidget(
222            parent=self._root_widget,
223            autoselect=True,
224            position=(
225                pos[0] - base_size * 0.5 * scale,
226                pos[1] - base_size * 0.5 * scale,
227            ),
228            size=(base_size * scale, base_size * scale),
229            texture=texture,
230            label='',
231            color=color,
232        )
233
234        # Do this deferred so it shows up on top of other buttons. (ew.)
235        def doit() -> None:
236            if not self._root_widget:
237                return
238            uiscale = 0.66 * scale * 2.0
239            maxwidth = 76.0 * scale
240            txt = ba.textwidget(
241                parent=self._root_widget,
242                position=(pos[0] + 0.0 * scale, pos[1] - (57.0 - 18.0) * scale),
243                color=(1, 1, 1, 0.3),
244                size=(0, 0),
245                h_align='center',
246                v_align='top',
247                scale=uiscale,
248                maxwidth=maxwidth,
249                text=self._input.get_button_name(self._settings[button]),
250            )
251            ba.buttonwidget(
252                edit=btn,
253                autoselect=True,
254                on_activate_call=ba.Call(
255                    AwaitKeyboardInputWindow, button, txt, self._settings
256                ),
257            )
258
259        ba.pushcall(doit)
260
261    def _cancel(self) -> None:
262        from bastd.ui.settings.controls import ControlsSettingsWindow
263
264        ba.containerwidget(edit=self._root_widget, transition='out_right')
265        ba.app.ui.set_main_menu_window(
266            ControlsSettingsWindow(transition='in_left').get_root_widget()
267        )
268
269    def _save(self) -> None:
270        from bastd.ui.settings.controls import ControlsSettingsWindow
271        from ba.internal import (
272            get_input_device_config,
273            should_submit_debug_info,
274            master_server_post,
275        )
276
277        ba.containerwidget(edit=self._root_widget, transition='out_right')
278        ba.playsound(ba.getsound('gunCocking'))
279
280        # There's a chance the device disappeared; handle that gracefully.
281        if not self._input:
282            return
283
284        dst = get_input_device_config(self._input, default=False)
285        dst2: dict[str, Any] = dst[0][dst[1]]
286        dst2.clear()
287
288        # Store any values that aren't -1.
289        for key, val in list(self._settings.items()):
290            if val != -1:
291                dst2[key] = val
292
293        # If we're allowed to phone home, send this config so we can generate
294        # more defaults in the future.
295        if should_submit_debug_info():
296            master_server_post(
297                'controllerConfig',
298                {
299                    'ua': ba.app.user_agent_string,
300                    'name': self._name,
301                    'b': ba.app.build_number,
302                    'config': dst2,
303                    'v': 2,
304                },
305            )
306        ba.app.config.apply_and_commit()
307        ba.app.ui.set_main_menu_window(
308            ControlsSettingsWindow(transition='in_left').get_root_widget()
309        )

Window for configuring keyboards.

ConfigKeyboardWindow(c: _ba.InputDevice, transition: str = 'in_right')
20    def __init__(self, c: ba.InputDevice, transition: str = 'in_right'):
21        self._r = 'configKeyboardWindow'
22        self._input = c
23        self._name = self._input.name
24        self._unique_id = self._input.unique_identifier
25        dname_raw = self._name
26        if self._unique_id != '#1':
27            dname_raw += ' ' + self._unique_id.replace('#', 'P')
28        self._displayname = ba.Lstr(translate=('inputDeviceNames', dname_raw))
29        self._width = 700
30        if self._unique_id != '#1':
31            self._height = 480
32        else:
33            self._height = 375
34        self._spacing = 40
35        uiscale = ba.app.ui.uiscale
36        super().__init__(
37            root_widget=ba.containerwidget(
38                size=(self._width, self._height),
39                scale=(
40                    1.6
41                    if uiscale is ba.UIScale.SMALL
42                    else 1.3
43                    if uiscale is ba.UIScale.MEDIUM
44                    else 1.0
45                ),
46                stack_offset=(0, 5) if uiscale is ba.UIScale.SMALL else (0, 0),
47                transition=transition,
48            )
49        )
50
51        self._rebuild_ui()
Inherited Members
ba.ui.Window
get_root_widget
class AwaitKeyboardInputWindow(ba.ui.Window):
312class AwaitKeyboardInputWindow(ba.Window):
313    """Window for capturing a keypress."""
314
315    def __init__(self, button: str, ui: ba.Widget, settings: dict):
316
317        self._capture_button = button
318        self._capture_key_ui = ui
319        self._settings = settings
320
321        width = 400
322        height = 150
323        uiscale = ba.app.ui.uiscale
324        super().__init__(
325            root_widget=ba.containerwidget(
326                size=(width, height),
327                transition='in_right',
328                scale=(
329                    2.0
330                    if uiscale is ba.UIScale.SMALL
331                    else 1.5
332                    if uiscale is ba.UIScale.MEDIUM
333                    else 1.0
334                ),
335            )
336        )
337        ba.textwidget(
338            parent=self._root_widget,
339            position=(0, height - 60),
340            size=(width, 25),
341            text=ba.Lstr(resource='pressAnyKeyText'),
342            h_align='center',
343            v_align='top',
344        )
345
346        self._counter = 5
347        self._count_down_text = ba.textwidget(
348            parent=self._root_widget,
349            h_align='center',
350            position=(0, height - 110),
351            size=(width, 25),
352            color=(1, 1, 1, 0.3),
353            text=str(self._counter),
354        )
355        self._decrement_timer: ba.Timer | None = ba.Timer(
356            1.0, self._decrement, repeat=True, timetype=ba.TimeType.REAL
357        )
358        ba.internal.capture_keyboard_input(ba.WeakCall(self._button_callback))
359
360    def __del__(self) -> None:
361        ba.internal.release_keyboard_input()
362
363    def _die(self) -> None:
364        # This strong-refs us; killing it allows us to die now.
365        self._decrement_timer = None
366        if self._root_widget:
367            ba.containerwidget(edit=self._root_widget, transition='out_left')
368
369    def _button_callback(self, event: dict[str, Any]) -> None:
370        self._settings[self._capture_button] = event['button']
371        if event['type'] == 'BUTTONDOWN':
372            bname = event['input_device'].get_button_name(event['button'])
373            ba.textwidget(edit=self._capture_key_ui, text=bname)
374            ba.playsound(ba.getsound('gunCocking'))
375            self._die()
376
377    def _decrement(self) -> None:
378        self._counter -= 1
379        if self._counter >= 1:
380            ba.textwidget(edit=self._count_down_text, text=str(self._counter))
381        else:
382            self._die()

Window for capturing a keypress.

AwaitKeyboardInputWindow(button: str, ui: _ba.Widget, settings: dict)
315    def __init__(self, button: str, ui: ba.Widget, settings: dict):
316
317        self._capture_button = button
318        self._capture_key_ui = ui
319        self._settings = settings
320
321        width = 400
322        height = 150
323        uiscale = ba.app.ui.uiscale
324        super().__init__(
325            root_widget=ba.containerwidget(
326                size=(width, height),
327                transition='in_right',
328                scale=(
329                    2.0
330                    if uiscale is ba.UIScale.SMALL
331                    else 1.5
332                    if uiscale is ba.UIScale.MEDIUM
333                    else 1.0
334                ),
335            )
336        )
337        ba.textwidget(
338            parent=self._root_widget,
339            position=(0, height - 60),
340            size=(width, 25),
341            text=ba.Lstr(resource='pressAnyKeyText'),
342            h_align='center',
343            v_align='top',
344        )
345
346        self._counter = 5
347        self._count_down_text = ba.textwidget(
348            parent=self._root_widget,
349            h_align='center',
350            position=(0, height - 110),
351            size=(width, 25),
352            color=(1, 1, 1, 0.3),
353            text=str(self._counter),
354        )
355        self._decrement_timer: ba.Timer | None = ba.Timer(
356            1.0, self._decrement, repeat=True, timetype=ba.TimeType.REAL
357        )
358        ba.internal.capture_keyboard_input(ba.WeakCall(self._button_callback))
Inherited Members
ba.ui.Window
get_root_widget