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