bauiv1lib.settings.devtools
UI functionality for Modding Tools.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI functionality for Modding Tools.""" 4 5from __future__ import annotations 6 7from typing import override 8 9import babase 10import bauiv1 as bui 11from bauiv1lib.popup import PopupMenu 12from bauiv1lib.confirm import ConfirmWindow 13from bauiv1lib.config import ConfigCheckBox 14 15 16class DevToolsWindow(bui.MainWindow): 17 """Window for accessing modding tools.""" 18 19 def __init__( 20 self, 21 transition: str | None = 'in_right', 22 origin_widget: bui.Widget | None = None, 23 ): 24 25 app = bui.app 26 assert app.classic is not None 27 28 uiscale = app.ui_v1.uiscale 29 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 30 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 31 self._height = ( 32 370.0 33 if uiscale is bui.UIScale.SMALL 34 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 35 ) 36 37 self._spacing = 32 38 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 39 40 self._scroll_width = self._width - (100 + 2 * x_inset) 41 self._scroll_height = self._height - 115.0 42 self._sub_width = self._scroll_width * 0.95 43 self._sub_height = 350.0 44 45 super().__init__( 46 root_widget=bui.containerwidget( 47 size=(self._width, self._height + top_extra), 48 toolbar_visibility=( 49 'menu_minimal' 50 if uiscale is bui.UIScale.SMALL 51 else 'menu_full' 52 ), 53 scale=( 54 2.13 55 if uiscale is bui.UIScale.SMALL 56 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 57 ), 58 stack_offset=( 59 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 60 ), 61 ), 62 transition=transition, 63 origin_widget=origin_widget, 64 ) 65 66 self._r = 'settingsDevTools' 67 68 if uiscale is bui.UIScale.SMALL: 69 bui.containerwidget( 70 edit=self._root_widget, on_cancel_call=self.main_window_back 71 ) 72 self._back_button = None 73 else: 74 self._back_button = bui.buttonwidget( 75 parent=self._root_widget, 76 position=(53 + x_inset, self._height - 60), 77 size=(140, 60), 78 scale=0.8, 79 autoselect=True, 80 label=bui.Lstr(resource='backText'), 81 button_type='back', 82 on_activate_call=self.main_window_back, 83 ) 84 bui.containerwidget( 85 edit=self._root_widget, cancel_button=self._back_button 86 ) 87 88 self._title_text = bui.textwidget( 89 parent=self._root_widget, 90 position=( 91 self._width * 0.5, 92 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 93 ), 94 size=(0, 25), 95 scale=(0.6 if uiscale is bui.UIScale.SMALL else 1.0), 96 maxwidth=self._width - 200, 97 text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'), 98 color=app.ui_v1.title_color, 99 h_align='center', 100 v_align='center', 101 ) 102 103 if self._back_button is not None: 104 bui.buttonwidget( 105 edit=self._back_button, 106 button_type='backSmall', 107 size=(60, 60), 108 label=bui.charstr(bui.SpecialChar.BACK), 109 ) 110 111 self._scrollwidget = bui.scrollwidget( 112 parent=self._root_widget, 113 position=(50 + x_inset, 50), 114 simple_culling_v=20.0, 115 highlight=False, 116 size=(self._scroll_width, self._scroll_height), 117 selection_loops_to_parent=True, 118 ) 119 bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget) 120 self._subcontainer = bui.containerwidget( 121 parent=self._scrollwidget, 122 size=(self._sub_width, self._sub_height), 123 background=False, 124 selection_loops_to_parent=True, 125 ) 126 127 v = self._sub_height - 35 128 this_button_width = 410 129 130 v -= self._spacing * 2.5 131 self._show_dev_console_button_check_box = ConfigCheckBox( 132 parent=self._subcontainer, 133 position=(90, v + 40), 134 size=(self._sub_width - 100, 30), 135 configkey='Show Dev Console Button', 136 displayname=bui.Lstr( 137 resource='settingsWindowAdvanced.showDevConsoleButtonText' 138 ), 139 scale=1.0, 140 maxwidth=400, 141 ) 142 if self._back_button is not None: 143 bui.widget( 144 edit=self._show_dev_console_button_check_box.widget, 145 up_widget=self._back_button, 146 ) 147 148 v -= self._spacing * 1.2 149 self._create_user_system_scripts_button = bui.buttonwidget( 150 parent=self._subcontainer, 151 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 152 size=(this_button_width, 60), 153 autoselect=True, 154 label=bui.Lstr(resource='userSystemScriptsCreateText'), 155 text_scale=1.0, 156 on_activate_call=babase.modutils.create_user_system_scripts, 157 ) 158 159 v -= self._spacing * 2.5 160 self._delete_user_system_scripts_button = bui.buttonwidget( 161 parent=self._subcontainer, 162 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 163 size=(this_button_width, 60), 164 autoselect=True, 165 label=bui.Lstr(resource='userSystemScriptsDeleteText'), 166 text_scale=1.0, 167 on_activate_call=lambda: ConfirmWindow( 168 action=babase.modutils.delete_user_system_scripts, 169 ), 170 ) 171 172 v -= self._spacing * 2.5 173 bui.textwidget( 174 parent=self._subcontainer, 175 position=(170, v + 10), 176 size=(0, 0), 177 text=bui.Lstr(resource='uiScaleText'), 178 color=app.ui_v1.title_color, 179 h_align='center', 180 v_align='center', 181 ) 182 183 PopupMenu( 184 parent=self._subcontainer, 185 position=(230, v - 20), 186 button_size=(200.0, 60.0), 187 width=100.0, 188 choices=[ 189 'auto', 190 'small', 191 'medium', 192 'large', 193 ], 194 choices_display=[ 195 bui.Lstr(resource='autoText'), 196 bui.Lstr(resource='sizeSmallText'), 197 bui.Lstr(resource='sizeMediumText'), 198 bui.Lstr(resource='sizeLargeText'), 199 ], 200 current_choice=app.config.get('UI Scale', 'auto'), 201 on_value_change_call=self._set_uiscale, 202 ) 203 204 @override 205 def get_main_window_state(self) -> bui.MainWindowState: 206 # Support recreating our window for back/refresh purposes. 207 cls = type(self) 208 return bui.BasicMainWindowState( 209 create_call=lambda transition, origin_widget: cls( 210 transition=transition, origin_widget=origin_widget 211 ) 212 ) 213 214 def _set_uiscale(self, val: str) -> None: 215 cfg = bui.app.config 216 cfg['UI Scale'] = val 217 cfg.apply_and_commit() 218 if bui.app.ui_v1.uiscale.name != val.upper(): 219 bui.screenmessage( 220 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 221 color=(1.0, 0.5, 0.0), 222 )
class
DevToolsWindow(bauiv1._uitypes.MainWindow):
17class DevToolsWindow(bui.MainWindow): 18 """Window for accessing modding tools.""" 19 20 def __init__( 21 self, 22 transition: str | None = 'in_right', 23 origin_widget: bui.Widget | None = None, 24 ): 25 26 app = bui.app 27 assert app.classic is not None 28 29 uiscale = app.ui_v1.uiscale 30 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 31 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 32 self._height = ( 33 370.0 34 if uiscale is bui.UIScale.SMALL 35 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 36 ) 37 38 self._spacing = 32 39 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 40 41 self._scroll_width = self._width - (100 + 2 * x_inset) 42 self._scroll_height = self._height - 115.0 43 self._sub_width = self._scroll_width * 0.95 44 self._sub_height = 350.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height + top_extra), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=( 55 2.13 56 if uiscale is bui.UIScale.SMALL 57 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 58 ), 59 stack_offset=( 60 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 61 ), 62 ), 63 transition=transition, 64 origin_widget=origin_widget, 65 ) 66 67 self._r = 'settingsDevTools' 68 69 if uiscale is bui.UIScale.SMALL: 70 bui.containerwidget( 71 edit=self._root_widget, on_cancel_call=self.main_window_back 72 ) 73 self._back_button = None 74 else: 75 self._back_button = bui.buttonwidget( 76 parent=self._root_widget, 77 position=(53 + x_inset, self._height - 60), 78 size=(140, 60), 79 scale=0.8, 80 autoselect=True, 81 label=bui.Lstr(resource='backText'), 82 button_type='back', 83 on_activate_call=self.main_window_back, 84 ) 85 bui.containerwidget( 86 edit=self._root_widget, cancel_button=self._back_button 87 ) 88 89 self._title_text = bui.textwidget( 90 parent=self._root_widget, 91 position=( 92 self._width * 0.5, 93 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 94 ), 95 size=(0, 25), 96 scale=(0.6 if uiscale is bui.UIScale.SMALL else 1.0), 97 maxwidth=self._width - 200, 98 text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'), 99 color=app.ui_v1.title_color, 100 h_align='center', 101 v_align='center', 102 ) 103 104 if self._back_button is not None: 105 bui.buttonwidget( 106 edit=self._back_button, 107 button_type='backSmall', 108 size=(60, 60), 109 label=bui.charstr(bui.SpecialChar.BACK), 110 ) 111 112 self._scrollwidget = bui.scrollwidget( 113 parent=self._root_widget, 114 position=(50 + x_inset, 50), 115 simple_culling_v=20.0, 116 highlight=False, 117 size=(self._scroll_width, self._scroll_height), 118 selection_loops_to_parent=True, 119 ) 120 bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget) 121 self._subcontainer = bui.containerwidget( 122 parent=self._scrollwidget, 123 size=(self._sub_width, self._sub_height), 124 background=False, 125 selection_loops_to_parent=True, 126 ) 127 128 v = self._sub_height - 35 129 this_button_width = 410 130 131 v -= self._spacing * 2.5 132 self._show_dev_console_button_check_box = ConfigCheckBox( 133 parent=self._subcontainer, 134 position=(90, v + 40), 135 size=(self._sub_width - 100, 30), 136 configkey='Show Dev Console Button', 137 displayname=bui.Lstr( 138 resource='settingsWindowAdvanced.showDevConsoleButtonText' 139 ), 140 scale=1.0, 141 maxwidth=400, 142 ) 143 if self._back_button is not None: 144 bui.widget( 145 edit=self._show_dev_console_button_check_box.widget, 146 up_widget=self._back_button, 147 ) 148 149 v -= self._spacing * 1.2 150 self._create_user_system_scripts_button = bui.buttonwidget( 151 parent=self._subcontainer, 152 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 153 size=(this_button_width, 60), 154 autoselect=True, 155 label=bui.Lstr(resource='userSystemScriptsCreateText'), 156 text_scale=1.0, 157 on_activate_call=babase.modutils.create_user_system_scripts, 158 ) 159 160 v -= self._spacing * 2.5 161 self._delete_user_system_scripts_button = bui.buttonwidget( 162 parent=self._subcontainer, 163 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 164 size=(this_button_width, 60), 165 autoselect=True, 166 label=bui.Lstr(resource='userSystemScriptsDeleteText'), 167 text_scale=1.0, 168 on_activate_call=lambda: ConfirmWindow( 169 action=babase.modutils.delete_user_system_scripts, 170 ), 171 ) 172 173 v -= self._spacing * 2.5 174 bui.textwidget( 175 parent=self._subcontainer, 176 position=(170, v + 10), 177 size=(0, 0), 178 text=bui.Lstr(resource='uiScaleText'), 179 color=app.ui_v1.title_color, 180 h_align='center', 181 v_align='center', 182 ) 183 184 PopupMenu( 185 parent=self._subcontainer, 186 position=(230, v - 20), 187 button_size=(200.0, 60.0), 188 width=100.0, 189 choices=[ 190 'auto', 191 'small', 192 'medium', 193 'large', 194 ], 195 choices_display=[ 196 bui.Lstr(resource='autoText'), 197 bui.Lstr(resource='sizeSmallText'), 198 bui.Lstr(resource='sizeMediumText'), 199 bui.Lstr(resource='sizeLargeText'), 200 ], 201 current_choice=app.config.get('UI Scale', 'auto'), 202 on_value_change_call=self._set_uiscale, 203 ) 204 205 @override 206 def get_main_window_state(self) -> bui.MainWindowState: 207 # Support recreating our window for back/refresh purposes. 208 cls = type(self) 209 return bui.BasicMainWindowState( 210 create_call=lambda transition, origin_widget: cls( 211 transition=transition, origin_widget=origin_widget 212 ) 213 ) 214 215 def _set_uiscale(self, val: str) -> None: 216 cfg = bui.app.config 217 cfg['UI Scale'] = val 218 cfg.apply_and_commit() 219 if bui.app.ui_v1.uiscale.name != val.upper(): 220 bui.screenmessage( 221 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 222 color=(1.0, 0.5, 0.0), 223 )
Window for accessing modding tools.
DevToolsWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
20 def __init__( 21 self, 22 transition: str | None = 'in_right', 23 origin_widget: bui.Widget | None = None, 24 ): 25 26 app = bui.app 27 assert app.classic is not None 28 29 uiscale = app.ui_v1.uiscale 30 self._width = 1000.0 if uiscale is bui.UIScale.SMALL else 670.0 31 x_inset = 150 if uiscale is bui.UIScale.SMALL else 0 32 self._height = ( 33 370.0 34 if uiscale is bui.UIScale.SMALL 35 else 450.0 if uiscale is bui.UIScale.MEDIUM else 520.0 36 ) 37 38 self._spacing = 32 39 top_extra = 10 if uiscale is bui.UIScale.SMALL else 0 40 41 self._scroll_width = self._width - (100 + 2 * x_inset) 42 self._scroll_height = self._height - 115.0 43 self._sub_width = self._scroll_width * 0.95 44 self._sub_height = 350.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height + top_extra), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=( 55 2.13 56 if uiscale is bui.UIScale.SMALL 57 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 58 ), 59 stack_offset=( 60 (0, 0) if uiscale is bui.UIScale.SMALL else (0, 0) 61 ), 62 ), 63 transition=transition, 64 origin_widget=origin_widget, 65 ) 66 67 self._r = 'settingsDevTools' 68 69 if uiscale is bui.UIScale.SMALL: 70 bui.containerwidget( 71 edit=self._root_widget, on_cancel_call=self.main_window_back 72 ) 73 self._back_button = None 74 else: 75 self._back_button = bui.buttonwidget( 76 parent=self._root_widget, 77 position=(53 + x_inset, self._height - 60), 78 size=(140, 60), 79 scale=0.8, 80 autoselect=True, 81 label=bui.Lstr(resource='backText'), 82 button_type='back', 83 on_activate_call=self.main_window_back, 84 ) 85 bui.containerwidget( 86 edit=self._root_widget, cancel_button=self._back_button 87 ) 88 89 self._title_text = bui.textwidget( 90 parent=self._root_widget, 91 position=( 92 self._width * 0.5, 93 self._height - (64 if uiscale is bui.UIScale.SMALL else 48), 94 ), 95 size=(0, 25), 96 scale=(0.6 if uiscale is bui.UIScale.SMALL else 1.0), 97 maxwidth=self._width - 200, 98 text=bui.Lstr(resource='settingsWindowAdvanced.devToolsText'), 99 color=app.ui_v1.title_color, 100 h_align='center', 101 v_align='center', 102 ) 103 104 if self._back_button is not None: 105 bui.buttonwidget( 106 edit=self._back_button, 107 button_type='backSmall', 108 size=(60, 60), 109 label=bui.charstr(bui.SpecialChar.BACK), 110 ) 111 112 self._scrollwidget = bui.scrollwidget( 113 parent=self._root_widget, 114 position=(50 + x_inset, 50), 115 simple_culling_v=20.0, 116 highlight=False, 117 size=(self._scroll_width, self._scroll_height), 118 selection_loops_to_parent=True, 119 ) 120 bui.widget(edit=self._scrollwidget, right_widget=self._scrollwidget) 121 self._subcontainer = bui.containerwidget( 122 parent=self._scrollwidget, 123 size=(self._sub_width, self._sub_height), 124 background=False, 125 selection_loops_to_parent=True, 126 ) 127 128 v = self._sub_height - 35 129 this_button_width = 410 130 131 v -= self._spacing * 2.5 132 self._show_dev_console_button_check_box = ConfigCheckBox( 133 parent=self._subcontainer, 134 position=(90, v + 40), 135 size=(self._sub_width - 100, 30), 136 configkey='Show Dev Console Button', 137 displayname=bui.Lstr( 138 resource='settingsWindowAdvanced.showDevConsoleButtonText' 139 ), 140 scale=1.0, 141 maxwidth=400, 142 ) 143 if self._back_button is not None: 144 bui.widget( 145 edit=self._show_dev_console_button_check_box.widget, 146 up_widget=self._back_button, 147 ) 148 149 v -= self._spacing * 1.2 150 self._create_user_system_scripts_button = bui.buttonwidget( 151 parent=self._subcontainer, 152 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 153 size=(this_button_width, 60), 154 autoselect=True, 155 label=bui.Lstr(resource='userSystemScriptsCreateText'), 156 text_scale=1.0, 157 on_activate_call=babase.modutils.create_user_system_scripts, 158 ) 159 160 v -= self._spacing * 2.5 161 self._delete_user_system_scripts_button = bui.buttonwidget( 162 parent=self._subcontainer, 163 position=(self._sub_width / 2 - this_button_width / 2, v - 10), 164 size=(this_button_width, 60), 165 autoselect=True, 166 label=bui.Lstr(resource='userSystemScriptsDeleteText'), 167 text_scale=1.0, 168 on_activate_call=lambda: ConfirmWindow( 169 action=babase.modutils.delete_user_system_scripts, 170 ), 171 ) 172 173 v -= self._spacing * 2.5 174 bui.textwidget( 175 parent=self._subcontainer, 176 position=(170, v + 10), 177 size=(0, 0), 178 text=bui.Lstr(resource='uiScaleText'), 179 color=app.ui_v1.title_color, 180 h_align='center', 181 v_align='center', 182 ) 183 184 PopupMenu( 185 parent=self._subcontainer, 186 position=(230, v - 20), 187 button_size=(200.0, 60.0), 188 width=100.0, 189 choices=[ 190 'auto', 191 'small', 192 'medium', 193 'large', 194 ], 195 choices_display=[ 196 bui.Lstr(resource='autoText'), 197 bui.Lstr(resource='sizeSmallText'), 198 bui.Lstr(resource='sizeMediumText'), 199 bui.Lstr(resource='sizeLargeText'), 200 ], 201 current_choice=app.config.get('UI Scale', 'auto'), 202 on_value_change_call=self._set_uiscale, 203 )
Create a MainWindow given a root widget and transition info.
Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.
205 @override 206 def get_main_window_state(self) -> bui.MainWindowState: 207 # Support recreating our window for back/refresh purposes. 208 cls = type(self) 209 return bui.BasicMainWindowState( 210 create_call=lambda transition, origin_widget: cls( 211 transition=transition, origin_widget=origin_widget 212 ) 213 )
Return a WindowState to recreate this window, if supported.
Inherited Members
- bauiv1._uitypes.MainWindow
- main_window_back_state
- main_window_close
- can_change_main_window
- main_window_back
- main_window_replace
- on_main_window_close
- bauiv1._uitypes.Window
- get_root_widget