bastd.ui.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 _ba
 8import ba
 9
10
11class ShowURLWindow(ba.Window):
12    """A window presenting a URL to the user visually."""
13
14    def __init__(self, address: str):
15
16        # in some cases we might want to show it as a qr code
17        # (for long URLs especially)
18        app = ba.app
19        uiscale = app.ui.uiscale
20        if app.platform == 'android' and app.subplatform == 'alibaba':
21            self._width = 500
22            self._height = 500
23            super().__init__(root_widget=ba.containerwidget(
24                size=(self._width, self._height),
25                transition='in_right',
26                scale=(1.25 if uiscale is ba.UIScale.SMALL else
27                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25)))
28            self._cancel_button = ba.buttonwidget(
29                parent=self._root_widget,
30                position=(50, self._height - 30),
31                size=(50, 50),
32                scale=0.6,
33                label='',
34                color=(0.6, 0.5, 0.6),
35                on_activate_call=self._done,
36                autoselect=True,
37                icon=ba.gettexture('crossOut'),
38                iconscale=1.2)
39            qr_size = 400
40            ba.imagewidget(parent=self._root_widget,
41                           position=(self._width * 0.5 - qr_size * 0.5,
42                                     self._height * 0.5 - qr_size * 0.5),
43                           size=(qr_size, qr_size),
44                           texture=_ba.get_qrcode_texture(address))
45            ba.containerwidget(edit=self._root_widget,
46                               cancel_button=self._cancel_button)
47        else:
48            # show it as a simple string...
49            self._width = 800
50            self._height = 200
51            self._root_widget = ba.containerwidget(
52                size=(self._width, self._height + 40),
53                transition='in_right',
54                scale=(1.25 if uiscale is ba.UIScale.SMALL else
55                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25))
56            ba.textwidget(parent=self._root_widget,
57                          position=(self._width * 0.5, self._height - 10),
58                          size=(0, 0),
59                          color=ba.app.ui.title_color,
60                          h_align='center',
61                          v_align='center',
62                          text=ba.Lstr(resource='directBrowserToURLText'),
63                          maxwidth=self._width * 0.95)
64            ba.textwidget(parent=self._root_widget,
65                          position=(self._width * 0.5,
66                                    self._height * 0.5 + 29),
67                          size=(0, 0),
68                          scale=1.3,
69                          color=ba.app.ui.infotextcolor,
70                          h_align='center',
71                          v_align='center',
72                          text=address,
73                          maxwidth=self._width * 0.95)
74            button_width = 200
75            btn = ba.buttonwidget(parent=self._root_widget,
76                                  position=(self._width * 0.5 -
77                                            button_width * 0.5, 20),
78                                  size=(button_width, 65),
79                                  label=ba.Lstr(resource='doneText'),
80                                  on_activate_call=self._done)
81            # we have no 'cancel' button but still want to be able to
82            # hit back/escape/etc to leave..
83            ba.containerwidget(edit=self._root_widget,
84                               selected_child=btn,
85                               start_button=btn,
86                               on_cancel_call=btn.activate)
87
88    def _done(self) -> None:
89        ba.containerwidget(edit=self._root_widget, transition='out_left')
class ShowURLWindow(ba.ui.Window):
12class ShowURLWindow(ba.Window):
13    """A window presenting a URL to the user visually."""
14
15    def __init__(self, address: str):
16
17        # in some cases we might want to show it as a qr code
18        # (for long URLs especially)
19        app = ba.app
20        uiscale = app.ui.uiscale
21        if app.platform == 'android' and app.subplatform == 'alibaba':
22            self._width = 500
23            self._height = 500
24            super().__init__(root_widget=ba.containerwidget(
25                size=(self._width, self._height),
26                transition='in_right',
27                scale=(1.25 if uiscale is ba.UIScale.SMALL else
28                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25)))
29            self._cancel_button = ba.buttonwidget(
30                parent=self._root_widget,
31                position=(50, self._height - 30),
32                size=(50, 50),
33                scale=0.6,
34                label='',
35                color=(0.6, 0.5, 0.6),
36                on_activate_call=self._done,
37                autoselect=True,
38                icon=ba.gettexture('crossOut'),
39                iconscale=1.2)
40            qr_size = 400
41            ba.imagewidget(parent=self._root_widget,
42                           position=(self._width * 0.5 - qr_size * 0.5,
43                                     self._height * 0.5 - qr_size * 0.5),
44                           size=(qr_size, qr_size),
45                           texture=_ba.get_qrcode_texture(address))
46            ba.containerwidget(edit=self._root_widget,
47                               cancel_button=self._cancel_button)
48        else:
49            # show it as a simple string...
50            self._width = 800
51            self._height = 200
52            self._root_widget = ba.containerwidget(
53                size=(self._width, self._height + 40),
54                transition='in_right',
55                scale=(1.25 if uiscale is ba.UIScale.SMALL else
56                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25))
57            ba.textwidget(parent=self._root_widget,
58                          position=(self._width * 0.5, self._height - 10),
59                          size=(0, 0),
60                          color=ba.app.ui.title_color,
61                          h_align='center',
62                          v_align='center',
63                          text=ba.Lstr(resource='directBrowserToURLText'),
64                          maxwidth=self._width * 0.95)
65            ba.textwidget(parent=self._root_widget,
66                          position=(self._width * 0.5,
67                                    self._height * 0.5 + 29),
68                          size=(0, 0),
69                          scale=1.3,
70                          color=ba.app.ui.infotextcolor,
71                          h_align='center',
72                          v_align='center',
73                          text=address,
74                          maxwidth=self._width * 0.95)
75            button_width = 200
76            btn = ba.buttonwidget(parent=self._root_widget,
77                                  position=(self._width * 0.5 -
78                                            button_width * 0.5, 20),
79                                  size=(button_width, 65),
80                                  label=ba.Lstr(resource='doneText'),
81                                  on_activate_call=self._done)
82            # we have no 'cancel' button but still want to be able to
83            # hit back/escape/etc to leave..
84            ba.containerwidget(edit=self._root_widget,
85                               selected_child=btn,
86                               start_button=btn,
87                               on_cancel_call=btn.activate)
88
89    def _done(self) -> None:
90        ba.containerwidget(edit=self._root_widget, transition='out_left')

