bauiv1lib.account.link
UI functionality for linking accounts.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI functionality for linking accounts.""" 4 5from __future__ import annotations 6 7import copy 8import time 9from typing import TYPE_CHECKING 10 11import bauiv1 as bui 12 13if TYPE_CHECKING: 14 from typing import Any 15 16 17class AccountLinkWindow(bui.Window): 18 """Window for linking accounts.""" 19 20 def __init__(self, origin_widget: bui.Widget | None = None): 21 plus = bui.app.plus 22 assert plus is not None 23 24 scale_origin: tuple[float, float] | None 25 if origin_widget is not None: 26 self._transition_out = 'out_scale' 27 scale_origin = origin_widget.get_screen_space_center() 28 transition = 'in_scale' 29 else: 30 self._transition_out = 'out_right' 31 scale_origin = None 32 transition = 'in_right' 33 bg_color = (0.4, 0.4, 0.5) 34 self._width = 560 35 self._height = 420 36 assert bui.app.classic is not None 37 uiscale = bui.app.ui_v1.uiscale 38 base_scale = ( 39 1.65 40 if uiscale is bui.UIScale.SMALL 41 else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.1 42 ) 43 super().__init__( 44 root_widget=bui.containerwidget( 45 size=(self._width, self._height), 46 transition=transition, 47 scale=base_scale, 48 scale_origin_stack_offset=scale_origin, 49 stack_offset=( 50 (0, -10) if uiscale is bui.UIScale.SMALL else (0, 0) 51 ), 52 ) 53 ) 54 self._cancel_button = bui.buttonwidget( 55 parent=self._root_widget, 56 position=(40, self._height - 45), 57 size=(50, 50), 58 scale=0.7, 59 label='', 60 color=bg_color, 61 on_activate_call=self._cancel, 62 autoselect=True, 63 icon=bui.gettexture('crossOut'), 64 iconscale=1.2, 65 ) 66 maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5) 67 bui.textwidget( 68 parent=self._root_widget, 69 position=(self._width * 0.5, self._height * 0.56), 70 size=(0, 0), 71 text=bui.Lstr( 72 resource=( 73 'accountSettingsWindow.linkAccountsInstructionsNewText' 74 ), 75 subs=[('${COUNT}', str(maxlinks))], 76 ), 77 maxwidth=self._width * 0.9, 78 color=bui.app.ui_v1.infotextcolor, 79 max_height=self._height * 0.6, 80 h_align='center', 81 v_align='center', 82 ) 83 bui.containerwidget( 84 edit=self._root_widget, cancel_button=self._cancel_button 85 ) 86 bui.buttonwidget( 87 parent=self._root_widget, 88 position=(40, 30), 89 size=(200, 60), 90 label=bui.Lstr( 91 resource='accountSettingsWindow.linkAccountsGenerateCodeText' 92 ), 93 autoselect=True, 94 on_activate_call=self._generate_press, 95 ) 96 self._enter_code_button = bui.buttonwidget( 97 parent=self._root_widget, 98 position=(self._width - 240, 30), 99 size=(200, 60), 100 label=bui.Lstr( 101 resource='accountSettingsWindow.linkAccountsEnterCodeText' 102 ), 103 autoselect=True, 104 on_activate_call=self._enter_code_press, 105 ) 106 107 def _generate_press(self) -> None: 108 from bauiv1lib import account 109 110 plus = bui.app.plus 111 assert plus is not None 112 113 if plus.get_v1_account_state() != 'signed_in': 114 account.show_sign_in_prompt() 115 return 116 bui.screenmessage( 117 bui.Lstr(resource='gatherWindow.requestingAPromoCodeText'), 118 color=(0, 1, 0), 119 ) 120 plus.add_v1_account_transaction( 121 { 122 'type': 'ACCOUNT_LINK_CODE_REQUEST', 123 'expire_time': time.time() + 5, 124 } 125 ) 126 plus.run_v1_account_transactions() 127 128 def _enter_code_press(self) -> None: 129 from bauiv1lib.sendinfo import SendInfoWindow 130 131 SendInfoWindow( 132 modal=True, 133 legacy_code_mode=True, 134 origin_widget=self._enter_code_button, 135 ) 136 bui.containerwidget( 137 edit=self._root_widget, transition=self._transition_out 138 ) 139 140 def _cancel(self) -> None: 141 bui.containerwidget( 142 edit=self._root_widget, transition=self._transition_out 143 ) 144 145 146class AccountLinkCodeWindow(bui.Window): 147 """Window showing code for account-linking.""" 148 149 def __init__(self, data: dict[str, Any]): 150 self._width = 350 151 self._height = 200 152 assert bui.app.classic is not None 153 uiscale = bui.app.ui_v1.uiscale 154 super().__init__( 155 root_widget=bui.containerwidget( 156 size=(self._width, self._height), 157 color=(0.45, 0.63, 0.15), 158 transition='in_scale', 159 scale=( 160 1.8 161 if uiscale is bui.UIScale.SMALL 162 else 1.35 if uiscale is bui.UIScale.MEDIUM else 1.0 163 ), 164 ) 165 ) 166 self._data = copy.deepcopy(data) 167 bui.getsound('cashRegister').play() 168 bui.getsound('swish').play() 169 self._cancel_button = bui.buttonwidget( 170 parent=self._root_widget, 171 scale=0.5, 172 position=(40, self._height - 40), 173 size=(50, 50), 174 label='', 175 on_activate_call=self.close, 176 autoselect=True, 177 color=(0.45, 0.63, 0.15), 178 icon=bui.gettexture('crossOut'), 179 iconscale=1.2, 180 ) 181 bui.containerwidget( 182 edit=self._root_widget, cancel_button=self._cancel_button 183 ) 184 bui.textwidget( 185 parent=self._root_widget, 186 position=(self._width * 0.5, self._height * 0.5), 187 size=(0, 0), 188 color=(1.0, 3.0, 1.0), 189 scale=2.0, 190 h_align='center', 191 v_align='center', 192 text=data['code'], 193 maxwidth=self._width * 0.85, 194 ) 195 196 def close(self) -> None: 197 """close the window""" 198 bui.containerwidget(edit=self._root_widget, transition='out_scale')
class
AccountLinkWindow(bauiv1._uitypes.Window):
18class AccountLinkWindow(bui.Window): 19 """Window for linking accounts.""" 20 21 def __init__(self, origin_widget: bui.Widget | None = None): 22 plus = bui.app.plus 23 assert plus is not None 24 25 scale_origin: tuple[float, float] | None 26 if origin_widget is not None: 27 self._transition_out = 'out_scale' 28 scale_origin = origin_widget.get_screen_space_center() 29 transition = 'in_scale' 30 else: 31 self._transition_out = 'out_right' 32 scale_origin = None 33 transition = 'in_right' 34 bg_color = (0.4, 0.4, 0.5) 35 self._width = 560 36 self._height = 420 37 assert bui.app.classic is not None 38 uiscale = bui.app.ui_v1.uiscale 39 base_scale = ( 40 1.65 41 if uiscale is bui.UIScale.SMALL 42 else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.1 43 ) 44 super().__init__( 45 root_widget=bui.containerwidget( 46 size=(self._width, self._height), 47 transition=transition, 48 scale=base_scale, 49 scale_origin_stack_offset=scale_origin, 50 stack_offset=( 51 (0, -10) if uiscale is bui.UIScale.SMALL else (0, 0) 52 ), 53 ) 54 ) 55 self._cancel_button = bui.buttonwidget( 56 parent=self._root_widget, 57 position=(40, self._height - 45), 58 size=(50, 50), 59 scale=0.7, 60 label='', 61 color=bg_color, 62 on_activate_call=self._cancel, 63 autoselect=True, 64 icon=bui.gettexture('crossOut'), 65 iconscale=1.2, 66 ) 67 maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5) 68 bui.textwidget( 69 parent=self._root_widget, 70 position=(self._width * 0.5, self._height * 0.56), 71 size=(0, 0), 72 text=bui.Lstr( 73 resource=( 74 'accountSettingsWindow.linkAccountsInstructionsNewText' 75 ), 76 subs=[('${COUNT}', str(maxlinks))], 77 ), 78 maxwidth=self._width * 0.9, 79 color=bui.app.ui_v1.infotextcolor, 80 max_height=self._height * 0.6, 81 h_align='center', 82 v_align='center', 83 ) 84 bui.containerwidget( 85 edit=self._root_widget, cancel_button=self._cancel_button 86 ) 87 bui.buttonwidget( 88 parent=self._root_widget, 89 position=(40, 30), 90 size=(200, 60), 91 label=bui.Lstr( 92 resource='accountSettingsWindow.linkAccountsGenerateCodeText' 93 ), 94 autoselect=True, 95 on_activate_call=self._generate_press, 96 ) 97 self._enter_code_button = bui.buttonwidget( 98 parent=self._root_widget, 99 position=(self._width - 240, 30), 100 size=(200, 60), 101 label=bui.Lstr( 102 resource='accountSettingsWindow.linkAccountsEnterCodeText' 103 ), 104 autoselect=True, 105 on_activate_call=self._enter_code_press, 106 ) 107 108 def _generate_press(self) -> None: 109 from bauiv1lib import account 110 111 plus = bui.app.plus 112 assert plus is not None 113 114 if plus.get_v1_account_state() != 'signed_in': 115 account.show_sign_in_prompt() 116 return 117 bui.screenmessage( 118 bui.Lstr(resource='gatherWindow.requestingAPromoCodeText'), 119 color=(0, 1, 0), 120 ) 121 plus.add_v1_account_transaction( 122 { 123 'type': 'ACCOUNT_LINK_CODE_REQUEST', 124 'expire_time': time.time() + 5, 125 } 126 ) 127 plus.run_v1_account_transactions() 128 129 def _enter_code_press(self) -> None: 130 from bauiv1lib.sendinfo import SendInfoWindow 131 132 SendInfoWindow( 133 modal=True, 134 legacy_code_mode=True, 135 origin_widget=self._enter_code_button, 136 ) 137 bui.containerwidget( 138 edit=self._root_widget, transition=self._transition_out 139 ) 140 141 def _cancel(self) -> None: 142 bui.containerwidget( 143 edit=self._root_widget, transition=self._transition_out 144 )
Window for linking accounts.
AccountLinkWindow(origin_widget: _bauiv1.Widget | None = None)
21 def __init__(self, origin_widget: bui.Widget | None = None): 22 plus = bui.app.plus 23 assert plus is not None 24 25 scale_origin: tuple[float, float] | None 26 if origin_widget is not None: 27 self._transition_out = 'out_scale' 28 scale_origin = origin_widget.get_screen_space_center() 29 transition = 'in_scale' 30 else: 31 self._transition_out = 'out_right' 32 scale_origin = None 33 transition = 'in_right' 34 bg_color = (0.4, 0.4, 0.5) 35 self._width = 560 36 self._height = 420 37 assert bui.app.classic is not None 38 uiscale = bui.app.ui_v1.uiscale 39 base_scale = ( 40 1.65 41 if uiscale is bui.UIScale.SMALL 42 else 1.5 if uiscale is bui.UIScale.MEDIUM else 1.1 43 ) 44 super().__init__( 45 root_widget=bui.containerwidget( 46 size=(self._width, self._height), 47 transition=transition, 48 scale=base_scale, 49 scale_origin_stack_offset=scale_origin, 50 stack_offset=( 51 (0, -10) if uiscale is bui.UIScale.SMALL else (0, 0) 52 ), 53 ) 54 ) 55 self._cancel_button = bui.buttonwidget( 56 parent=self._root_widget, 57 position=(40, self._height - 45), 58 size=(50, 50), 59 scale=0.7, 60 label='', 61 color=bg_color, 62 on_activate_call=self._cancel, 63 autoselect=True, 64 icon=bui.gettexture('crossOut'), 65 iconscale=1.2, 66 ) 67 maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5) 68 bui.textwidget( 69 parent=self._root_widget, 70 position=(self._width * 0.5, self._height * 0.56), 71 size=(0, 0), 72 text=bui.Lstr( 73 resource=( 74 'accountSettingsWindow.linkAccountsInstructionsNewText' 75 ), 76 subs=[('${COUNT}', str(maxlinks))], 77 ), 78 maxwidth=self._width * 0.9, 79 color=bui.app.ui_v1.infotextcolor, 80 max_height=self._height * 0.6, 81 h_align='center', 82 v_align='center', 83 ) 84 bui.containerwidget( 85 edit=self._root_widget, cancel_button=self._cancel_button 86 ) 87 bui.buttonwidget( 88 parent=self._root_widget, 89 position=(40, 30), 90 size=(200, 60), 91 label=bui.Lstr( 92 resource='accountSettingsWindow.linkAccountsGenerateCodeText' 93 ), 94 autoselect=True, 95 on_activate_call=self._generate_press, 96 ) 97 self._enter_code_button = bui.buttonwidget( 98 parent=self._root_widget, 99 position=(self._width - 240, 30), 100 size=(200, 60), 101 label=bui.Lstr( 102 resource='accountSettingsWindow.linkAccountsEnterCodeText' 103 ), 104 autoselect=True, 105 on_activate_call=self._enter_code_press, 106 )
Inherited Members
- bauiv1._uitypes.Window
- get_root_widget
class
AccountLinkCodeWindow(bauiv1._uitypes.Window):
147class AccountLinkCodeWindow(bui.Window): 148 """Window showing code for account-linking.""" 149 150 def __init__(self, data: dict[str, Any]): 151 self._width = 350 152 self._height = 200 153 assert bui.app.classic is not None 154 uiscale = bui.app.ui_v1.uiscale 155 super().__init__( 156 root_widget=bui.containerwidget( 157 size=(self._width, self._height), 158 color=(0.45, 0.63, 0.15), 159 transition='in_scale', 160 scale=( 161 1.8 162 if uiscale is bui.UIScale.SMALL 163 else 1.35 if uiscale is bui.UIScale.MEDIUM else 1.0 164 ), 165 ) 166 ) 167 self._data = copy.deepcopy(data) 168 bui.getsound('cashRegister').play() 169 bui.getsound('swish').play() 170 self._cancel_button = bui.buttonwidget( 171 parent=self._root_widget, 172 scale=0.5, 173 position=(40, self._height - 40), 174 size=(50, 50), 175 label='', 176 on_activate_call=self.close, 177 autoselect=True, 178 color=(0.45, 0.63, 0.15), 179 icon=bui.gettexture('crossOut'), 180 iconscale=1.2, 181 ) 182 bui.containerwidget( 183 edit=self._root_widget, cancel_button=self._cancel_button 184 ) 185 bui.textwidget( 186 parent=self._root_widget, 187 position=(self._width * 0.5, self._height * 0.5), 188 size=(0, 0), 189 color=(1.0, 3.0, 1.0), 190 scale=2.0, 191 h_align='center', 192 v_align='center', 193 text=data['code'], 194 maxwidth=self._width * 0.85, 195 ) 196 197 def close(self) -> None: 198 """close the window""" 199 bui.containerwidget(edit=self._root_widget, transition='out_scale')
Window showing code for account-linking.
AccountLinkCodeWindow(data: dict[str, typing.Any])
150 def __init__(self, data: dict[str, Any]): 151 self._width = 350 152 self._height = 200 153 assert bui.app.classic is not None 154 uiscale = bui.app.ui_v1.uiscale 155 super().__init__( 156 root_widget=bui.containerwidget( 157 size=(self._width, self._height), 158 color=(0.45, 0.63, 0.15), 159 transition='in_scale', 160 scale=( 161 1.8 162 if uiscale is bui.UIScale.SMALL 163 else 1.35 if uiscale is bui.UIScale.MEDIUM else 1.0 164 ), 165 ) 166 ) 167 self._data = copy.deepcopy(data) 168 bui.getsound('cashRegister').play() 169 bui.getsound('swish').play() 170 self._cancel_button = bui.buttonwidget( 171 parent=self._root_widget, 172 scale=0.5, 173 position=(40, self._height - 40), 174 size=(50, 50), 175 label='', 176 on_activate_call=self.close, 177 autoselect=True, 178 color=(0.45, 0.63, 0.15), 179 icon=bui.gettexture('crossOut'), 180 iconscale=1.2, 181 ) 182 bui.containerwidget( 183 edit=self._root_widget, cancel_button=self._cancel_button 184 ) 185 bui.textwidget( 186 parent=self._root_widget, 187 position=(self._width * 0.5, self._height * 0.5), 188 size=(0, 0), 189 color=(1.0, 3.0, 1.0), 190 scale=2.0, 191 h_align='center', 192 v_align='center', 193 text=data['code'], 194 maxwidth=self._width * 0.85, 195 )
def
close(self) -> None:
197 def close(self) -> None: 198 """close the window""" 199 bui.containerwidget(edit=self._root_widget, transition='out_scale')
close the window
Inherited Members
- bauiv1._uitypes.Window
- get_root_widget