bauiv1lib.qrcode

Provides functionality for displaying QR codes.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Provides functionality for displaying QR codes."""
 4from __future__ import annotations
 5
 6from typing_extensions import override
 7import bauiv1 as bui
 8
 9from bauiv1lib.popup import PopupWindow
10
11
12class QRCodeWindow(PopupWindow):
13    """Popup window that shows a QR code."""
14
15    def __init__(self, origin_widget: bui.Widget, qr_tex: bui.Texture):
16        position = origin_widget.get_screen_space_center()
17        assert bui.app.classic is not None
18        uiscale = bui.app.ui_v1.uiscale
19        scale = (
20            2.3
21            if uiscale is bui.UIScale.SMALL
22            else 1.65
23            if uiscale is bui.UIScale.MEDIUM
24            else 1.23
25        )
26        self._transitioning_out = False
27        self._width = 450
28        self._height = 400
29        bg_color = (0.5, 0.4, 0.6)
30        super().__init__(
31            position=position,
32            size=(self._width, self._height),
33            scale=scale,
34            bg_color=bg_color,
35        )
36        self._cancel_button = bui.buttonwidget(
37            parent=self.root_widget,
38            position=(50, self._height - 30),
39            size=(50, 50),
40            scale=0.5,
41            label='',
42            color=bg_color,
43            on_activate_call=self._on_cancel_press,
44            autoselect=True,
45            icon=bui.gettexture('crossOut'),
46            iconscale=1.2,
47        )
48        bui.imagewidget(
49            parent=self.root_widget,
50            position=(self._width * 0.5 - 150, self._height * 0.5 - 150),
51            size=(300, 300),
52            texture=qr_tex,
53        )
54
55    def _on_cancel_press(self) -> None:
56        self._transition_out()
57
58    def _transition_out(self) -> None:
59        if not self._transitioning_out:
60            self._transitioning_out = True
61            bui.containerwidget(edit=self.root_widget, transition='out_scale')
62
63    @override
64    def on_popup_cancel(self) -> None:
65        bui.getsound('swish').play()
66        self._transition_out()
class QRCodeWindow(bauiv1lib.popup.PopupWindow):
13class QRCodeWindow(PopupWindow):
14    """Popup window that shows a QR code."""
15
16    def __init__(self, origin_widget: bui.Widget, qr_tex: bui.Texture):
17        position = origin_widget.get_screen_space_center()
18        assert bui.app.classic is not None
19        uiscale = bui.app.ui_v1.uiscale
20        scale = (
21            2.3
22            if uiscale is bui.UIScale.SMALL
23            else 1.65
24            if uiscale is bui.UIScale.MEDIUM
25            else 1.23
26        )
27        self._transitioning_out = False
28        self._width = 450
29        self._height = 400
30        bg_color = (0.5, 0.4, 0.6)
31        super().__init__(
32            position=position,
33            size=(self._width, self._height),
34            scale=scale,
35            bg_color=bg_color,
36        )
37        self._cancel_button = bui.buttonwidget(
38            parent=self.root_widget,
39            position=(50, self._height - 30),
40            size=(50, 50),
41            scale=0.5,
42            label='',
43            color=bg_color,
44            on_activate_call=self._on_cancel_press,
45            autoselect=True,
46            icon=bui.gettexture('crossOut'),
47            iconscale=1.2,
48        )
49        bui.imagewidget(
50            parent=self.root_widget,
51            position=(self._width * 0.5 - 150, self._height * 0.5 - 150),
52            size=(300, 300),
53            texture=qr_tex,
54        )
55
56    def _on_cancel_press(self) -> None:
57        self._transition_out()
58
59    def _transition_out(self) -> None:
60        if not self._transitioning_out:
61            self._transitioning_out = True
62            bui.containerwidget(edit=self.root_widget, transition='out_scale')
63
64    @override
65    def on_popup_cancel(self) -> None:
66        bui.getsound('swish').play()
67        self._transition_out()

Popup window that shows a QR code.

QRCodeWindow(origin_widget: _bauiv1.Widget, qr_tex: _bauiv1.Texture)
16    def __init__(self, origin_widget: bui.Widget, qr_tex: bui.Texture):
17        position = origin_widget.get_screen_space_center()
18        assert bui.app.classic is not None
19        uiscale = bui.app.ui_v1.uiscale
20        scale = (
21            2.3
22            if uiscale is bui.UIScale.SMALL
23            else 1.65
24            if uiscale is bui.UIScale.MEDIUM
25            else 1.23
26        )
27        self._transitioning_out = False
28        self._width = 450
29        self._height = 400
30        bg_color = (0.5, 0.4, 0.6)
31        super().__init__(
32            position=position,
33            size=(self._width, self._height),
34            scale=scale,
35            bg_color=bg_color,
36        )
37        self._cancel_button = bui.buttonwidget(
38            parent=self.root_widget,
39            position=(50, self._height - 30),
40            size=(50, 50),
41            scale=0.5,
42            label='',
43            color=bg_color,
44            on_activate_call=self._on_cancel_press,
45            autoselect=True,
46            icon=bui.gettexture('crossOut'),
47            iconscale=1.2,
48        )
49        bui.imagewidget(
50            parent=self.root_widget,
51            position=(self._width * 0.5 - 150, self._height * 0.5 - 150),
52            size=(300, 300),
53            texture=qr_tex,
54        )
@override
def on_popup_cancel(self) -> None:
64    @override
65    def on_popup_cancel(self) -> None:
66        bui.getsound('swish').play()
67        self._transition_out()

Called when the popup is canceled.

Cancels can occur due to clicking outside the window, hitting escape, etc.