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 if uiscale is bui.UIScale.MEDIUM else 1.25
 31                ),
 32            )
 33        )
 34        bui.textwidget(
 35            parent=self._root_widget,
 36            position=(self._width * 0.5, self._height - 10),
 37            size=(0, 0),
 38            color=app.ui_v1.title_color,
 39            h_align='center',
 40            v_align='center',
 41            text=bui.Lstr(resource='directBrowserToURLText'),
 42            maxwidth=self._width * 0.95,
 43        )
 44        bui.textwidget(
 45            parent=self._root_widget,
 46            position=(self._width * 0.5, self._height - 60),
 47            size=(0, 0),
 48            scale=1.3,
 49            color=app.ui_v1.infotextcolor,
 50            h_align='center',
 51            v_align='center',
 52            text=address,
 53            maxwidth=self._width * 0.95,
 54        )
 55        button_width = 200
 56
 57        qr_size = 220
 58        bui.imagewidget(
 59            parent=self._root_widget,
 60            position=(
 61                self._width * 0.5 - qr_size * 0.5,
 62                self._height * 0.5 - qr_size * 0.5 + 10,
 63            ),
 64            size=(qr_size, qr_size),
 65            texture=bui.get_qrcode_texture(address),
 66        )
 67
 68        xoffs = 0
 69        if bui.clipboard_is_supported():
 70            xoffs = -150
 71            btn = bui.buttonwidget(
 72                parent=self._root_widget,
 73                position=(
 74                    self._width * 0.5 - button_width * 0.5 + xoffs,
 75                    20,
 76                ),
 77                size=(button_width, 65),
 78                autoselect=True,
 79                label=bui.Lstr(resource='copyText'),
 80                on_activate_call=self._copy,
 81            )
 82            xoffs = 150
 83
 84        btn = bui.buttonwidget(
 85            parent=self._root_widget,
 86            position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20),
 87            size=(button_width, 65),
 88            autoselect=True,
 89            label=bui.Lstr(resource='doneText'),
 90            on_activate_call=self._done,
 91        )
 92        # we have no 'cancel' button but still want to be able to
 93        # hit back/escape/etc to leave..
 94        bui.containerwidget(
 95            edit=self._root_widget,
 96            selected_child=btn,
 97            start_button=btn,
 98            on_cancel_call=btn.activate,
 99        )
100
101    def _copy(self) -> None:
102        bui.clipboard_set_text(self._address)
103        bui.screenmessage(bui.Lstr(resource='copyConfirmText'), color=(0, 1, 0))
104
105    def _done(self) -> None:
106        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 if uiscale is bui.UIScale.MEDIUM else 1.25
 32                ),
 33            )
 34        )
 35        bui.textwidget(
 36            parent=self._root_widget,
 37            position=(self._width * 0.5, self._height - 10),
 38            size=(0, 0),
 39            color=app.ui_v1.title_color,
 40            h_align='center',
 41            v_align='center',
 42            text=bui.Lstr(resource='directBrowserToURLText'),
 43            maxwidth=self._width * 0.95,
 44        )
 45        bui.textwidget(
 46            parent=self._root_widget,
 47            position=(self._width * 0.5, self._height - 60),
 48            size=(0, 0),
 49            scale=1.3,
 50            color=app.ui_v1.infotextcolor,
 51            h_align='center',
 52            v_align='center',
 53            text=address,
 54            maxwidth=self._width * 0.95,
 55        )
 56        button_width = 200
 57
 58        qr_size = 220
 59        bui.imagewidget(
 60            parent=self._root_widget,
 61            position=(
 62                self._width * 0.5 - qr_size * 0.5,
 63                self._height * 0.5 - qr_size * 0.5 + 10,
 64            ),
 65            size=(qr_size, qr_size),
 66            texture=bui.get_qrcode_texture(address),
 67        )
 68
 69        xoffs = 0
 70        if bui.clipboard_is_supported():
 71            xoffs = -150
 72            btn = bui.buttonwidget(
 73                parent=self._root_widget,
 74                position=(
 75                    self._width * 0.5 - button_width * 0.5 + xoffs,
 76                    20,
 77                ),
 78                size=(button_width, 65),
 79                autoselect=True,
 80                label=bui.Lstr(resource='copyText'),
 81                on_activate_call=self._copy,
 82            )
 83            xoffs = 150
 84
 85        btn = bui.buttonwidget(
 86            parent=self._root_widget,
 87            position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20),
 88            size=(button_width, 65),
 89            autoselect=True,
 90            label=bui.Lstr(resource='doneText'),
 91            on_activate_call=self._done,
 92        )
 93        # we have no 'cancel' button but still want to be able to
 94        # hit back/escape/etc to leave..
 95        bui.containerwidget(
 96            edit=self._root_widget,
 97            selected_child=btn,
 98            start_button=btn,
 99            on_cancel_call=btn.activate,
100        )
101
102    def _copy(self) -> None:
103        bui.clipboard_set_text(self._address)
104        bui.screenmessage(bui.Lstr(resource='copyConfirmText'), color=(0, 1, 0))
105
106    def _done(self) -> None:
107        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 if uiscale is bui.UIScale.MEDIUM else 1.25
 32                ),
 33            )
 34        )
 35        bui.textwidget(
 36            parent=self._root_widget,
 37            position=(self._width * 0.5, self._height - 10),
 38            size=(0, 0),
 39            color=app.ui_v1.title_color,
 40            h_align='center',
 41            v_align='center',
 42            text=bui.Lstr(resource='directBrowserToURLText'),
 43            maxwidth=self._width * 0.95,
 44        )
 45        bui.textwidget(
 46            parent=self._root_widget,
 47            position=(self._width * 0.5, self._height - 60),
 48            size=(0, 0),
 49            scale=1.3,
 50            color=app.ui_v1.infotextcolor,
 51            h_align='center',
 52            v_align='center',
 53            text=address,
 54            maxwidth=self._width * 0.95,
 55        )
 56        button_width = 200
 57
 58        qr_size = 220
 59        bui.imagewidget(
 60            parent=self._root_widget,
 61            position=(
 62                self._width * 0.5 - qr_size * 0.5,
 63                self._height * 0.5 - qr_size * 0.5 + 10,
 64            ),
 65            size=(qr_size, qr_size),
 66            texture=bui.get_qrcode_texture(address),
 67        )
 68
 69        xoffs = 0
 70        if bui.clipboard_is_supported():
 71            xoffs = -150
 72            btn = bui.buttonwidget(
 73                parent=self._root_widget,
 74                position=(
 75                    self._width * 0.5 - button_width * 0.5 + xoffs,
 76                    20,
 77                ),
 78                size=(button_width, 65),
 79                autoselect=True,
 80                label=bui.Lstr(resource='copyText'),
 81                on_activate_call=self._copy,
 82            )
 83            xoffs = 150
 84
 85        btn = bui.buttonwidget(
 86            parent=self._root_widget,
 87            position=(self._width * 0.5 - button_width * 0.5 + xoffs, 20),
 88            size=(button_width, 65),
 89            autoselect=True,
 90            label=bui.Lstr(resource='doneText'),
 91            on_activate_call=self._done,
 92        )
 93        # we have no 'cancel' button but still want to be able to
 94        # hit back/escape/etc to leave..
 95        bui.containerwidget(
 96            edit=self._root_widget,
 97            selected_child=btn,
 98            start_button=btn,
 99            on_cancel_call=btn.activate,
100        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget