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

Popup window that shows a QR code.

QRCodeWindow(origin_widget: _bauiv1.Widget, qr_tex: _bauiv1.Texture)
17    def __init__(self, origin_widget: bui.Widget, qr_tex: bui.Texture):
18        position = origin_widget.get_screen_space_center()
19        assert bui.app.classic is not None
20        uiscale = bui.app.ui_v1.uiscale
21        scale = (
22            2.3
23            if uiscale is bui.UIScale.SMALL
24            else 1.65 if uiscale is bui.UIScale.MEDIUM 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        )
@override
def on_popup_cancel(self) -> None:
63    @override
64    def on_popup_cancel(self) -> None:
65        bui.getsound('swish').play()
66        self._transition_out()

Called when the popup is canceled.

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