bastd.ui.configerror
UI for dealing with broken config files.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI for dealing with broken config files.""" 4 5from __future__ import annotations 6 7from typing import TYPE_CHECKING 8 9import ba 10import ba.internal 11 12if TYPE_CHECKING: 13 pass 14 15 16class ConfigErrorWindow(ba.Window): 17 """Window for dealing with a broken config.""" 18 19 def __init__(self) -> None: 20 self._config_file_path = ba.app.config_file_path 21 width = 800 22 super().__init__( 23 ba.containerwidget(size=(width, 400), transition='in_right') 24 ) 25 padding = 20 26 ba.textwidget( 27 parent=self._root_widget, 28 position=(padding, 220 + 60), 29 size=(width - 2 * padding, 100 - 2 * padding), 30 h_align='center', 31 v_align='top', 32 scale=0.73, 33 text=( 34 f'Error reading {ba.internal.appnameupper()} config file' 35 ':\n\n\nCheck the console' 36 ' (press ~ twice) for details.\n\nWould you like to quit and' 37 ' try to fix it by hand\nor overwrite it with defaults?\n\n' 38 '(high scores, player profiles, etc will be lost if you' 39 ' overwrite)' 40 ), 41 ) 42 ba.textwidget( 43 parent=self._root_widget, 44 position=(padding, 198 + 60), 45 size=(width - 2 * padding, 100 - 2 * padding), 46 h_align='center', 47 v_align='top', 48 scale=0.5, 49 text=self._config_file_path, 50 ) 51 quit_button = ba.buttonwidget( 52 parent=self._root_widget, 53 position=(35, 30), 54 size=(240, 54), 55 label='Quit and Edit', 56 on_activate_call=self._quit, 57 ) 58 ba.buttonwidget( 59 parent=self._root_widget, 60 position=(width - 370, 30), 61 size=(330, 54), 62 label='Overwrite with Defaults', 63 on_activate_call=self._defaults, 64 ) 65 ba.containerwidget( 66 edit=self._root_widget, 67 cancel_button=quit_button, 68 selected_child=quit_button, 69 ) 70 71 def _quit(self) -> None: 72 ba.timer(0.001, self._edit_and_quit, timetype=ba.TimeType.REAL) 73 ba.internal.lock_all_input() 74 75 def _edit_and_quit(self) -> None: 76 ba.internal.open_file_externally(self._config_file_path) 77 ba.timer(0.1, ba.quit, timetype=ba.TimeType.REAL) 78 79 def _defaults(self) -> None: 80 from ba.internal import commit_app_config 81 82 ba.containerwidget(edit=self._root_widget, transition='out_left') 83 ba.playsound(ba.getsound('gunCocking')) 84 ba.screenmessage('settings reset.', color=(1, 1, 0)) 85 86 # At this point settings are already set; lets just commit them 87 # to disk. 88 commit_app_config(force=True)
class
ConfigErrorWindow(ba.ui.Window):
17class ConfigErrorWindow(ba.Window): 18 """Window for dealing with a broken config.""" 19 20 def __init__(self) -> None: 21 self._config_file_path = ba.app.config_file_path 22 width = 800 23 super().__init__( 24 ba.containerwidget(size=(width, 400), transition='in_right') 25 ) 26 padding = 20 27 ba.textwidget( 28 parent=self._root_widget, 29 position=(padding, 220 + 60), 30 size=(width - 2 * padding, 100 - 2 * padding), 31 h_align='center', 32 v_align='top', 33 scale=0.73, 34 text=( 35 f'Error reading {ba.internal.appnameupper()} config file' 36 ':\n\n\nCheck the console' 37 ' (press ~ twice) for details.\n\nWould you like to quit and' 38 ' try to fix it by hand\nor overwrite it with defaults?\n\n' 39 '(high scores, player profiles, etc will be lost if you' 40 ' overwrite)' 41 ), 42 ) 43 ba.textwidget( 44 parent=self._root_widget, 45 position=(padding, 198 + 60), 46 size=(width - 2 * padding, 100 - 2 * padding), 47 h_align='center', 48 v_align='top', 49 scale=0.5, 50 text=self._config_file_path, 51 ) 52 quit_button = ba.buttonwidget( 53 parent=self._root_widget, 54 position=(35, 30), 55 size=(240, 54), 56 label='Quit and Edit', 57 on_activate_call=self._quit, 58 ) 59 ba.buttonwidget( 60 parent=self._root_widget, 61 position=(width - 370, 30), 62 size=(330, 54), 63 label='Overwrite with Defaults', 64 on_activate_call=self._defaults, 65 ) 66 ba.containerwidget( 67 edit=self._root_widget, 68 cancel_button=quit_button, 69 selected_child=quit_button, 70 ) 71 72 def _quit(self) -> None: 73 ba.timer(0.001, self._edit_and_quit, timetype=ba.TimeType.REAL) 74 ba.internal.lock_all_input() 75 76 def _edit_and_quit(self) -> None: 77 ba.internal.open_file_externally(self._config_file_path) 78 ba.timer(0.1, ba.quit, timetype=ba.TimeType.REAL) 79 80 def _defaults(self) -> None: 81 from ba.internal import commit_app_config 82 83 ba.containerwidget(edit=self._root_widget, transition='out_left') 84 ba.playsound(ba.getsound('gunCocking')) 85 ba.screenmessage('settings reset.', color=(1, 1, 0)) 86 87 # At this point settings are already set; lets just commit them 88 # to disk. 89 commit_app_config(force=True)
Window for dealing with a broken config.
ConfigErrorWindow()
20 def __init__(self) -> None: 21 self._config_file_path = ba.app.config_file_path 22 width = 800 23 super().__init__( 24 ba.containerwidget(size=(width, 400), transition='in_right') 25 ) 26 padding = 20 27 ba.textwidget( 28 parent=self._root_widget, 29 position=(padding, 220 + 60), 30 size=(width - 2 * padding, 100 - 2 * padding), 31 h_align='center', 32 v_align='top', 33 scale=0.73, 34 text=( 35 f'Error reading {ba.internal.appnameupper()} config file' 36 ':\n\n\nCheck the console' 37 ' (press ~ twice) for details.\n\nWould you like to quit and' 38 ' try to fix it by hand\nor overwrite it with defaults?\n\n' 39 '(high scores, player profiles, etc will be lost if you' 40 ' overwrite)' 41 ), 42 ) 43 ba.textwidget( 44 parent=self._root_widget, 45 position=(padding, 198 + 60), 46 size=(width - 2 * padding, 100 - 2 * padding), 47 h_align='center', 48 v_align='top', 49 scale=0.5, 50 text=self._config_file_path, 51 ) 52 quit_button = ba.buttonwidget( 53 parent=self._root_widget, 54 position=(35, 30), 55 size=(240, 54), 56 label='Quit and Edit', 57 on_activate_call=self._quit, 58 ) 59 ba.buttonwidget( 60 parent=self._root_widget, 61 position=(width - 370, 30), 62 size=(330, 54), 63 label='Overwrite with Defaults', 64 on_activate_call=self._defaults, 65 ) 66 ba.containerwidget( 67 edit=self._root_widget, 68 cancel_button=quit_button, 69 selected_child=quit_button, 70 )
Inherited Members
- ba.ui.Window
- get_root_widget