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