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
 32                    if uiscale is bui.UIScale.MEDIUM
 33                    else 1.25
 34                ),
 35            )
 36        )
 37        bui.getsound('error').play()
 38
 39        bui.textwidget(
 40            parent=self._root_widget,
 41            position=(self._width * 0.5, self._height - 46),
 42            size=(0, 0),
 43            color=app.ui_v1.title_color,
 44            h_align='center',
 45            v_align='center',
 46            text=bui.Lstr(
 47                resource='deviceAccountUpgradeText',
 48                subs=[('${NAME}', login_name)],
 49            ),
 50            maxwidth=self._width * 0.95,
 51        )
 52        bui.textwidget(
 53            parent=self._root_widget,
 54            position=(self._width * 0.5, 125),
 55            size=(0, 0),
 56            scale=0.8,
 57            color=(0.7, 0.8, 0.7),
 58            h_align='center',
 59            v_align='center',
 60            text=(
 61                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 62                + login_name
 63                + '    ---->    '
 64                + bui.charstr(bui.SpecialChar.V2_LOGO)
 65                + login_name
 66            ),
 67            maxwidth=self._width * 0.95,
 68        )
 69        button_width = 200
 70
 71        cancel_button = bui.buttonwidget(
 72            parent=self._root_widget,
 73            position=(20, 25),
 74            size=(button_width, 65),
 75            autoselect=True,
 76            label=bui.Lstr(resource='notNowText'),
 77            on_activate_call=self._done,
 78        )
 79
 80        _what_is_this_button = bui.buttonwidget(
 81            parent=self._root_widget,
 82            position=(self._width * 0.5 - button_width * 0.5, 25),
 83            size=(button_width, 65),
 84            autoselect=True,
 85            label=bui.Lstr(resource='whatIsThisText'),
 86            color=(0.55, 0.5, 0.6),
 87            textcolor=(0.75, 0.7, 0.8),
 88            on_activate_call=show_what_is_v2_page,
 89        )
 90
 91        upgrade_button = bui.buttonwidget(
 92            parent=self._root_widget,
 93            position=(self._width - button_width - 20, 25),
 94            size=(button_width, 65),
 95            autoselect=True,
 96            label=bui.Lstr(resource='upgradeText'),
 97            on_activate_call=self._upgrade_press,
 98        )
 99
100        bui.containerwidget(
101            edit=self._root_widget,
102            selected_child=upgrade_button,
103            cancel_button=cancel_button,
104        )
105
106    def _upgrade_press(self) -> None:
107        plus = bui.app.plus
108        assert plus is not None
109
110        # Get rid of the window and sign out before kicking the
111        # user over to a browser to do the upgrade. This hopefully
112        # makes it more clear when they come back that they need to
113        # sign in with the 'BombSquad account' option.
114        bui.containerwidget(edit=self._root_widget, transition='out_left')
115        plus.sign_out_v1()
116        bamasteraddr = plus.get_master_server_address(version=2)
117        bui.open_url(f'{bamasteraddr}/v2uda/{self._code}')
118
119    def _done(self) -> None:
120        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
 33                    if uiscale is bui.UIScale.MEDIUM
 34                    else 1.25
 35                ),
 36            )
 37        )
 38        bui.getsound('error').play()
 39
 40        bui.textwidget(
 41            parent=self._root_widget,
 42            position=(self._width * 0.5, self._height - 46),
 43            size=(0, 0),
 44            color=app.ui_v1.title_color,
 45            h_align='center',
 46            v_align='center',
 47            text=bui.Lstr(
 48                resource='deviceAccountUpgradeText',
 49                subs=[('${NAME}', login_name)],
 50            ),
 51            maxwidth=self._width * 0.95,
 52        )
 53        bui.textwidget(
 54            parent=self._root_widget,
 55            position=(self._width * 0.5, 125),
 56            size=(0, 0),
 57            scale=0.8,
 58            color=(0.7, 0.8, 0.7),
 59            h_align='center',
 60            v_align='center',
 61            text=(
 62                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 63                + login_name
 64                + '    ---->    '
 65                + bui.charstr(bui.SpecialChar.V2_LOGO)
 66                + login_name
 67            ),
 68            maxwidth=self._width * 0.95,
 69        )
 70        button_width = 200
 71
 72        cancel_button = bui.buttonwidget(
 73            parent=self._root_widget,
 74            position=(20, 25),
 75            size=(button_width, 65),
 76            autoselect=True,
 77            label=bui.Lstr(resource='notNowText'),
 78            on_activate_call=self._done,
 79        )
 80
 81        _what_is_this_button = bui.buttonwidget(
 82            parent=self._root_widget,
 83            position=(self._width * 0.5 - button_width * 0.5, 25),
 84            size=(button_width, 65),
 85            autoselect=True,
 86            label=bui.Lstr(resource='whatIsThisText'),
 87            color=(0.55, 0.5, 0.6),
 88            textcolor=(0.75, 0.7, 0.8),
 89            on_activate_call=show_what_is_v2_page,
 90        )
 91
 92        upgrade_button = bui.buttonwidget(
 93            parent=self._root_widget,
 94            position=(self._width - button_width - 20, 25),
 95            size=(button_width, 65),
 96            autoselect=True,
 97            label=bui.Lstr(resource='upgradeText'),
 98            on_activate_call=self._upgrade_press,
 99        )
