bauiv1lib.account.unlink
UI functionality for unlinking accounts.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI functionality for unlinking accounts.""" 4 5from __future__ import annotations 6 7import time 8from typing import TYPE_CHECKING 9 10import bauiv1 as bui 11 12if TYPE_CHECKING: 13 from typing import Any 14 15 16class AccountUnlinkWindow(bui.Window): 17 """A window to kick off account unlinks.""" 18 19 def __init__(self, origin_widget: bui.Widget | None = None): 20 plus = bui.app.plus 21 assert plus is not None 22 23 scale_origin: tuple[float, float] | None 24 if origin_widget is not None: 25 self._transition_out = 'out_scale' 26 scale_origin = origin_widget.get_screen_space_center() 27 transition = 'in_scale' 28 else: 29 self._transition_out = 'out_right' 30 scale_origin = None 31 transition = 'in_right' 32 bg_color = (0.4, 0.4, 0.5) 33 self._width = 540 34 self._height = 350 35 self._scroll_width = 400 36 self._scroll_height = 200 37 assert bui.app.classic is not None 38 uiscale = bui.app.ui_v1.uiscale 39 base_scale = ( 40 2.0 41 if uiscale is bui.UIScale.SMALL 42 else 1.6 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=(30, self._height - 50), 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 bui.textwidget( 68 parent=self._root_widget, 69 position=(self._width * 0.5, self._height * 0.88), 70 size=(0, 0), 71 text=bui.Lstr( 72 resource='accountSettingsWindow.unlinkAccountsInstructionsText' 73 ), 74 maxwidth=self._width * 0.7, 75 color=bui.app.ui_v1.infotextcolor, 76 h_align='center', 77 v_align='center', 78 ) 79 bui.containerwidget( 80 edit=self._root_widget, cancel_button=self._cancel_button 81 ) 82 83 self._scrollwidget = bui.scrollwidget( 84 parent=self._root_widget, 85 highlight=False, 86 position=( 87 (self._width - self._scroll_width) * 0.5, 88 self._height - 85 - self._scroll_height, 89 ), 90 size=(self._scroll_width, self._scroll_height), 91 ) 92 bui.containerwidget(edit=self._scrollwidget, claims_left_right=True) 93 self._columnwidget = bui.columnwidget( 94 parent=self._scrollwidget, border=2, margin=0, left_border=10 95 ) 96 97 our_login_id = plus.get_v1_account_public_login_id() 98 if our_login_id is None: 99 entries = [] 100 else: 101 account_infos = plus.get_v1_account_misc_read_val_2( 102 'linkedAccounts2', [] 103 ) 104 entries = [ 105 {'name': ai['d'], 'id': ai['id']} 106 for ai in account_infos 107 if ai['id'] != our_login_id 108 ] 109 110 # (avoid getting our selection stuck on an empty column widget) 111 if not entries: 112 bui.containerwidget(edit=self._scrollwidget, selectable=False) 113 for i, entry in enumerate(entries): 114 txt = bui.textwidget( 115 parent=self._columnwidget, 116 selectable=True, 117 text=entry['name'], 118 size=(self._scroll_width - 30, 30), 119 autoselect=True, 120 click_activate=True, 121 on_activate_call=bui.Call(self._on_entry_selected, entry), 122 ) 123 bui.widget(edit=txt, left_widget=self._cancel_button) 124 if i == 0: 125 bui.widget(edit=txt, up_widget=self._cancel_button) 126 127 def _on_entry_selected(self, entry: dict[str, Any]) -> None: 128 plus = bui.app.plus 129 assert plus is not None 130 131 bui.screenmessage( 132 bui.Lstr( 133 resource='pleaseWaitText', fallback_resource='requestingText' 134 ), 135 color=(0, 1, 0), 136 ) 137 plus.add_v1_account_transaction( 138 { 139 'type': 'ACCOUNT_UNLINK_REQUEST', 140 'accountID': entry['id'], 141 'expire_time': time.time() + 5, 142 } 143 ) 144 plus.run_v1_account_transactions() 145 bui.containerwidget( 146 edit=self._root_widget, transition=self._transition_out 147 ) 148 149 def _cancel(self) -> None: 150 bui.containerwidget( 151 edit=self._root_widget, transition=self._transition_out 152 )
class
AccountUnlinkWindow(bauiv1._uitypes.Window):
17class AccountUnlinkWindow(bui.Window): 18 """A window to kick off account unlinks.""" 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 = 540 35 self._height = 350 36 self._scroll_width = 400 37 self._scroll_height = 200 38 assert bui.app.classic is not None 39 uiscale = bui.app.ui_v1.uiscale 40 base_scale = ( 41 2.0 42 if uiscale is bui.UIScale.SMALL 43 else 1.6 if uiscale is bui.UIScale.MEDIUM else 1.1 44 ) 45 super().__init__( 46 root_widget=bui.containerwidget( 47 size=(self._width, self._height), 48 transition=transition, 49 scale=base_scale, 50 scale_origin_stack_offset=scale_origin, 51 stack_offset=( 52 (0, -10) if uiscale is bui.UIScale.SMALL else (0, 0) 53 ), 54 ) 55 ) 56 self._cancel_button = bui.buttonwidget( 57 parent=self._root_widget, 58 position=(30, self._height - 50), 59 size=(50, 50), 60 scale=0.7, 61 label='', 62 color=bg_color, 63 on_activate_call=self._cancel, 64 autoselect=True, 65 icon=bui.gettexture('crossOut'), 66 iconscale=1.2, 67 ) 68 bui.textwidget( 69 parent=self._root_widget, 70 position=(self._width * 0.5, self._height * 0.88), 71 size=(0, 0), 72 text=bui.Lstr( 73 resource='accountSettingsWindow.unlinkAccountsInstructionsText' 74 ), 75 maxwidth=self._width * 0.7, 76 color=bui.app.ui_v1.infotextcolor, 77 h_align='center', 78 v_align='center', 79 ) 80 bui.containerwidget( 81 edit=self._root_widget, cancel_button=self._cancel_button 82 ) 83 84 self._scrollwidget = bui.scrollwidget( 85 parent=self._root_widget, 86 highlight=False, 87 position=( 88 (self._width - self._scroll_width) * 0.5, 89 self._height - 85 - self._scroll_height, 90 ), 91 size=(self._scroll_width, self._scroll_height), 92 ) 93 bui.containerwidget(edit=self._scrollwidget, claims_left_right=True) 94 self._columnwidget = bui.columnwidget( 95 parent=self._scrollwidget, border=2, margin=0, left_border=10 96 ) 97 98 our_login_id = plus.get_v1_account_public_login_id() 99 if our_login_id is None: 100 entries = [] 101 else: 102 account_infos = plus.get_v1_account_misc_read_val_2( 103 'linkedAccounts2', [] 104 ) 105 entries = [ 106 {'name': ai['d'], 'id': ai['id']} 107 for ai in account_infos 108 if ai['id'] != our_login_id 109 ] 110 111 # (avoid getting our selection stuck on an empty column widget) 112 if not entries: 113 bui.containerwidget(edit=self._scrollwidget, selectable=False) 114 for i, entry in enumerate(entries): 115 txt = bui.textwidget( 116 parent=self._columnwidget, 117 selectable=True, 118 text=entry['name'], 119 size=(self._scroll_width - 30, 30), 120 autoselect=True, 121 click_activate=True, 122 on_activate_call=bui.Call(self._on_entry_selected, entry), 123 ) 124 bui.widget(edit=txt, left_widget=self._cancel_button) 125 if i == 0: 126 bui.widget(edit=txt, up_widget=self._cancel_button) 127 128 def _on_entry_selected(self, entry: dict[str, Any]) -> None: 129 plus = bui.app.plus 130 assert plus is not None 131 132 bui.screenmessage( 133 bui.Lstr( 134 resource='pleaseWaitText', fallback_resource='requestingText' 135 ), 136 color=(0, 1, 0), 137 ) 138 plus.add_v1_account_transaction( 139 { 140 'type': 'ACCOUNT_UNLINK_REQUEST', 141 'accountID': entry['id'], 142 'expire_time': time.time() + 5, 143 } 144 ) 145 plus.run_v1_account_transactions() 146 bui.containerwidget( 147 edit=self._root_widget, transition=self._transition_out 148 ) 149 150 def _cancel(self) -> None: 151 bui.containerwidget( 152 edit=self._root_widget, transition=self._transition_out 153 )
A window to kick off account unlinks.
AccountUnlinkWindow(origin_widget: _bauiv1.Widget | None = None)
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 = 540 35 self._height = 350 36 self._scroll_width = 400 37 self._scroll_height = 200 38 assert bui.app.classic is not None 39 uiscale = bui.app.ui_v1.uiscale 40 base_scale = ( 41 2.0 42 if uiscale is bui.UIScale.SMALL 43 else 1.6 if uiscale is bui.UIScale.MEDIUM else 1.1 44 ) 45 super().__init__( 46 root_widget=bui.containerwidget( 47 size=(self._width, self._height), 48 transition=transition, 49 scale=base_scale, 50 scale_origin_stack_offset=scale_origin, 51 stack_offset=( 52 (0, -10) if uiscale is bui.UIScale.SMALL else (0, 0) 53 ), 54 ) 55 ) 56 self._cancel_button = bui.buttonwidget( 57 parent=self._root_widget, 58 position=(30, self._height - 50), 59 size=(50, 50), 60 scale=0.7, 61 label='', 62 color=bg_color, 63 on_activate_call=self._cancel, 64 autoselect=True, 65 icon=bui.gettexture('crossOut'), 66 iconscale=1.2, 67 ) 68 bui.textwidget( 69 parent=self._root_widget, 70 position=(self._width * 0.5, self._height * 0.88), 71 size=(0, 0), 72 text=bui.Lstr( 73 resource='accountSettingsWindow.unlinkAccountsInstructionsText' 74 ), 75 maxwidth=self._width * 0.7, 76 color=bui.app.ui_v1.infotextcolor, 77 h_align='center', 78 v_align='center', 79 ) 80 bui.containerwidget( 81 edit=self._root_widget, cancel_button=self._cancel_button 82 ) 83 84 self._scrollwidget = bui.scrollwidget( 85 parent=self._root_widget, 86 highlight=False, 87 position=( 88 (self._width - self._scroll_width) * 0.5, 89 self._height - 85 - self._scroll_height, 90 ), 91 size=(self._scroll_width, self._scroll_height), 92 ) 93 bui.containerwidget(edit=self._scrollwidget, claims_left_right=True) 94 self._columnwidget = bui.columnwidget( 95 parent=self._scrollwidget, border=2, margin=0, left_border=10 96 ) 97 98 our_login_id = plus.get_v1_account_public_login_id() 99 if our_login_id is None: 100 entries = [] 101 else: 102 account_infos = plus.get_v1_account_misc_read_val_2( 103 'linkedAccounts2', [] 104 ) 105 entries = [ 106 {'name': ai['d'], 'id': ai['id']} 107 for ai in account_infos 108 if ai['id'] != our_login_id 109 ] 110 111 # (avoid getting our selection stuck on an empty column widget) 112 if not entries: 113 bui.containerwidget(edit=self._scrollwidget, selectable=False) 114 for i, entry in enumerate(entries): 115 txt = bui.textwidget( 116 parent=self._columnwidget, 117 selectable=True, 118 text=entry['name'], 119 size=(self._scroll_width - 30, 30), 120 autoselect=True, 121 click_activate=True, 122 on_activate_call=bui.Call(self._on_entry_selected, entry), 123 ) 124 bui.widget(edit=txt, left_widget=self._cancel_button) 125 if i == 0: 126 bui.widget(edit=txt, up_widget=self._cancel_button)