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

Popup window that shows a QR code.

QRCodeWindow(origin_widget: _ba.Widget, qr_tex: _ba.Texture)
14    def __init__(self, origin_widget: ba.Widget, qr_tex: ba.Texture):
15
16        position = origin_widget.get_screen_space_center()
17        uiscale = ba.app.ui.uiscale
18        scale = (2.3 if uiscale is ba.UIScale.SMALL else
19                 1.65 if uiscale is ba.UIScale.MEDIUM else 1.23)
20        self._transitioning_out = False
21        self._width = 450
22        self._height = 400
23        bg_color = (0.5, 0.4, 0.6)
24        popup.PopupWindow.__init__(self,
25                                   position=position,
26                                   size=(self._width, self._height),
27                                   scale=scale,
28                                   bg_color=bg_color)
29        self._cancel_button = ba.buttonwidget(
30            parent=self.root_widget,
31            position=(50, self._height - 30),
32            size=(50, 50),
33            scale=0.5,
34            label='',
35            color=bg_color,
36            on_activate_call=self._on_cancel_press,
37            autoselect=True,
38            icon=ba.gettexture('crossOut'),
39            iconscale=1.2)
40        ba.imagewidget(parent=self.root_widget,
41                       position=(self._width * 0.5 - 150,
42                                 self._height * 0.5 - 150),
43                       size=(300, 300),
44                       texture=qr_tex)
def on_popup_cancel(self) -> None:
54    def on_popup_cancel(self) -> None:
55        ba.playsound(ba.getsound('swish'))
56        self._transition_out()

Called when the popup is canceled.

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