100
101        bui.containerwidget(
102            edit=self._root_widget,
103            selected_child=upgrade_button,
104            cancel_button=cancel_button,
105        )
106
107    def _upgrade_press(self) -> None:
108        plus = bui.app.plus
109        assert plus is not None
110
111        # Get rid of the window and sign out before kicking the
112        # user over to a browser to do the upgrade. This hopefully
113        # makes it more clear when they come back that they need to
114        # sign in with the 'BombSquad account' option.
115        bui.containerwidget(edit=self._root_widget, transition='out_left')
116        plus.sign_out_v1()
117        bamasteraddr = plus.get_master_server_address(version=2)
118        bui.open_url(f'{bamasteraddr}/v2uda/{self._code}')
119
120    def _done(self) -> None:
121        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
 33                    if uiscale is bui.UIScale.MEDIUM
 34                    else 1.25
 35                ),
 36            )
 37        )
 38        bui.getsound('error').play()
 39
 40        bui.textwidget(
 41            parent=self._root_widget,
 42            position=(self._width * 0.5, self._height - 46),
 43            size=(0, 0),
 44            color=app.ui_v1.title_color,
 45            h_align='center',
 46            v_align='center',
 47            text=bui.Lstr(
 48                resource='deviceAccountUpgradeText',
 49                subs=[('${NAME}', login_name)],
 50            ),
 51            maxwidth=self._width * 0.95,
 52        )
 53        bui.textwidget(
 54            parent=self._root_widget,
 55            position=(self._width * 0.5, 125),
 56            size=(0, 0),
 57            scale=0.8,
 58            color=(0.7, 0.8, 0.7),
 59            h_align='center',
 60            v_align='center',
 61            text=(
 62                bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
 63                + login_name
 64                + '    ---->    '
 65                + bui.charstr(bui.SpecialChar.V2_LOGO)
 66                + login_name
 67            ),
 68            maxwidth=self._width * 0.95,
 69        )
 70        button_width = 200
 71
 72        cancel_button = bui.buttonwidget(
 73            parent=self._root_widget,
 74            position=(20, 25),
 75            size=(button_width, 65),
 76            autoselect=True,
 77            label=bui.Lstr(resource='notNowText'),
 78            on_activate_call=self._done,
 79        )
 80
 81        _what_is_this_button = bui.buttonwidget(
 82            parent=self._root_widget,
 83            position=(self._width * 0.5 - button_width * 0.5, 25),
 84            size=(button_width, 65),
 85            autoselect=True,
 86            label=bui.Lstr(resource='whatIsThisText'),
 87            color=(0.55, 0.5, 0.6),
 88            textcolor=(0.75, 0.7, 0.8),
 89            on_activate_call=show_what_is_v2_page,
 90        )
 91
 92        upgrade_button = bui.buttonwidget(
 93            parent=self._root_widget,
 94            position=(self._width - button_width - 20, 25),
 95            size=(button_width, 65),
 96            autoselect=True,
 97            label=bui.Lstr(resource='upgradeText'),
 98            on_activate_call=self._upgrade_press,
 99        )
100
101        bui.containerwidget(
102            edit=self._root_widget,
103            selected_child=upgrade_button,
104            cancel_button=cancel_button,
105        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget