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

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

Return a WindowState to recreate this window, if supported.