bauiv1lib.settings.touchscreen
UI settings functionality related to touchscreens.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI settings functionality related to touchscreens.""" 4from __future__ import annotations 5 6from typing import override 7 8import bauiv1 as bui 9import bascenev1 as bs 10 11 12class TouchscreenSettingsWindow(bui.MainWindow): 13 """Settings window for touchscreens.""" 14 15 def __del__(self) -> None: 16 bs.set_touchscreen_editing(False) 17 18 def __init__( 19 self, 20 transition: str | None = 'in_right', 21 origin_widget: bui.Widget | None = None, 22 ) -> None: 23 self._width = 780 24 self._height = 380 25 self._r = 'configTouchscreenWindow' 26 27 bs.set_touchscreen_editing(True) 28 29 assert bui.app.classic is not None 30 uiscale = bui.app.ui_v1.uiscale 31 super().__init__( 32 root_widget=bui.containerwidget( 33 size=(self._width, self._height), 34 scale=( 35 1.9 36 if uiscale is bui.UIScale.SMALL 37 else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.2 38 ), 39 toolbar_visibility=( 40 'menu_minimal' 41 if uiscale is bui.UIScale.SMALL 42 else 'menu_full' 43 ), 44 stack_offset=( 45 (0, -20) if uiscale is bui.UIScale.SMALL else (0, 0) 46 ), 47 ), 48 transition=transition, 49 origin_widget=origin_widget, 50 ) 51 52 if uiscale is bui.UIScale.SMALL: 53 bui.containerwidget( 54 edit=self._root_widget, on_cancel_call=self.main_window_back 55 ) 56 else: 57 btn = bui.buttonwidget( 58 parent=self._root_widget, 59 position=(55, self._height - 60), 60 size=(60, 60), 61 label=bui.charstr(bui.SpecialChar.BACK), 62 button_type='backSmall', 63 scale=0.8, 64 on_activate_call=self.main_window_back, 65 ) 66 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 67 68 bui.textwidget( 69 parent=self._root_widget, 70 position=(25, self._height - 57), 71 size=(self._width, 25), 72 text=bui.Lstr(resource=f'{self._r}.titleText'), 73 color=bui.app.ui_v1.title_color, 74 maxwidth=280, 75 h_align='center', 76 v_align='center', 77 ) 78 79 self._scroll_width = self._width - 100 80 self._scroll_height = self._height - 110 81 self._sub_width = self._scroll_width - 20 82 self._sub_height = 360 83 84 self._scrollwidget = bui.scrollwidget( 85 parent=self._root_widget, 86 position=( 87 (self._width - self._scroll_width) * 0.5, 88 self._height - 65 - self._scroll_height, 89 ), 90 size=(self._scroll_width, self._scroll_height), 91 claims_left_right=True, 92 selection_loops_to_parent=True, 93 ) 94 self._subcontainer = bui.containerwidget( 95 parent=self._scrollwidget, 96 size=(self._sub_width, self._sub_height), 97 background=False, 98 claims_left_right=True, 99 selection_loops_to_parent=True, 100 ) 101 self._build_gui() 102 103 @override 104 def get_main_window_state(self) -> bui.MainWindowState: 105 # Support recreating our window for back/refresh purposes. 106 cls = type(self) 107 return bui.BasicMainWindowState( 108 create_call=lambda transition, origin_widget: cls( 109 transition=transition, origin_widget=origin_widget 110 ) 111 ) 112 113 def _build_gui(self) -> None: 114 # pylint: disable=too-many-locals 115 from bauiv1lib.config import ConfigNumberEdit, ConfigCheckBox 116 from bauiv1lib.radiogroup import make_radio_group 117 118 # Clear anything already there. 119 children = self._subcontainer.get_children() 120 for child in children: 121 child.delete() 122 h = 30 123 hoffs = 100 124 hoffs2 = 70 125 hoffs3 = 320 126 v = self._sub_height - 85 127 clr = (0.8, 0.8, 0.8, 1.0) 128 clr2 = (0.8, 0.8, 0.8) 129 bui.textwidget( 130 parent=self._subcontainer, 131 position=(self._sub_width * 0.5, v + 63), 132 size=(0, 0), 133 text=bui.Lstr(resource=f'{self._r}.swipeInfoText'), 134 flatness=1.0, 135 color=(0, 0.9, 0.1, 0.7), 136 maxwidth=self._sub_width * 0.9, 137 scale=0.55, 138 h_align='center', 139 v_align='center', 140 ) 141 cur_val = bui.app.config.get('Touch Movement Control Type', 'swipe') 142 bui.textwidget( 143 parent=self._subcontainer, 144 position=(h, v - 2), 145 size=(0, 30), 146 text=bui.Lstr(resource=f'{self._r}.movementText'), 147 maxwidth=190, 148 color=clr, 149 v_align='center', 150 ) 151 cb1 = bui.checkboxwidget( 152 parent=self._subcontainer, 153 position=(h + hoffs + 220, v), 154 size=(170, 30), 155 text=bui.Lstr(resource=f'{self._r}.joystickText'), 156 maxwidth=100, 157 textcolor=clr2, 158 scale=0.9, 159 ) 160 cb2 = bui.checkboxwidget( 161 parent=self._subcontainer, 162 position=(h + hoffs + 357, v), 163 size=(170, 30), 164 text=bui.Lstr(resource=f'{self._r}.swipeText'), 165 maxwidth=100, 166 textcolor=clr2, 167 value=False, 168 scale=0.9, 169 ) 170 make_radio_group( 171 (cb1, cb2), ('joystick', 'swipe'), cur_val, self._movement_changed 172 ) 173 v -= 50 174 ConfigNumberEdit( 175 parent=self._subcontainer, 176 position=(h, v), 177 xoffset=hoffs2 + 65, 178 configkey='Touch Controls Scale Movement', 179 displayname=bui.Lstr( 180 resource=f'{self._r}.movementControlScaleText' 181 ), 182 changesound=False, 183 minval=0.1, 184 maxval=4.0, 185 increment=0.1, 186 ) 187 v -= 50 188 cur_val = bui.app.config.get('Touch Action Control Type', 'buttons') 189 bui.textwidget( 190 parent=self._subcontainer, 191 position=(h, v - 2), 192 size=(0, 30), 193 text=bui.Lstr(resource=f'{self._r}.actionsText'), 194 maxwidth=190, 195 color=clr, 196 v_align='center', 197 ) 198 cb1 = bui.checkboxwidget( 199 parent=self._subcontainer, 200 position=(h + hoffs + 220, v), 201 size=(170, 30), 202 text=bui.Lstr(resource=f'{self._r}.buttonsText'), 203 maxwidth=100, 204 textcolor=clr2, 205 scale=0.9, 206 ) 207 cb2 = bui.checkboxwidget( 208 parent=self._subcontainer, 209 position=(h + hoffs + 357, v), 210 size=(170, 30), 211 text=bui.Lstr(resource=f'{self._r}.swipeText'), 212 maxwidth=100, 213 textcolor=clr2, 214 scale=0.9, 215 ) 216 make_radio_group( 217 (cb1, cb2), ('buttons', 'swipe'), cur_val, self._actions_changed 218 ) 219 v -= 50 220 ConfigNumberEdit( 221 parent=self._subcontainer, 222 position=(h, v), 223 xoffset=hoffs2 + 65, 224 configkey='Touch Controls Scale Actions', 225 displayname=bui.Lstr(resource=f'{self._r}.actionControlScaleText'), 226 changesound=False, 227 minval=0.1, 228 maxval=4.0, 229 increment=0.1, 230 ) 231 232 v -= 50 233 bui.textwidget( 234 parent=self._subcontainer, 235 position=(h, v - 2), 236 size=(0, 30), 237 text=bui.Lstr(resource=f'{self._r}.swipeControlsHiddenText'), 238 maxwidth=190, 239 color=clr, 240 v_align='center', 241 ) 242 243 ConfigCheckBox( 244 parent=self._subcontainer, 245 position=(h + hoffs3, v), 246 size=(100, 30), 247 maxwidth=400, 248 configkey='Touch Controls Swipe Hidden', 249 displayname='', 250 ) 251 v -= 65 252 253 bui.buttonwidget( 254 parent=self._subcontainer, 255 position=(self._sub_width * 0.5 - 70, v), 256 size=(170, 60), 257 label=bui.Lstr(resource=f'{self._r}.resetText'), 258 scale=0.75, 259 on_activate_call=self._reset, 260 ) 261 262 bui.textwidget( 263 parent=self._root_widget, 264 position=(self._width * 0.5, 38), 265 size=(0, 0), 266 h_align='center', 267 text=bui.Lstr(resource=f'{self._r}.dragControlsText'), 268 maxwidth=self._width * 0.8, 269 scale=0.65, 270 color=(1, 1, 1, 0.4), 271 ) 272 273 def _actions_changed(self, v: str) -> None: 274 cfg = bui.app.config 275 cfg['Touch Action Control Type'] = v 276 cfg.apply_and_commit() 277 278 def _movement_changed(self, v: str) -> None: 279 cfg = bui.app.config 280 cfg['Touch Movement Control Type'] = v 281 cfg.apply_and_commit() 282 283 def _reset(self) -> None: 284 cfg = bui.app.config 285 cfgkeys = [ 286 'Touch Movement Control Type', 287 'Touch Action Control Type', 288 'Touch Controls Scale', 289 'Touch Controls Scale Movement', 290 'Touch Controls Scale Actions', 291 'Touch Controls Swipe Hidden', 292 'Touch DPad X', 293 'Touch DPad Y', 294 'Touch Buttons X', 295 'Touch Buttons Y', 296 ] 297 for cfgkey in cfgkeys: 298 if cfgkey in cfg: 299 del cfg[cfgkey] 300 cfg.apply_and_commit() 301 bui.apptimer(0, self._build_gui)
class
TouchscreenSettingsWindow(bauiv1._uitypes.MainWindow):
13class TouchscreenSettingsWindow(bui.MainWindow): 14 """Settings window for touchscreens.""" 15 16 def __del__(self) -> None: 17 bs.set_touchscreen_editing(False) 18 19 def __init__( 20 self, 21 transition: str | None = 'in_right', 22 origin_widget: bui.Widget | None = None, 23 ) -> None: 24 self._width = 780 25 self._height = 380 26 self._r = 'configTouchscreenWindow' 27 28 bs.set_touchscreen_editing(True) 29 30 assert bui.app.classic is not None 31 uiscale = bui.app.ui_v1.uiscale 32 super().__init__( 33 root_widget=bui.containerwidget( 34 size=(self._width, self._height), 35 scale=( 36 1.9 37 if uiscale is bui.UIScale.SMALL 38 else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.2 39 ), 40 toolbar_visibility=( 41 'menu_minimal' 42 if uiscale is bui.UIScale.SMALL 43 else 'menu_full' 44 ), 45 stack_offset=( 46 (0, -20) if uiscale is bui.UIScale.SMALL else (0, 0) 47 ), 48 ), 49 transition=transition, 50 origin_widget=origin_widget, 51 ) 52 53 if uiscale is bui.UIScale.SMALL: 54 bui.containerwidget( 55 edit=self._root_widget, on_cancel_call=self.main_window_back 56 ) 57 else: 58 btn = bui.buttonwidget( 59 parent=self._root_widget, 60 position=(55, self._height - 60), 61 size=(60, 60), 62 label=bui.charstr(bui.SpecialChar.BACK), 63 button_type='backSmall', 64 scale=0.8, 65 on_activate_call=self.main_window_back, 66 ) 67 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 68 69 bui.textwidget( 70 parent=self._root_widget, 71 position=(25, self._height - 57), 72 size=(self._width, 25), 73 text=bui.Lstr(resource=f'{self._r}.titleText'), 74 color=bui.app.ui_v1.title_color, 75 maxwidth=280, 76 h_align='center', 77 v_align='center', 78 ) 79 80 self._scroll_width = self._width - 100 81 self._scroll_height = self._height - 110 82 self._sub_width = self._scroll_width - 20 83 self._sub_height = 360 84 85 self._scrollwidget = bui.scrollwidget( 86 parent=self._root_widget, 87 position=( 88 (self._width - self._scroll_width) * 0.5, 89 self._height - 65 - self._scroll_height, 90 ), 91 size=(self._scroll_width, self._scroll_height), 92 claims_left_right=True, 93 selection_loops_to_parent=True, 94 ) 95 self._subcontainer = bui.containerwidget( 96 parent=self._scrollwidget, 97 size=(self._sub_width, self._sub_height), 98 background=False, 99 claims_left_right=True, 100 selection_loops_to_parent=True, 101 ) 102 self._build_gui() 103 104 @override 105 def get_main_window_state(self) -> bui.MainWindowState: 106 # Support recreating our window for back/refresh purposes. 107 cls = type(self) 108 return bui.BasicMainWindowState( 109 create_call=lambda transition, origin_widget: cls( 110 transition=transition, origin_widget=origin_widget 111 ) 112 ) 113 114 def _build_gui(self) -> None: 115 # pylint: disable=too-many-locals 116 from bauiv1lib.config import ConfigNumberEdit, ConfigCheckBox 117 from bauiv1lib.radiogroup import make_radio_group 118 119 # Clear anything already there. 120 children = self._subcontainer.get_children() 121 for child in children: 122 child.delete() 123 h = 30 124 hoffs = 100 125 hoffs2 = 70 126 hoffs3 = 320 127 v = self._sub_height - 85 128 clr = (0.8, 0.8, 0.8, 1.0) 129 clr2 = (0.8, 0.8, 0.8) 130 bui.textwidget( 131 parent=self._subcontainer, 132 position=(self._sub_width * 0.5, v + 63), 133 size=(0, 0), 134 text=bui.Lstr(resource=f'{self._r}.swipeInfoText'), 135 flatness=1.0, 136 color=(0, 0.9, 0.1, 0.7), 137 maxwidth=self._sub_width * 0.9, 138 scale=0.55, 139 h_align='center', 140 v_align='center', 141 ) 142 cur_val = bui.app.config.get('Touch Movement Control Type', 'swipe') 143 bui.textwidget( 144 parent=self._subcontainer, 145 position=(h, v - 2), 146 size=(0, 30), 147 text=bui.Lstr(resource=f'{self._r}.movementText'), 148 maxwidth=190, 149 color=clr, 150 v_align='center', 151 ) 152 cb1 = bui.checkboxwidget( 153 parent=self._subcontainer, 154 position=(h + hoffs + 220, v), 155 size=(170, 30), 156 text=bui.Lstr(resource=f'{self._r}.joystickText'), 157 maxwidth=100, 158 textcolor=clr2, 159 scale=0.9, 160 ) 161 cb2 = bui.checkboxwidget( 162 parent=self._subcontainer, 163 position=(h + hoffs + 357, v), 164 size=(170, 30), 165 text=bui.Lstr(resource=f'{self._r}.swipeText'), 166 maxwidth=100, 167 textcolor=clr2, 168 value=False, 169 scale=0.9, 170 ) 171 make_radio_group( 172 (cb1, cb2), ('joystick', 'swipe'), cur_val, self._movement_changed 173 ) 174 v -= 50 175 ConfigNumberEdit( 176 parent=self._subcontainer, 177 position=(h, v), 178 xoffset=hoffs2 + 65, 179 configkey='Touch Controls Scale Movement', 180 displayname=bui.Lstr( 181 resource=f'{self._r}.movementControlScaleText' 182 ), 183 changesound=False, 184 minval=0.1, 185 maxval=4.0, 186 increment=0.1, 187 ) 188 v -= 50 189 cur_val = bui.app.config.get('Touch Action Control Type', 'buttons') 190 bui.textwidget( 191 parent=self._subcontainer, 192 position=(h, v - 2), 193 size=(0, 30), 194 text=bui.Lstr(resource=f'{self._r}.actionsText'), 195 maxwidth=190, 196 color=clr, 197 v_align='center', 198 ) 199 cb1 = bui.checkboxwidget( 200 parent=self._subcontainer, 201 position=(h + hoffs + 220, v), 202 size=(170, 30), 203 text=bui.Lstr(resource=f'{self._r}.buttonsText'), 204 maxwidth=100, 205 textcolor=clr2, 206 scale=0.9, 207 ) 208 cb2 = bui.checkboxwidget( 209 parent=self._subcontainer, 210 position=(h + hoffs + 357, v), 211 size=(170, 30), 212 text=bui.Lstr(resource=f'{self._r}.swipeText'), 213 maxwidth=100, 214 textcolor=clr2, 215 scale=0.9, 216 ) 217 make_radio_group( 218 (cb1, cb2), ('buttons', 'swipe'), cur_val, self._actions_changed 219 ) 220 v -= 50 221 ConfigNumberEdit( 222 parent=self._subcontainer, 223 position=(h, v), 224 xoffset=hoffs2 + 65, 225 configkey='Touch Controls Scale Actions', 226 displayname=bui.Lstr(resource=f'{self._r}.actionControlScaleText'), 227 changesound=False, 228 minval=0.1, 229 maxval=4.0, 230 increment=0.1, 231 ) 232 233 v -= 50 234 bui.textwidget( 235 parent=self._subcontainer, 236 position=(h, v - 2), 237 size=(0, 30), 238 text=bui.Lstr(resource=f'{self._r}.swipeControlsHiddenText'), 239 maxwidth=190, 240 color=clr, 241 v_align='center', 242 ) 243 244 ConfigCheckBox( 245 parent=self._subcontainer, 246 position=(h + hoffs3, v), 247 size=(100, 30), 248 maxwidth=400, 249 configkey='Touch Controls Swipe Hidden', 250 displayname='', 251 ) 252 v -= 65 253 254 bui.buttonwidget( 255 parent=self._subcontainer, 256 position=(self._sub_width * 0.5 - 70, v), 257 size=(170, 60), 258 label=bui.Lstr(resource=f'{self._r}.resetText'), 259 scale=0.75, 260 on_activate_call=self._reset, 261 ) 262 263 bui.textwidget( 264 parent=self._root_widget, 265 position=(self._width * 0.5, 38), 266 size=(0, 0), 267 h_align='center', 268 text=bui.Lstr(resource=f'{self._r}.dragControlsText'), 269 maxwidth=self._width * 0.8, 270 scale=0.65, 271 color=(1, 1, 1, 0.4), 272 ) 273 274 def _actions_changed(self, v: str) -> None: 275 cfg = bui.app.config 276 cfg['Touch Action Control Type'] = v 277 cfg.apply_and_commit() 278 279 def _movement_changed(self, v: str) -> None: 280 cfg = bui.app.config 281 cfg['Touch Movement Control Type'] = v 282 cfg.apply_and_commit() 283 284 def _reset(self) -> None: 285 cfg = bui.app.config 286 cfgkeys = [ 287 'Touch Movement Control Type', 288 'Touch Action Control Type', 289 'Touch Controls Scale', 290 'Touch Controls Scale Movement', 291 'Touch Controls Scale Actions', 292 'Touch Controls Swipe Hidden', 293 'Touch DPad X', 294 'Touch DPad Y', 295 'Touch Buttons X', 296 'Touch Buttons Y', 297 ] 298 for cfgkey in cfgkeys: 299 if cfgkey in cfg: 300 del cfg[cfgkey] 301 cfg.apply_and_commit() 302 bui.apptimer(0, self._build_gui)
Settings window for touchscreens.
TouchscreenSettingsWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
19 def __init__( 20 self, 21 transition: str | None = 'in_right', 22 origin_widget: bui.Widget | None = None, 23 ) -> None: 24 self._width = 780 25 self._height = 380 26 self._r = 'configTouchscreenWindow' 27 28 bs.set_touchscreen_editing(True) 29 30 assert bui.app.classic is not None 31 uiscale = bui.app.ui_v1.uiscale 32 super().__init__( 33 root_widget=bui.containerwidget( 34 size=(self._width, self._height), 35 scale=( 36 1.9 37 if uiscale is bui.UIScale.SMALL 38 else 1.55 if uiscale is bui.UIScale.MEDIUM else 1.2 39 ), 40 toolbar_visibility=( 41 'menu_minimal' 42 if uiscale is bui.UIScale.SMALL 43 else 'menu_full' 44 ), 45 stack_offset=( 46 (0, -20) if uiscale is bui.UIScale.SMALL else (0, 0) 47 ), 48 ), 49 transition=transition, 50 origin_widget=origin_widget, 51 ) 52 53 if uiscale is bui.UIScale.SMALL: 54 bui.containerwidget( 55 edit=self._root_widget, on_cancel_call=self.main_window_back 56 ) 57 else: 58 btn = bui.buttonwidget( 59 parent=self._root_widget, 60 position=(55, self._height - 60), 61 size=(60, 60), 62 label=bui.charstr(bui.SpecialChar.BACK), 63 button_type='backSmall', 64 scale=0.8, 65 on_activate_call=self.main_window_back, 66 ) 67 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 68 69 bui.textwidget( 70 parent=self._root_widget, 71 position=(25, self._height - 57), 72 size=(self._width, 25), 73 text=bui.Lstr(resource=f'{self._r}.titleText'), 74 color=bui.app.ui_v1.title_color, 75 maxwidth=280, 76 h_align='center', 77 v_align='center', 78 ) 79 80 self._scroll_width = self._width - 100 81 self._scroll_height = self._height - 110 82 self._sub_width = self._scroll_width - 20 83 self._sub_height = 360 84 85 self._scrollwidget = bui.scrollwidget( 86 parent=self._root_widget, 87 position=( 88 (self._width - self._scroll_width) * 0.5, 89 self._height - 65 - self._scroll_height, 90 ), 91 size=(self._scroll_width, self._scroll_height), 92 claims_left_right=True, 93 selection_loops_to_parent=True, 94 ) 95 self._subcontainer = bui.containerwidget( 96 parent=self._scrollwidget, 97 size=(self._sub_width, self._sub_height), 98 background=False, 99 claims_left_right=True, 100 selection_loops_to_parent=True, 101 ) 102 self._build_gui()
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.
104 @override 105 def get_main_window_state(self) -> bui.MainWindowState: 106 # Support recreating our window for back/refresh purposes. 107 cls = type(self) 108 return bui.BasicMainWindowState( 109 create_call=lambda transition, origin_widget: cls( 110 transition=transition, origin_widget=origin_widget 111 ) 112 )
Return a WindowState to recreate this window, if supported.