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 = 800 if uiscale is bui.UIScale.SMALL else 700
 24        height = 390
 25        spacing = 40
 26        assert bui.app.classic is not None
 27        super().__init__(
 28            root_widget=bui.containerwidget(
 29                size=(width, height),
 30                toolbar_visibility=(
 31                    'menu_minimal'
 32                    if uiscale is bui.UIScale.SMALL
 33                    else 'menu_full'
 34                ),
 35                scale=(
 36                    1.76
 37                    if uiscale is bui.UIScale.SMALL
 38                    else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0
 39                ),
 40                stack_offset=(
 41                    (-10, 0) if uiscale is bui.UIScale.SMALL else (0, 0)
 42                ),
 43            ),
 44            transition=transition,
 45            origin_widget=origin_widget,
 46        )
 47        if uiscale is bui.UIScale.SMALL:
 48            bui.containerwidget(
 49                edit=self.get_root_widget(),
 50                on_cancel_call=self.main_window_back,
 51            )
 52        else:
 53            btn = bui.buttonwidget(
 54                parent=self._root_widget,
 55                position=(40, height - 67),
 56                size=(140, 65),
 57                scale=0.8,
 58                label=bui.Lstr(resource='backText'),
 59                button_type='back',
 60                text_scale=1.1,
 61                autoselect=True,
 62                on_activate_call=self.main_window_back,
 63            )
 64            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 65            bui.buttonwidget(
 66                edit=btn,
 67                button_type='backSmall',
 68                size=(60, 60),
 69                label=bui.charstr(bui.SpecialChar.BACK),
 70            )
 71
 72        bui.textwidget(
 73            parent=self._root_widget,
 74            position=(width * 0.5, height - 42),
 75            size=(0, 0),
 76            text=bui.Lstr(resource=f'{self._r}.titleText'),
 77            maxwidth=370,
 78            color=bui.app.ui_v1.title_color,
 79            scale=0.8,
 80            h_align='center',
 81            v_align='center',
 82        )
 83
 84        v = height - 70.0
 85        v -= spacing * 1.2
 86        bui.textwidget(
 87            parent=self._root_widget,
 88            position=(15, v - 26),
 89            size=(width - 30, 30),
 90            maxwidth=width * 0.95,
 91            color=(0.7, 0.9, 0.7, 1.0),
 92            scale=0.8,
 93            text=bui.Lstr(
 94                resource=f'{self._r}.explanationText',
 95                subs=[
 96                    ('${APP_NAME}', bui.Lstr(resource='titleText')),
 97                    ('${REMOTE_APP_NAME}', bui.get_remote_app_name()),
 98                ],
 99            ),
100            max_height=100,
101            h_align='center',
102            v_align='center',
103        )
104        v -= 90
105
106        # Update: now we just show link to the remote webpage.
107        bui.textwidget(
108            parent=self._root_widget,
109            position=(width * 0.5, v + 5),
110            size=(0, 0),
111            color=(0.7, 0.9, 0.7, 1.0),
112            scale=1.4,
113            text='bombsquadgame.com/remote',
114            maxwidth=width * 0.95,
115            max_height=60,
116            h_align='center',
117            v_align='center',
118        )
119        v -= 30
120
121        bui.textwidget(
122            parent=self._root_widget,
123            position=(width * 0.5, v - 35),
124            size=(0, 0),
125            color=(0.7, 0.9, 0.7, 0.8),
126            scale=0.65,
127            text=bui.Lstr(resource=f'{self._r}.bestResultsText'),
128            maxwidth=width * 0.95,
129            max_height=height * 0.19,
130            h_align='center',
131            v_align='center',
132        )
133
134        bui.checkboxwidget(
135            parent=self._root_widget,
136            position=(width * 0.5 - 150, v - 116),
137            size=(300, 30),
138            maxwidth=300,
139            scale=0.8,
140            value=not bui.app.config.resolve('Enable Remote App'),
141            autoselect=True,
142            text=bui.Lstr(resource='disableRemoteAppConnectionsText'),
143            on_value_change_call=self._on_check_changed,
144        )
145
146    @override
147    def get_main_window_state(self) -> bui.MainWindowState:
148        # Support recreating our window for back/refresh purposes.
149        cls = type(self)
150        return bui.BasicMainWindowState(
151            create_call=lambda transition, origin_widget: cls(
152                transition=transition, origin_widget=origin_widget
153            )
154        )
155
156    def _on_check_changed(self, value: bool) -> None:
157        cfg = bui.app.config
158        cfg['Enable Remote App'] = not value
159        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 = 800 if uiscale is bui.UIScale.SMALL else 700
 25        height = 390
 26        spacing = 40
 27        assert bui.app.classic is not None
 28        super().__init__(
 29            root_widget=bui.containerwidget(
 30                size=(width, height),
 31                toolbar_visibility=(
 32                    'menu_minimal'
 33                    if uiscale is bui.UIScale.SMALL
 34                    else 'menu_full'
 35                ),
 36                scale=(
 37                    1.76
 38                    if uiscale is bui.UIScale.SMALL
 39                    else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0
 40                ),
 41                stack_offset=(
 42                    (-10, 0) if uiscale is bui.UIScale.SMALL else (0, 0)
 43                ),
 44            ),
 45            transition=transition,
 46            origin_widget=origin_widget,
 47        )
 48        if uiscale is bui.UIScale.SMALL:
 49            bui.containerwidget(
 50                edit=self.get_root_widget(),
 51                on_cancel_call=self.main_window_back,
 52            )
 53        else:
 54            btn = bui.buttonwidget(
 55                parent=self._root_widget,
 56                position=(40, height - 67),
 57                size=(140, 65),
 58                scale=0.8,
 59                label=bui.Lstr(resource='backText'),
 60                button_type='back',
 61                text_scale=1.1,
 62                autoselect=True,
 63                on_activate_call=self.main_window_back,
 64            )
 65            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 66            bui.buttonwidget(
 67                edit=btn,
 68                button_type='backSmall',
 69                size=(60, 60),
 70                label=bui.charstr(bui.SpecialChar.BACK),
 71            )
 72
 73        bui.textwidget(
 74            parent=self._root_widget,
 75            position=(width * 0.5, height - 42),
 76            size=(0, 0),
 77            text=bui.Lstr(resource=f'{self._r}.titleText'),
 78            maxwidth=370,
 79            color=bui.app.ui_v1.title_color,
 80            scale=0.8,
 81            h_align='center',
 82            v_align='center',
 83        )
 84
 85        v = height - 70.0
 86        v -= spacing * 1.2
 87        bui.textwidget(
 88            parent=self._root_widget,
 89            position=(15, v - 26),
 90            size=(width - 30, 30),
 91            maxwidth=width * 0.95,
 92            color=(0.7, 0.9, 0.7, 1.0),
 93            scale=0.8,
 94            text=bui.Lstr(
 95                resource=f'{self._r}.explanationText',
 96                subs=[
 97                    ('${APP_NAME}', bui.Lstr(resource='titleText')),
 98                    ('${REMOTE_APP_NAME}', bui.get_remote_app_name()),
 99                ],
100            ),
101            max_height=100,
102            h_align='center',
103            v_align='center',
104        )
105        v -= 90
106
107        # Update: now we just show link to the remote webpage.
108        bui.textwidget(
109            parent=self._root_widget,
110            position=(width * 0.5, v + 5),
111            size=(0, 0),
112            color=(0.7, 0.9, 0.7, 1.0),
113            scale=1.4,
114            text='bombsquadgame.com/remote',
115            maxwidth=width * 0.95,
116            max_height=60,
117            h_align='center',
118            v_align='center',
119        )
120        v -= 30
121
122        bui.textwidget(
123            parent=self._root_widget,
124            position=(width * 0.5, v - 35),
125            size=(0, 0),
126            color=(0.7, 0.9, 0.7, 0.8),
127            scale=0.65,
128            text=bui.Lstr(resource=f'{self._r}.bestResultsText'),
129            maxwidth=width * 0.95,
130            max_height=height * 0.19,
131            h_align='center',
132            v_align='center',
133        )
134
135        bui.checkboxwidget(
136            parent=self._root_widget,
137            position=(width * 0.5 - 150, v - 116),
138            size=(300, 30),
139            maxwidth=300,
140            scale=0.8,
141            value=not bui.app.config.resolve('Enable Remote App'),
142            autoselect=True,
143            text=bui.Lstr(resource='disableRemoteAppConnectionsText'),
144            on_value_change_call=self._on_check_changed,
145        )
146
147    @override
148    def get_main_window_state(self) -> bui.MainWindowState:
149        # Support recreating our window for back/refresh purposes.
150        cls = type(self)
151        return bui.BasicMainWindowState(
152            create_call=lambda transition, origin_widget: cls(
153                transition=transition, origin_widget=origin_widget
154            )
155        )
156
157    def _on_check_changed(self, value: bool) -> None:
158        cfg = bui.app.config
159        cfg['Enable Remote App'] = not value
160        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 = 800 if uiscale is bui.UIScale.SMALL else 700
 25        height = 390
 26        spacing = 40
 27        assert bui.app.classic is not None
 28        super().__init__(
 29            root_widget=bui.containerwidget(
 30                size=(width, height),
 31                toolbar_visibility=(
 32                    'menu_minimal'
 33                    if uiscale is bui.UIScale.SMALL
 34                    else 'menu_full'
 35                ),
 36                scale=(
 37                    1.76
 38                    if uiscale is bui.UIScale.SMALL
 39                    else 1.3 if uiscale is bui.UIScale.MEDIUM else 1.0
 40                ),
 41                stack_offset=(
 42                    (-10, 0) if uiscale is bui.UIScale.SMALL else (0, 0)
 43                ),
 44            ),
 45            transition=transition,
 46            origin_widget=origin_widget,
 47        )
 48        if uiscale is bui.UIScale.SMALL:
 49            bui.containerwidget(
 50                edit=self.get_root_widget(),
 51                on_cancel_call=self.main_window_back,
 52            )
 53        else:
 54            btn = bui.buttonwidget(
 55                parent=self._root_widget,
 56                position=(40, height - 67),
 57                size=(140, 65),
 58                scale=0.8,
 59                label=bui.Lstr(resource='backText'),
 60                button_type='back',
 61                text_scale=1.1,
 62                autoselect=True,
 63                on_activate_call=self.main_window_back,
 64            )
 65            bui.containerwidget(edit=self._root_widget, cancel_button=btn)
 66            bui.buttonwidget(
 67                edit=btn,
 68                button_type='backSmall',
 69                size=(60, 60),
 70                label=bui.charstr(bui.SpecialChar.BACK),
 71            )
 72
 73        bui.textwidget(
 74            parent=self._root_widget,
 75            position=(width * 0.5, height - 42),
 76            size=(0, 0),
 77            text=bui.Lstr(resource=f'{self._r}.titleText'),
 78            maxwidth=370,
 79            color=bui.app.ui_v1.title_color,
 80            scale=0.8,
 81            h_align='center',
 82            v_align='center',
 83        )
 84
 85        v = height - 70.0
 86        v -= spacing * 1.2
 87        bui.textwidget(
 88            parent=self._root_widget,
 89            position=(15, v - 26),
 90            size=(width - 30, 30),
 91            maxwidth=width * 0.95,
 92            color=(0.7, 0.9, 0.7, 1.0),
 93            scale=0.8,
 94            text=bui.Lstr(
 95                resource=f'{self._r}.explanationText',
 96                subs=[
 97                    ('${APP_NAME}', bui.Lstr(resource='titleText')),
 98                    ('${REMOTE_APP_NAME}', bui.get_remote_app_name()),
 99                ],
100            ),
101            max_height=100,
102            h_align='center',
103            v_align='center',
104        )
105        v -= 90
106
107        # Update: now we just show link to the remote webpage.
108        bui.textwidget(
109            parent=self._root_widget,
110            position=(width * 0.5, v + 5),
111            size=(0, 0),
112            color=(0.7, 0.9, 0.7, 1.0),
113            scale=1.4,
114            text='bombsquadgame.com/remote',
115            maxwidth=width * 0.95,
116            max_height=60,
117            h_align='center',
118            v_align='center',
119        )
120        v -= 30
121
122        bui.textwidget(
123            parent=self._root_widget,
124            position=(width * 0.5, v - 35),
125            size=(0, 0),
126            color=(0.7, 0.9, 0.7, 0.8),
127            scale=0.65,
128            text=bui.Lstr(resource=f'{self._r}.bestResultsText'),
129            maxwidth=width * 0.95,
130            max_height=height * 0.19,
131            h_align='center',
132            v_align='center',
133        )
134
135        bui.checkboxwidget(
136            parent=self._root_widget,
137            position=(width * 0.5 - 150, v - 116),
138            size=(300, 30),
139            maxwidth=300,
140            scale=0.8,
141            value=not bui.app.config.resolve('Enable Remote App'),
142            autoselect=True,
143            text=bui.Lstr(resource='disableRemoteAppConnectionsText'),
144            on_value_change_call=self._on_check_changed,
145        )

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.

@override
def get_main_window_state(self) -> bauiv1.MainWindowState:
147    @override
148    def get_main_window_state(self) -> bui.MainWindowState:
149        # Support recreating our window for back/refresh purposes.
150        cls = type(self)
151        return bui.BasicMainWindowState(
152            create_call=lambda transition, origin_widget: cls(
153                transition=transition, origin_widget=origin_widget
154            )
155        )

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