bauiv1lib.url
UI functionality related to URLs.
1# Released under the MIT License. See LICENSE for details. 2# 3"""UI functionality related to URLs.""" 4 5from __future__ import annotations 6 7import bauiv1 as bui 8 9 10class ShowURLWindow(bui.Window): 11 """A window presenting a URL to the user visually.""" 12 13 def __init__(self, address: str): 14 # in some cases we might want to show it as a qr code 15 # (for long URLs especially) 16 app = bui.app 17 assert app.classic is not None 18 uiscale = app.ui_v1.uiscale 19 self._address = address 20 21 self._width = 800 22 self._height = 450 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 31 if uiscale is bui.UIScale.MEDIUM 32 else 1.25 33 ), 34 ) 35 ) 36 bui.textwidget( 37 parent=self._root_widget, 38 position=(self._width * 0.5, self._height - 10), 39 size=(0, 0), 40 color=app.ui_v1.title_color, 41 h_align='center', 42 v_align='center', 43 text=bui.Lstr(resource='directBrowserToURLText'), 44 maxwidth=self._width * 0.95, 45 ) 46 bui.textwidget( 47 parent=self._root_widget, 48 position=(self._width * 0.5, self._height - 60), 49 size=(0, 0), 50 scale=1.3, 51 color=app.ui_v1.infotextcolor, 52 h_align='center', 53 v_align='center', 54 text=address, 55 maxwidth=self._width * 0.95, 56 ) 57 button_width = 200 58 59 qr_size = 220 60 bui.imagewidget( 61 parent=self._root_widget, 62 position=( 63 self._width * 0.5 - qr_size * 0.5, 64 self._height * 0.5 - qr_size * 0.5 + 10, 65 ), 66 size=(qr_size, qr_size), 67 texture=bui.get_qrcode_texture(address), 68 ) 69 70 xoffs = 0 71 if bui.clipboard_is_supported(): 72 xoffs = -150 73 btn = bui.buttonwidget( 74 parent=self._root_widget, 75 position=( 76 self._width * 0.5 - button_width * 0.5 + xoffs, 77 20, 78 ), 79 size=(button_width, 65), 80 autoselect=True, 81 label=bui.Lstr(resource='copyText'), 82 on_activate_call=self._copy, 83 ) 84 xoffs = 150 85 86 btn = bui.buttonwidget( 87 parent=self._root_widget, 88 position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20), 89 size=(button_width, 65), 90 autoselect=True, 91 label=bui.Lstr(resource='doneText'), 92 on_activate_call=self._done, 93 ) 94 # we have no 'cancel' button but still want to be able to 95 # hit back/escape/etc to leave.. 96 bui.containerwidget( 97 edit=self._root_widget, 98 selected_child=btn, 99 start_button=btn, 100 on_cancel_call=btn.activate, 101 ) 102 103 def _copy(self) -> None: 104 bui.clipboard_set_text(self._address) 105 bui.screenmessage(bui.Lstr(resource='copyConfirmText'), color=(0, 1, 0)) 106 107 def _done(self) -> None: 108 bui.containerwidget(edit=self._root_widget, transition='out_left')
class
ShowURLWindow(bauiv1._uitypes.Window):
11class ShowURLWindow(bui.Window): 12 """A window presenting a URL to the user visually.""" 13 14 def __init__(self, address: str): 15 # in some cases we might want to show it as a qr code 16 # (for long URLs especially) 17 app = bui.app 18 assert app.classic is not None 19 uiscale = app.ui_v1.uiscale 20 self._address = address 21 22 self._width = 800 23 self._height = 450 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.textwidget( 38 parent=self._root_widget, 39 position=(self._width * 0.5, self._height - 10), 40 size=(0, 0), 41 color=app.ui_v1.title_color, 42 h_align='center', 43 v_align='center', 44 text=bui.Lstr(resource='directBrowserToURLText'), 45 maxwidth=self._width * 0.95, 46 ) 47 bui.textwidget( 48 parent=self._root_widget, 49 position=(self._width * 0.5, self._height - 60), 50 size=(0, 0), 51 scale=1.3, 52 color=app.ui_v1.infotextcolor, 53 h_align='center', 54 v_align='center', 55 text=address, 56 maxwidth=self._width * 0.95, 57 ) 58 button_width = 200 59 60 qr_size = 220 61 bui.imagewidget( 62 parent=self._root_widget, 63 position=( 64 self._width * 0.5 - qr_size * 0.5, 65 self._height * 0.5 - qr_size * 0.5 + 10, 66 ), 67 size=(qr_size, qr_size), 68 texture=bui.get_qrcode_texture(address), 69 ) 70 71 xoffs = 0 72 if bui.clipboard_is_supported(): 73 xoffs = -150 74 btn = bui.buttonwidget( 75 parent=self._root_widget, 76 position=( 77 self._width * 0.5 - button_width * 0.5 + xoffs, 78 20, 79 ), 80 size=(button_width, 65), 81 autoselect=True, 82 label=bui.Lstr(resource='copyText'), 83 on_activate_call=self._copy, 84 ) 85 xoffs = 150 86 87 btn = bui.buttonwidget( 88 parent=self._root_widget, 89 position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20), 90 size=(button_width, 65), 91 autoselect=True, 92 label=bui.Lstr(resource='doneText'), 93 on_activate_call=self._done, 94 ) 95 # we have no 'cancel' button but still want to be able to 96 # hit back/escape/etc to leave.. 97 bui.containerwidget( 98 edit=self._root_widget, 99 selected_child=btn, 100 start_button=btn, 101 on_cancel_call=btn.activate, 102 ) 103 104 def _copy(self) -> None: 105 bui.clipboard_set_text(self._address) 106 bui.screenmessage(bui.Lstr(resource='copyConfirmText'), color=(0, 1, 0)) 107 108 def _done(self) -> None: 109 bui.containerwidget(edit=self._root_widget, transition='out_left')
A window presenting a URL to the user visually.
ShowURLWindow(address: str)
14 def __init__(self, address: str): 15 # in some cases we might want to show it as a qr code 16 # (for long URLs especially) 17 app = bui.app 18 assert app.classic is not None 19 uiscale = app.ui_v1.uiscale 20 self._address = address 21 22 self._width = 800 23 self._height = 450 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.textwidget( 38 parent=self._root_widget, 39 position=(self._width * 0.5, self._height - 10), 40 size=(0, 0), 41 color=app.ui_v1.title_color, 42 h_align='center', 43 v_align='center', 44 text=bui.Lstr(resource='directBrowserToURLText'), 45 maxwidth=self._width * 0.95, 46 ) 47 bui.textwidget( 48 parent=self._root_widget, 49 position=(self._width * 0.5, self._height - 60), 50 size=(0, 0), 51 scale=1.3, 52 color=app.ui_v1.infotextcolor, 53 h_align='center', 54 v_align='center', 55 text=address, 56 maxwidth=self._width * 0.95, 57 ) 58 button_width = 200 59 60 qr_size = 220 61 bui.imagewidget( 62 parent=self._root_widget, 63 position=( 64 self._width * 0.5 - qr_size * 0.5, 65 self._height * 0.5 - qr_size * 0.5 + 10, 66 ), 67 size=(qr_size, qr_size), 68 texture=bui.get_qrcode_texture(address), 69 ) 70 71 xoffs = 0 72 if bui.clipboard_is_supported(): 73 xoffs = -150 74 btn = bui.buttonwidget( 75 parent=self._root_widget, 76 position=( 77 self._width * 0.5 - button_width * 0.5 + xoffs, 78 20, 79 ), 80 size=(button_width, 65), 81 autoselect=True, 82 label=bui.Lstr(resource='copyText'), 83 on_activate_call=self._copy, 84 ) 85 xoffs = 150 86 87 btn = bui.buttonwidget( 88 parent=self._root_widget, 89 position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20), 90 size=(button_width, 65), 91 autoselect=True, 92 label=bui.Lstr(resource='doneText'), 93 on_activate_call=self._done, 94 ) 95 # we have no 'cancel' button but still want to be able to 96 # hit back/escape/etc to leave.. 97 bui.containerwidget( 98 edit=self._root_widget, 99 selected_child=btn, 100 start_button=btn, 101 on_cancel_call=btn.activate, 102 )
Inherited Members
- bauiv1._uitypes.Window
- get_root_widget