Bombsquad-Ballistica-Modded.../dist/ba_data/python/bauiv1lib/qrcode.py

66 lines
1.9 KiB
Python
Raw Permalink Normal View History

2021-03-29 03:24:13 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""Provides functionality for displaying QR codes."""
from __future__ import annotations
2024-05-19 18:25:43 +05:30
from typing import override
2023-08-13 17:21:49 +05:30
import bauiv1 as bui
2021-03-29 03:24:13 +05:30
2024-01-27 21:25:16 +05:30
from bauiv1lib.popup import PopupWindow
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
class QRCodeWindow(PopupWindow):
2021-03-29 03:24:13 +05:30
"""Popup window that shows a QR code."""
2023-08-13 17:21:49 +05:30
def __init__(self, origin_widget: bui.Widget, qr_tex: bui.Texture):
2021-03-29 03:24:13 +05:30
position = origin_widget.get_screen_space_center()
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
uiscale = bui.app.ui_v1.uiscale
scale = (
2.3
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
2024-05-19 18:25:43 +05:30
else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
)
2021-03-29 03:24:13 +05:30
self._transitioning_out = False
self._width = 450
self._height = 400
bg_color = (0.5, 0.4, 0.6)
2023-08-13 17:21:49 +05:30
super().__init__(
position=position,
size=(self._width, self._height),
scale=scale,
bg_color=bg_color,
)
2023-08-13 17:21:49 +05:30
self._cancel_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self.root_widget,
position=(50, self._height - 30),
size=(50, 50),
scale=0.5,
label='',
color=bg_color,
on_activate_call=self._on_cancel_press,
autoselect=True,
2023-08-13 17:21:49 +05:30
icon=bui.gettexture('crossOut'),
iconscale=1.2,
)
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self.root_widget,
position=(self._width * 0.5 - 150, self._height * 0.5 - 150),
size=(300, 300),
texture=qr_tex,
)
2021-03-29 03:24:13 +05:30
def _on_cancel_press(self) -> None:
self._transition_out()
def _transition_out(self) -> None:
if not self._transitioning_out:
self._transitioning_out = True
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self.root_widget, transition='out_scale')
2021-03-29 03:24:13 +05:30
2024-01-27 21:25:16 +05:30
@override
2021-03-29 03:24:13 +05:30
def on_popup_cancel(self) -> None:
2023-08-13 17:21:49 +05:30
bui.getsound('swish').play()
2021-03-29 03:24:13 +05:30
self._transition_out()