bauiv1lib.inbox

Provides a popup window to view achievements.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Provides a popup window to view achievements."""
  4
  5from __future__ import annotations
  6
  7from typing import override
  8
  9from bauiv1lib.popup import PopupWindow
 10import bauiv1 as bui
 11
 12
 13class InboxWindow(PopupWindow):
 14    """Popup window to show account messages."""
 15
 16    def __init__(
 17        self, position: tuple[float, float], scale: float | None = None
 18    ):
 19        assert bui.app.classic is not None
 20        uiscale = bui.app.ui_v1.uiscale
 21        if scale is None:
 22            scale = (
 23                2.3
 24                if uiscale is bui.UIScale.SMALL
 25                else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 26            )
 27        self._transitioning_out = False
 28        self._width = 450
 29        self._height = (
 30            300
 31            if uiscale is bui.UIScale.SMALL
 32            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 33        )
 34        bg_color = (0.5, 0.4, 0.6)
 35
 36        # creates our _root_widget
 37        super().__init__(
 38            position=position,
 39            size=(self._width, self._height),
 40            scale=scale,
 41            bg_color=bg_color,
 42            edge_buffer_scale=4.0,  # Try to keep button unobscured.
 43        )
 44
 45        self._cancel_button = bui.buttonwidget(
 46            parent=self.root_widget,
 47            position=(50, self._height - 30),
 48            size=(50, 50),
 49            scale=0.5,
 50            label='',
 51            color=bg_color,
 52            on_activate_call=self._on_cancel_press,
 53            autoselect=True,
 54            icon=bui.gettexture('crossOut'),
 55            iconscale=1.2,
 56        )
 57
 58        self._title_text = bui.textwidget(
 59            parent=self.root_widget,
 60            position=(self._width * 0.5, self._height - 20),
 61            size=(0, 0),
 62            h_align='center',
 63            v_align='center',
 64            scale=0.6,
 65            text='INBOX (UNDER CONSTRUCTION)',
 66            maxwidth=200,
 67            color=bui.app.ui_v1.title_color,
 68        )
 69
 70        self._scrollwidget = bui.scrollwidget(
 71            parent=self.root_widget,
 72            size=(self._width - 60, self._height - 70),
 73            position=(30, 30),
 74            capture_arrows=True,
 75            simple_culling_v=10,
 76        )
 77        bui.widget(edit=self._scrollwidget, autoselect=True)
 78
 79        bui.containerwidget(
 80            edit=self.root_widget, cancel_button=self._cancel_button
 81        )
 82
 83        entries: list[str] = []
 84        incr = 20
 85        sub_width = self._width - 90
 86        sub_height = 40 + len(entries) * incr
 87
 88        self._subcontainer = bui.containerwidget(
 89            parent=self._scrollwidget,
 90            size=(sub_width, sub_height),
 91            background=False,
 92        )
 93
 94        for i, entry in enumerate(entries):
 95            bui.textwidget(
 96                parent=self._subcontainer,
 97                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
 98                maxwidth=20,
 99                scale=0.5,
100                flatness=1.0,
101                shadow=0.0,
102                text=entry,
103                size=(0, 0),
104                h_align='right',
105                v_align='center',
106            )
107
108    def _on_cancel_press(self) -> None:
109        self._transition_out()
110
111    def _transition_out(self) -> None:
112        if not self._transitioning_out:
113            self._transitioning_out = True
114            bui.containerwidget(edit=self.root_widget, transition='out_scale')
115
116    @override
117    def on_popup_cancel(self) -> None:
118        bui.getsound('swish').play()
119        self._transition_out()
class InboxWindow(bauiv1lib.popup.PopupWindow):
 14class InboxWindow(PopupWindow):
 15    """Popup window to show account messages."""
 16
 17    def __init__(
 18        self, position: tuple[float, float], scale: float | None = None
 19    ):
 20        assert bui.app.classic is not None
 21        uiscale = bui.app.ui_v1.uiscale
 22        if scale is None:
 23            scale = (
 24                2.3
 25                if uiscale is bui.UIScale.SMALL
 26                else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 27            )
 28        self._transitioning_out = False
 29        self._width = 450
 30        self._height = (
 31            300
 32            if uiscale is bui.UIScale.SMALL
 33            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 34        )
 35        bg_color = (0.5, 0.4, 0.6)
 36
 37        # creates our _root_widget
 38        super().__init__(
 39            position=position,
 40            size=(self._width, self._height),
 41            scale=scale,
 42            bg_color=bg_color,
 43            edge_buffer_scale=4.0,  # Try to keep button unobscured.
 44        )
 45
 46        self._cancel_button = bui.buttonwidget(
 47            parent=self.root_widget,
 48            position=(50, self._height - 30),
 49            size=(50, 50),
 50            scale=0.5,
 51            label='',
 52            color=bg_color,
 53            on_activate_call=self._on_cancel_press,
 54            autoselect=True,
 55            icon=bui.gettexture('crossOut'),
 56            iconscale=1.2,
 57        )
 58
 59        self._title_text = bui.textwidget(
 60            parent=self.root_widget,
 61            position=(self._width * 0.5, self._height - 20),
 62            size=(0, 0),
 63            h_align='center',
 64            v_align='center',
 65            scale=0.6,
 66            text='INBOX (UNDER CONSTRUCTION)',
 67            maxwidth=200,
 68            color=bui.app.ui_v1.title_color,
 69        )
 70
 71        self._scrollwidget = bui.scrollwidget(
 72            parent=self.root_widget,
 73            size=(self._width - 60, self._height - 70),
 74            position=(30, 30),
 75            capture_arrows=True,
 76            simple_culling_v=10,
 77        )
 78        bui.widget(edit=self._scrollwidget, autoselect=True)
 79
 80        bui.containerwidget(
 81            edit=self.root_widget, cancel_button=self._cancel_button
 82        )
 83
 84        entries: list[str] = []
 85        incr = 20
 86        sub_width = self._width - 90
 87        sub_height = 40 + len(entries) * incr
 88
 89        self._subcontainer = bui.containerwidget(
 90            parent=self._scrollwidget,
 91            size=(sub_width, sub_height),
 92            background=False,
 93        )
 94
 95        for i, entry in enumerate(entries):
 96            bui.textwidget(
 97                parent=self._subcontainer,
 98                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
 99                maxwidth=20,
100                scale=0.5,
101                flatness=1.0,
102                shadow=0.0,
103                text=entry,
104                size=(0, 0),
105                h_align='right',
106                v_align='center',
107            )
108
109    def _on_cancel_press(self) -> None:
110        self._transition_out()
111
112    def _transition_out(self) -> None:
113        if not self._transitioning_out:
114            self._transitioning_out = True
115            bui.containerwidget(edit=self.root_widget, transition='out_scale')
116
117    @override
118    def on_popup_cancel(self) -> None:
119        bui.getsound('swish').play()
120        self._transition_out()

Popup window to show account messages.

InboxWindow(position: tuple[float, float], scale: float | None = None)
 17    def __init__(
 18        self, position: tuple[float, float], scale: float | None = None
 19    ):
 20        assert bui.app.classic is not None
 21        uiscale = bui.app.ui_v1.uiscale
 22        if scale is None:
 23            scale = (
 24                2.3
 25                if uiscale is bui.UIScale.SMALL
 26                else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 27            )
 28        self._transitioning_out = False
 29        self._width = 450
 30        self._height = (
 31            300
 32            if uiscale is bui.UIScale.SMALL
 33            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 34        )
 35        bg_color = (0.5, 0.4, 0.6)
 36
 37        # creates our _root_widget
 38        super().__init__(
 39            position=position,
 40            size=(self._width, self._height),
 41            scale=scale,
 42            bg_color=bg_color,
 43            edge_buffer_scale=4.0,  # Try to keep button unobscured.
 44        )
 45
 46        self._cancel_button = bui.buttonwidget(
 47            parent=self.root_widget,
 48            position=(50, self._height - 30),
 49            size=(50, 50),
 50            scale=0.5,
 51            label='',
 52            color=bg_color,
 53            on_activate_call=self._on_cancel_press,
 54            autoselect=True,
 55            icon=bui.gettexture('crossOut'),
 56            iconscale=1.2,
 57        )
 58
 59        self._title_text = bui.textwidget(
 60            parent=self.root_widget,
 61            position=(self._width * 0.5, self._height - 20),
 62            size=(0, 0),
 63            h_align='center',
 64            v_align='center',
 65            scale=0.6,
 66            text='INBOX (UNDER CONSTRUCTION)',
 67            maxwidth=200,
 68            color=bui.app.ui_v1.title_color,
 69        )
 70
 71        self._scrollwidget = bui.scrollwidget(
 72            parent=self.root_widget,
 73            size=(self._width - 60, self._height - 70),
 74            position=(30, 30),
 75            capture_arrows=True,
 76            simple_culling_v=10,
 77        )
 78        bui.widget(edit=self._scrollwidget, autoselect=True)
 79
 80        bui.containerwidget(
 81            edit=self.root_widget, cancel_button=self._cancel_button
 82        )
 83
 84        entries: list[str] = []
 85        incr = 20
 86        sub_width = self._width - 90
 87        sub_height = 40 + len(entries) * incr
 88
 89        self._subcontainer = bui.containerwidget(
 90            parent=self._scrollwidget,
 91            size=(sub_width, sub_height),
 92            background=False,
 93        )
 94
 95        for i, entry in enumerate(entries):
 96            bui.textwidget(
 97                parent=self._subcontainer,
 98                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
 99                maxwidth=20,
100                scale=0.5,
101                flatness=1.0,
102                shadow=0.0,
103                text=entry,
104                size=(0, 0),
105                h_align='right',
106                v_align='center',
107            )
@override
def on_popup_cancel(self) -> None:
117    @override
118    def on_popup_cancel(self) -> None:
119        bui.getsound('swish').play()
120        self._transition_out()

Called when the popup is canceled.

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