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

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
 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        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget
def show_what_is_v2_page() -> None:
121def show_what_is_v2_page() -> None:
122    """Show the webpage describing V2 accounts."""
123    plus = bui.app.plus
124    assert plus is not None
125
126    bamasteraddr = plus.get_master_server_address(version=2)
127    bui.open_url(f'{bamasteraddr}/whatisv2')

Show the webpage describing V2 accounts.