bauiv1lib.settings.remoteapp
Settings UI functionality related to the remote app.
1# Released under the MIT License. See LICENSE for details. 2# 3"""Settings UI functionality related to the remote app.""" 4 5from __future__ import annotations 6 7from typing import override 8 9import bauiv1 as bui 10 11 12class RemoteAppSettingsWindow(bui.MainWindow): 13 """Window showing info/settings related to the remote app.""" 14 15 def __init__( 16 self, 17 transition: str | None = 'in_right', 18 origin_widget: bui.Widget | None = None, 19 ) -> None: 20 self._r = 'connectMobileDevicesWindow' 21 app = bui.app 22 uiscale = app.ui_v1.uiscale 23 width = 1200 if uiscale is bui.UIScale.SMALL else 700 24 height = 800 if uiscale is bui.UIScale.SMALL else 390 25 # yoffs = -48 if uiscale is bui.UIScale.SMALL else 0 26 spacing = 40 27 assert bui.app.classic is not None 28 29 # Do some fancy math to fill all available screen area up to the 30 # size of our backing container. This lets us fit to the exact 31 # screen shape at small ui scale. 32 screensize = bui.get_virtual_screen_size() 33 scale = ( 34 1.75 35 if uiscale is bui.UIScale.SMALL 36 else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0 37 ) 38 # Calc screen size in our local container space and clamp to a 39 # bit smaller than our container size. 40 # target_width = min(width - 60, screensize[0] / scale) 41 target_height = min(height - 70, screensize[1] / scale) 42 43 # To get top/left coords, go to the center of our window and 44 # offset by half the width/height of our target area. 45 yoffs = 0.5 * height + 0.5 * target_height + 30.0 46 47 super().__init__( 48 root_widget=bui.containerwidget( 49 size=(width, height), 50 toolbar_visibility=( 51 'menu_minimal' 52 if uiscale is bui.UIScale.SMALL 53 else 'menu_full' 54 ), 55 scale=scale, 56 ), 57 transition=transition, 58 origin_widget=origin_widget, 59 # We're affected by screen size only at small ui-scale. 60 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 61 ) 62 if uiscale is bui.UIScale.SMALL: 63 bui.containerwidget( 64 edit=self.get_root_widget(), 65 on_cancel_call=self.main_window_back, 66 ) 67 else: 68 btn = bui.buttonwidget( 69 parent=self._root_widget, 70 position=(40, yoffs - 67), 71 size=(60, 60), 72 scale=0.8, 73 label=bui.charstr(bui.SpecialChar.BACK), 74 button_type='backSmall', 75 text_scale=1.1, 76 autoselect=True, 77 on_activate_call=self.main_window_back, 78 ) 79 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 80 81 bui.textwidget( 82 parent=self._root_widget, 83 position=( 84 width * 0.5, 85 yoffs - (62 if uiscale is bui.UIScale.SMALL else 42), 86 ), 87 size=(0, 0), 88 text=bui.Lstr(resource=f'{self._r}.titleText'), 89 maxwidth=370, 90 color=bui.app.ui_v1.title_color, 91 scale=0.8, 92 h_align='center', 93 v_align='center', 94 ) 95 96 # Generally center the rest of our contents vertically. 97 v = height * 0.5 + 140.0 98 v -= spacing * 1.2 99 bui.textwidget( 100 parent=self._root_widget, 101 position=(15, v - 26), 102 size=(width - 30, 30), 103 maxwidth=width * 0.95, 104 color=(0.7, 0.9, 0.7, 1.0), 105 scale=0.8, 106 text=bui.Lstr( 107 resource=f'{self._r}.explanationText', 108 subs=[ 109 ('${APP_NAME}', bui.Lstr(resource='titleText')), 110 ('${REMOTE_APP_NAME}', bui.get_remote_app_name()), 111 ], 112 ), 113 max_height=100, 114 h_align='center', 115 v_align='center', 116 ) 117 v -= 90 118 119 # Update: now we just show link to the remote webpage. 120 bui.textwidget( 121 parent=self._root_widget, 122 position=(width * 0.5, v + 5), 123 size=(0, 0), 124 color=(0.7, 0.9, 0.7, 1.0), 125 scale=1.4, 126 text='bombsquadgame.com/remote', 127 maxwidth=width * 0.95, 128 max_height=60, 129 h_align='center', 130 v_align='center', 131 ) 132 v -= 30 133 134 bui.textwidget( 135 parent=self._root_widget, 136 position=(width * 0.5, v - 35), 137 size=(0, 0), 138 color=(0.7, 0.9, 0.7, 0.8), 139 scale=0.65, 140 text=bui.Lstr(resource=f'{self._r}.bestResultsText'), 141 maxwidth=width * 0.95, 142 max_height=100, 143 h_align='center', 144 v_align='center', 145 ) 146 147 bui.checkboxwidget( 148 parent=self._root_widget, 149 position=(width * 0.5 - 150, v - 116), 150 size=(300, 30), 151 maxwidth=300, 152 scale=0.8, 153 value=not bui.app.config.resolve('Enable Remote App'), 154 autoselect=True, 155 text=bui.Lstr(resource='disableRemoteAppConnectionsText'), 156 on_value_change_call=self._on_check_changed, 157 ) 158 159 @override 160 def get_main_window_state(self) -> bui.MainWindowState: 161 # Support recreating our window for back/refresh purposes. 162 cls = type(self) 163 return bui.BasicMainWindowState( 164 create_call=lambda transition, origin_widget: cls( 165 transition=transition, origin_widget=origin_widget 166 ) 167 ) 168 169 def _on_check_changed(self, value: bool) -> None: 170 cfg = bui.app.config 171 cfg['Enable Remote App'] = not value 172 cfg.apply_and_commit()
class
RemoteAppSettingsWindow(bauiv1._uitypes.MainWindow):
13class RemoteAppSettingsWindow(bui.MainWindow): 14 """Window showing info/settings related to the remote app.""" 15 16 def __init__( 17 self, 18 transition: str | None = 'in_right', 19 origin_widget: bui.Widget | None = None, 20 ) -> None: 21 self._r = 'connectMobileDevicesWindow' 22 app = bui.app 23 uiscale = app.ui_v1.uiscale 24 width = 1200 if uiscale is bui.UIScale.SMALL else 700 25 height = 800 if uiscale is bui.UIScale.SMALL else 390 26 # yoffs = -48 if uiscale is bui.UIScale.SMALL else 0 27 spacing = 40 28 assert bui.app.classic is not None 29 30 # Do some fancy math to fill all available screen area up to the 31 # size of our backing container. This lets us fit to the exact 32 # screen shape at small ui scale. 33 screensize = bui.get_virtual_screen_size() 34 scale = ( 35 1.75 36 if uiscale is bui.UIScale.SMALL 37 else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0 38 ) 39 # Calc screen size in our local container space and clamp to a 40 # bit smaller than our container size. 41 # target_width = min(width - 60, screensize[0] / scale) 42 target_height = min(height - 70, screensize[1] / scale) 43 44 # To get top/left coords, go to the center of our window and 45 # offset by half the width/height of our target area. 46 yoffs = 0.5 * height + 0.5 * target_height + 30.0 47 48 super().__init__( 49 root_widget=bui.containerwidget( 50 size=(width, height), 51 toolbar_visibility=( 52 'menu_minimal' 53 if uiscale is bui.UIScale.SMALL 54 else 'menu_full' 55 ), 56 scale=scale, 57 ), 58 transition=transition, 59 origin_widget=origin_widget, 60 # We're affected by screen size only at small ui-scale. 61 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 62 ) 63 if uiscale is bui.UIScale.SMALL: 64 bui.containerwidget( 65 edit=self.get_root_widget(), 66 on_cancel_call=self.main_window_back, 67 ) 68 else: 69 btn = bui.buttonwidget( 70 parent=self._root_widget, 71 position=(40, yoffs - 67), 72 size=(60, 60), 73 scale=0.8, 74 label=bui.charstr(bui.SpecialChar.BACK), 75 button_type='backSmall', 76 text_scale=1.1, 77 autoselect=True, 78 on_activate_call=self.main_window_back, 79 ) 80 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 81 82 bui.textwidget( 83 parent=self._root_widget, 84 position=( 85 width * 0.5, 86 yoffs - (62 if uiscale is bui.UIScale.SMALL else 42), 87 ), 88 size=(0, 0), 89 text=bui.Lstr(resource=f'{self._r}.titleText'), 90 maxwidth=370, 91 color=bui.app.ui_v1.title_color, 92 scale=0.8, 93 h_align='center', 94 v_align='center', 95 ) 96 97 # Generally center the rest of our contents vertically. 98 v = height * 0.5 + 140.0 99 v -= spacing * 1.2 100 bui.textwidget( 101 parent=self._root_widget, 102 position=(15, v - 26), 103 size=(width - 30, 30), 104 maxwidth=width * 0.95, 105 color=(0.7, 0.9, 0.7, 1.0), 106 scale=0.8, 107 text=bui.Lstr( 108 resource=f'{self._r}.explanationText', 109 subs=[ 110 ('${APP_NAME}', bui.Lstr(resource='titleText')), 111 ('${REMOTE_APP_NAME}', bui.get_remote_app_name()), 112 ], 113 ), 114 max_height=100, 115 h_align='center', 116 v_align='center', 117 ) 118 v -= 90 119 120 # Update: now we just show link to the remote webpage. 121 bui.textwidget( 122 parent=self._root_widget, 123 position=(width * 0.5, v + 5), 124 size=(0, 0), 125 color=(0.7, 0.9, 0.7, 1.0), 126 scale=1.4, 127 text='bombsquadgame.com/remote', 128 maxwidth=width * 0.95, 129 max_height=60, 130 h_align='center', 131 v_align='center', 132 ) 133 v -= 30 134 135 bui.textwidget( 136 parent=self._root_widget, 137 position=(width * 0.5, v - 35), 138 size=(0, 0), 139 color=(0.7, 0.9, 0.7, 0.8), 140 scale=0.65, 141 text=bui.Lstr(resource=f'{self._r}.bestResultsText'), 142 maxwidth=width * 0.95, 143 max_height=100, 144 h_align='center', 145 v_align='center', 146 ) 147 148 bui.checkboxwidget( 149 parent=self._root_widget, 150 position=(width * 0.5 - 150, v - 116), 151 size=(300, 30), 152 maxwidth=300, 153 scale=0.8, 154 value=not bui.app.config.resolve('Enable Remote App'), 155 autoselect=True, 156 text=bui.Lstr(resource='disableRemoteAppConnectionsText'), 157 on_value_change_call=self._on_check_changed, 158 ) 159 160 @override 161 def get_main_window_state(self) -> bui.MainWindowState: 162 # Support recreating our window for back/refresh purposes. 163 cls = type(self) 164 return bui.BasicMainWindowState( 165 create_call=lambda transition, origin_widget: cls( 166 transition=transition, origin_widget=origin_widget 167 ) 168 ) 169 170 def _on_check_changed(self, value: bool) -> None: 171 cfg = bui.app.config 172 cfg['Enable Remote App'] = not value 173 cfg.apply_and_commit()
Window showing info/settings related to the remote app.
RemoteAppSettingsWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
16 def __init__( 17 self, 18 transition: str | None = 'in_right', 19 origin_widget: bui.Widget | None = None, 20 ) -> None: 21 self._r = 'connectMobileDevicesWindow' 22 app = bui.app 23 uiscale = app.ui_v1.uiscale 24 width = 1200 if uiscale is bui.UIScale.SMALL else 700 25 height = 800 if uiscale is bui.UIScale.SMALL else 390 26 # yoffs = -48 if uiscale is bui.UIScale.SMALL else 0 27 spacing = 40 28 assert bui.app.classic is not None 29 30 # Do some fancy math to fill all available screen area up to the 31 # size of our backing container. This lets us fit to the exact 32 # screen shape at small ui scale. 33 screensize = bui.get_virtual_screen_size() 34 scale = ( 35 1.75 36 if uiscale is bui.UIScale.SMALL 37 else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0 38 ) 39 # Calc screen size in our local container space and clamp to a 40 # bit smaller than our container size. 41 # target_width = min(width - 60, screensize[0] / scale) 42 target_height = min(height - 70, screensize[1] / scale) 43 44 # To get top/left coords, go to the center of our window and 45 # offset by half the width/height of our target area. 46 yoffs = 0.5 * height + 0.5 * target_height + 30.0 47 48 super().__init__( 49 root_widget=bui.containerwidget( 50 size=(width, height), 51 toolbar_visibility=( 52 'menu_minimal' 53 if uiscale is bui.UIScale.SMALL 54 else 'menu_full' 55 ), 56 scale=scale, 57 ), 58 transition=transition, 59 origin_widget=origin_widget, 60 # We're affected by screen size only at small ui-scale. 61 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 62 ) 63 if uiscale is bui.UIScale.SMALL: 64 bui.containerwidget( 65 edit=self.get_root_widget(), 66 on_cancel_call=self.main_window_back, 67 ) 68 else: 69 btn = bui.buttonwidget( 70 parent=self._root_widget, 71 position=(40, yoffs - 67), 72 size=(60, 60), 73 scale=0.8, 74 label=bui.charstr(bui.SpecialChar.BACK), 75 button_type='backSmall', 76 text_scale=1.1, 77 autoselect=True, 78 on_activate_call=self.main_window_back, 79 ) 80 bui.containerwidget(edit=self._root_widget, cancel_button=btn) 81 82 bui.textwidget( 83 parent=self._root_widget, 84 position=( 85 width * 0.5, 86 yoffs - (62 if uiscale is bui.UIScale.SMALL else 42), 87 ), 88 size=(0, 0), 89 text=bui.Lstr(resource=f'{self._r}.titleText'), 90 maxwidth=370, 91 color=bui.app.ui_v1.title_color, 92 scale=0.8, 93 h_align='center', 94 v_align='center', 95 ) 96 97 # Generally center the rest of our contents vertically. 98 v = height * 0.5 + 140.0 99 v -= spacing * 1.2 100 bui.textwidget( 101 parent=self._root_widget, 102 position=(15, v - 26), 103 size=(width - 30, 30), 104 maxwidth=width * 0.95, 105 color=(0.7, 0.9, 0.7, 1.0), 106 scale=0.8, 107 text=bui.Lstr( 108 resource=f'{self._r}.explanationText', 109 subs=[ 110 ('${APP_NAME}', bui.Lstr(resource='titleText')), 111 ('${REMOTE_APP_NAME}', bui.get_remote_app_name()), 112 ], 113 ), 114 max_height=100, 115 h_align='center', 116 v_align='center', 117 ) 118 v -= 90 119 120 # Update: now we just show link to the remote webpage. 121 bui.textwidget( 122 parent=self._root_widget, 123 position=(width * 0.5, v + 5), 124 size=(0, 0), 125 color=(0.7, 0.9, 0.7, 1.0), 126 scale=1.4, 127 text='bombsquadgame.com/remote', 128 maxwidth=width * 0.95, 129 max_height=60, 130 h_align='center', 131 v_align='center', 132 ) 133 v -= 30 134 135 bui.textwidget( 136 parent=self._root_widget, 137 position=(width * 0.5, v - 35), 138 size=(0, 0), 139 color=(0.7, 0.9, 0.7, 0.8), 140 scale=0.65, 141 text=bui.Lstr(resource=f'{self._r}.bestResultsText'), 142 maxwidth=width * 0.95, 143 max_height=100, 144 h_align='center', 145 v_align='center', 146 ) 147 148 bui.checkboxwidget( 149 parent=self._root_widget, 150 position=(width * 0.5 - 150, v - 116), 151 size=(300, 30), 152 maxwidth=300, 153 scale=0.8, 154 value=not bui.app.config.resolve('Enable Remote App'), 155 autoselect=True, 156 text=bui.Lstr(resource='disableRemoteAppConnectionsText'), 157 on_value_change_call=self._on_check_changed, 158 )
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.
160 @override 161 def get_main_window_state(self) -> bui.MainWindowState: 162 # Support recreating our window for back/refresh purposes. 163 cls = type(self) 164 return bui.BasicMainWindowState( 165 create_call=lambda transition, origin_widget: cls( 166 transition=transition, origin_widget=origin_widget 167 ) 168 )
Return a WindowState to recreate this window, if supported.