bauiv1lib.v2upgrade

UI for upgrading V1 accounts to V2.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI for upgrading V1 accounts to V2."""
  4
  5from __future__ import annotations
  6
  7import bauiv1 as bui
  8
  9
 10class V2UpgradeWindow(bui.Window):
 11    """A window presenting a URL to the user visually."""
 12
 13    def __init__(self, login_name: str, code: str):
 14        from bauiv1lib.account.settings import show_what_is_v2_page
 15
 16        app = bui.app
 17        assert app.classic is not None
 18        uiscale = app.ui_v1.uiscale
 19
 20        self._code = code
 21
 22        self._width = 700
 23        self._height = 270
 24        super().__init__(
 25            root_widget=bui.containerwidget(
 26                size=(self._width, self._height + 40),
 27                transition='in_right',
 28                scale=(
 29                    1.25
 30                    if uiscale is bui.UIScale.SMALL
 31                    else 1.25 if uiscale is bui.UIScale.MEDIUM else 1.25
 32                ),
 33            )
 34        )
 35        bui.getsound('error').play()
 36
 37        bui.textwidget(
 38            parent=self._root_widget,
 39            position=(self._width * 0.5, self._height - 46),
 40            size=(0, 0),
 41            color=app.ui_v1.title_color,
 42            h_align='center',
 43            v_align='center',
 44            text=bui.Lstr(
 45                resource='deviceAccountUpgradeText',
 46                subs=[('${NAME}', login_name)],
 47            ),
 48            maxwidth=self._width * 0.95,
 49        )
 50        bui.textwidget(
 51            parent=self._root_widget,
 52            position=(self._width * 0.5, 125),
 53            size=(0, 0),
 54            scale=0.8,
 55            color=(0.7, 0.8, 0.7),
 56            h_align='center',
 57            v_align='center',
 58            text=(
 59                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 60                + login_name
 61                + '    ---->    '
 62                + bui.charstr(bui.SpecialChar.V2_LOGO)
 63                + login_name
 64            ),
 65            maxwidth=self._width * 0.95,
 66        )
 67        button_width = 200
 68
 69        cancel_button = bui.buttonwidget(
 70            parent=self._root_widget,
 71            position=(20, 25),
 72            size=(button_width, 65),
 73            autoselect=True,
 74            label=bui.Lstr(resource='notNowText'),
 75            on_activate_call=self._done,
 76        )
 77
 78        _what_is_this_button = bui.buttonwidget(
 79            parent=self._root_widget,
 80            position=(self._width * 0.5 - button_width * 0.5, 25),
 81            size=(button_width, 65),
 82            autoselect=True,
 83            label=bui.Lstr(resource='whatIsThisText'),
 84            color=(0.55, 0.5, 0.6),
 85            textcolor=(0.75, 0.7, 0.8),
 86            on_activate_call=show_what_is_v2_page,
 87        )
 88
 89        upgrade_button = bui.buttonwidget(
 90            parent=self._root_widget,
 91            position=(self._width - button_width - 20, 25),
 92            size=(button_width, 65),
 93            autoselect=True,
 94            label=bui.Lstr(resource='upgradeText'),
 95            on_activate_call=self._upgrade_press,
 96        )
 97
 98        bui.containerwidget(
 99            edit=self._root_widget,
100            selected_child=upgrade_button,
101            cancel_button=cancel_button,
102        )
103
104    def _upgrade_press(self) -> None:
105        plus = bui.app.plus
106        assert plus is not None
107
108        # Get rid of the window and sign out before kicking the
109        # user over to a browser to do the upgrade. This hopefully
110        # makes it more clear when they come back that they need to
111        # sign in with the 'BombSquad account' option.
112        bui.containerwidget(edit=self._root_widget, transition='out_left')
113        plus.sign_out_v1()
114        bamasteraddr = plus.get_master_server_address(version=2)
115        bui.open_url(f'{bamasteraddr}/v2uda/{self._code}')
116
117    def _done(self) -> None:
118        bui.containerwidget(edit=self._root_widget, transition='out_left')
class V2UpgradeWindow(bauiv1._uitypes.Window):
 11class V2UpgradeWindow(bui.Window):
 12    """A window presenting a URL to the user visually."""
 13
 14    def __init__(self, login_name: str, code: str):
 15        from bauiv1lib.account.settings import show_what_is_v2_page
 16
 17        app = bui.app
 18        assert app.classic is not None
 19        uiscale = app.ui_v1.uiscale
 20
 21        self._code = code
 22
 23        self._width = 700
 24        self._height = 270
 25        super().__init__(
 26            root_widget=bui.containerwidget(
 27                size=(self._width, self._height + 40),
 28                transition='in_right',
 29                scale=(
 30                    1.25
 31                    if uiscale is bui.UIScale.SMALL
 32                    else 1.25 if uiscale is bui.UIScale.MEDIUM else 1.25
 33                ),
 34            )
 35        )
 36        bui.getsound('error').play()
 37
 38        bui.textwidget(
 39            parent=self._root_widget,
 40            position=(self._width * 0.5, self._height - 46),
 41            size=(0, 0),
 42            color=app.ui_v1.title_color,
 43            h_align='center',
 44            v_align='center',
 45            text=bui.Lstr(
 46                resource='deviceAccountUpgradeText',
 47                subs=[('${NAME}', login_name)],
 48            ),
 49            maxwidth=self._width * 0.95,
 50        )
 51        bui.textwidget(
 52            parent=self._root_widget,
 53            position=(self._width * 0.5, 125),
 54            size=(0, 0),
 55            scale=0.8,
 56            color=(0.7, 0.8, 0.7),
 57            h_align='center',
 58            v_align='center',
 59            text=(
 60                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 61                + login_name
 62                + '    ---->    '
 63                + bui.charstr(bui.SpecialChar.V2_LOGO)
 64                + login_name
 65            ),
 66            maxwidth=self._width * 0.95,
 67        )
 68        button_width = 200
 69
 70        cancel_button = bui.buttonwidget(
 71            parent=self._root_widget,
 72            position=(20, 25),
 73            size=(button_width, 65),
 74            autoselect=True,
 75            label=bui.Lstr(resource='notNowText'),
 76            on_activate_call=self._done,
 77        )
 78
 79        _what_is_this_button = bui.buttonwidget(
 80            parent=self._root_widget,
 81            position=(self._width * 0.5 - button_width * 0.5, 25),
 82            size=(button_width, 65),
 83            autoselect=True,
 84            label=bui.Lstr(resource='whatIsThisText'),
 85            color=(0.55, 0.5, 0.6),
 86            textcolor=(0.75, 0.7, 0.8),
 87            on_activate_call=show_what_is_v2_page,
 88        )
 89
 90        upgrade_button = bui.buttonwidget(
 91            parent=self._root_widget,
 92            position=(self._width - button_width - 20, 25),
 93            size=(button_width, 65),
 94            autoselect=True,
 95            label=bui.Lstr(resource='upgradeText'),
 96            on_activate_call=self._upgrade_press,
 97        )
 98
 99        bui.containerwidget(
100            edit=self._root_widget,
101            selected_child=upgrade_button,
102            cancel_button=cancel_button,
103        )
104
105    def _upgrade_press(self) -> None:
106        plus = bui.app.plus
107        assert plus is not None
108
109        # Get rid of the window and sign out before kicking the
110        # user over to a browser to do the upgrade. This hopefully
111        # makes it more clear when they come back that they need to
112        # sign in with the 'BombSquad account' option.
113        bui.containerwidget(edit=self._root_widget, transition='out_left')
114        plus.sign_out_v1()
115        bamasteraddr = plus.get_master_server_address(version=2)
116        bui.open_url(f'{bamasteraddr}/v2uda/{self._code}')
117
118    def _done(self) -> None:
119        bui.containerwidget(edit=self._root_widget, transition='out_left')

A window presenting a URL to the user visually.

V2UpgradeWindow(login_name: str, code: str)
 14    def __init__(self, login_name: str, code: str):
 15        from bauiv1lib.account.settings import show_what_is_v2_page
 16
 17        app = bui.app
 18        assert app.classic is not None
 19        uiscale = app.ui_v1.uiscale
 20
 21        self._code = code
 22
 23        self._width = 700
 24        self._height = 270
 25        super().__init__(
 26            root_widget=bui.containerwidget(
 27                size=(self._width, self._height + 40),
 28                transition='in_right',
 29                scale=(
 30                    1.25
 31                    if uiscale is bui.UIScale.SMALL
 32                    else 1.25 if uiscale is bui.UIScale.MEDIUM else 1.25
 33                ),
 34            )
 35        )
 36        bui.getsound('error').play()
 37
 38        bui.textwidget(
 39            parent=self._root_widget,
 40            position=(self._width * 0.5, self._height - 46),
 41            size=(0, 0),
 42            color=app.ui_v1.title_color,
 43            h_align='center',
 44            v_align='center',
 45            text=bui.Lstr(
 46                resource='deviceAccountUpgradeText',
 47                subs=[('${NAME}', login_name)],
 48            ),
 49            maxwidth=self._width * 0.95,
 50        )
 51        bui.textwidget(
 52            parent=self._root_widget,
 53            position=(self._width * 0.5, 125),
 54            size=(0, 0),
 55            scale=0.8,
 56            color=(0.7, 0.8, 0.7),
 57            h_align='center',
 58            v_align='center',
 59            text=(
 60                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 61                + login_name
 62                + '    ---->    '
 63                + bui.charstr(bui.SpecialChar.V2_LOGO)
 64                + login_name
 65            ),
 66            maxwidth=self._width * 0.95,
 67        )
 68        button_width = 200
 69
 70        cancel_button = bui.buttonwidget(
 71            parent=self._root_widget,
 72            position=(20, 25),
 73            size=(button_width, 65),
 74            autoselect=True,
 75            label=bui.Lstr(resource='notNowText'),
 76            on_activate_call=self._done,
 77        )
 78
 79        _what_is_this_button = bui.buttonwidget(
 80            parent=self._root_widget,
 81            position=(self._width * 0.5 - button_width * 0.5, 25),
 82            size=(button_width, 65),
 83            autoselect=True,
 84            label=bui.Lstr(resource='whatIsThisText'),
 85            color=(0.55, 0.5, 0.6),
 86            textcolor=(0.75, 0.7, 0.8),
 87            on_activate_call=show_what_is_v2_page,
 88        )
 89
 90        upgrade_button = bui.buttonwidget(
 91            parent=self._root_widget,
 92            position=(self._width - button_width - 20, 25),
 93            size=(button_width, 65),
 94            autoselect=True,
 95            label=bui.Lstr(resource='upgradeText'),
 96            on_activate_call=self._upgrade_press,
 97        )
 98
 99        bui.containerwidget(
100            edit=self._root_widget,
101            selected_child=upgrade_button,
102            cancel_button=cancel_button,
103        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget