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

Popup window that shows a QR code.

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

Called when the popup is canceled.

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