A window presenting a URL to the user visually.

ShowURLWindow(address: str)
15    def __init__(self, address: str):
16
17        # in some cases we might want to show it as a qr code
18        # (for long URLs especially)
19        app = ba.app
20        uiscale = app.ui.uiscale
21        if app.platform == 'android' and app.subplatform == 'alibaba':
22            self._width = 500
23            self._height = 500
24            super().__init__(root_widget=ba.containerwidget(
25                size=(self._width, self._height),
26                transition='in_right',
27                scale=(1.25 if uiscale is ba.UIScale.SMALL else
28                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25)))
29            self._cancel_button = ba.buttonwidget(
30                parent=self._root_widget,
31                position=(50, self._height - 30),
32                size=(50, 50),
33                scale=0.6,
34                label='',
35                color=(0.6, 0.5, 0.6),
36                on_activate_call=self._done,
37                autoselect=True,
38                icon=ba.gettexture('crossOut'),
39                iconscale=1.2)
40            qr_size = 400
41            ba.imagewidget(parent=self._root_widget,
42                           position=(self._width * 0.5 - qr_size * 0.5,
43                                     self._height * 0.5 - qr_size * 0.5),
44                           size=(qr_size, qr_size),
45                           texture=_ba.get_qrcode_texture(address))
46            ba.containerwidget(edit=self._root_widget,
47                               cancel_button=self._cancel_button)
48        else:
49            # show it as a simple string...
50            self._width = 800
51            self._height = 200
52            self._root_widget = ba.containerwidget(
53                size=(self._width, self._height + 40),
54                transition='in_right',
55                scale=(1.25 if uiscale is ba.UIScale.SMALL else
56                       1.25 if uiscale is ba.UIScale.MEDIUM else 1.25))
57            ba.textwidget(parent=self._root_widget,
58                          position=(self._width * 0.5, self._height - 10),
59                          size=(0, 0),
60                          color=ba.app.ui.title_color,
61                          h_align='center',
62                          v_align='center',
63                          text=ba.Lstr(resource='directBrowserToURLText'),
64                          maxwidth=self._width * 0.95)
65            ba.textwidget(parent=self._root_widget,
66                          position=(self._width * 0.5,
67                                    self._height * 0.5 + 29),
68                          size=(0, 0),
69                          scale=1.3,
70                          color=ba.app.ui.infotextcolor,
71                          h_align='center',
72                          v_align='center',
73                          text=address,
74                          maxwidth=self._width * 0.95)
75            button_width = 200
76            btn = ba.buttonwidget(parent=self._root_widget,
77                                  position=(self._width * 0.5 -
78                                            button_width * 0.5, 20),
79                                  size=(button_width, 65),
80                                  label=ba.Lstr(resource='doneText'),
81                                  on_activate_call=self._done)
82            # we have no 'cancel' button but still want to be able to
83            # hit back/escape/etc to leave..
84            ba.containerwidget(edit=self._root_widget,
85                               selected_child=btn,
86                               start_button=btn,
87                               on_cancel_call=btn.activate)
Inherited Members
ba.ui.Window
get_root_widget