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
  9# from bauiv1lib.popup import PopupWindow
 10import bauiv1 as bui
 11
 12
 13class InboxWindow(bui.MainWindow):
 14    """Popup window to show account messages."""
 15
 16    def __init__(
 17        self,
 18        transition: str | None = 'in_right',
 19        origin_widget: bui.Widget | None = None,
 20    ):
 21        assert bui.app.classic is not None
 22        uiscale = bui.app.ui_v1.uiscale
 23        self._width = 600 if uiscale is bui.UIScale.SMALL else 450
 24        self._height = (
 25            380
 26            if uiscale is bui.UIScale.SMALL
 27            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 28        )
 29        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 30
 31        super().__init__(
 32            root_widget=bui.containerwidget(
 33                size=(self._width, self._height),
 34                toolbar_visibility=(
 35                    'menu_minimal'
 36                    if uiscale is bui.UIScale.SMALL
 37                    else 'menu_full'
 38                ),
 39                scale=(
 40                    2.3
 41                    if uiscale is bui.UIScale.SMALL
 42                    else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 43                ),
 44                stack_offset=(
 45                    (0, 0)
 46                    if uiscale is bui.UIScale.SMALL
 47                    else (0, 0) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 48                ),
 49            ),
 50            transition=transition,
 51            origin_widget=origin_widget,
 52        )
 53
 54        if uiscale is bui.UIScale.SMALL:
 55            bui.containerwidget(
 56                edit=self._root_widget, on_cancel_call=self.main_window_back
 57            )
 58            self._back_button = None
 59        else:
 60            self._back_button = bui.buttonwidget(
 61                parent=self._root_widget,
 62                autoselect=True,
 63                position=(50, self._height - 38 + yoffs),
 64                size=(60, 60),
 65                scale=0.6,
 66                label=bui.charstr(bui.SpecialChar.BACK),
 67                button_type='backSmall',
 68                on_activate_call=self.main_window_back,
 69            )
 70            bui.containerwidget(
 71                edit=self._root_widget, cancel_button=self._back_button
 72            )
 73
 74        self._title_text = bui.textwidget(
 75            parent=self._root_widget,
 76            position=(
 77                self._width * 0.5,
 78                self._height
 79                - (27 if uiscale is bui.UIScale.SMALL else 20)
 80                + yoffs,
 81            ),
 82            size=(0, 0),
 83            h_align='center',
 84            v_align='center',
 85            scale=0.6,
 86            text='INBOX (UNDER CONSTRUCTION)',
 87            maxwidth=200,
 88            color=bui.app.ui_v1.title_color,
 89        )
 90
 91        self._scrollwidget = bui.scrollwidget(
 92            parent=self._root_widget,
 93            size=(
 94                self._width - 60,
 95                self._height - (150 if uiscale is bui.UIScale.SMALL else 70),
 96            ),
 97            position=(
 98                30,
 99                (110 if uiscale is bui.UIScale.SMALL else 30) + yoffs,
100            ),
101            capture_arrows=True,
102            simple_culling_v=10,
103        )
104        bui.widget(edit=self._scrollwidget, autoselect=True)
105        if uiscale is bui.UIScale.SMALL:
106            bui.widget(
107                edit=self._scrollwidget,
108                left_widget=bui.get_special_widget('back_button'),
109            )
110
111        bui.containerwidget(
112            edit=self._root_widget, cancel_button=self._back_button
113        )
114
115        entries: list[str] = []
116        incr = 20
117        sub_width = self._width - 90
118        sub_height = 40 + len(entries) * incr
119
120        self._subcontainer = bui.containerwidget(
121            parent=self._scrollwidget,
122            size=(sub_width, sub_height),
123            background=False,
124        )
125
126        for i, entry in enumerate(entries):
127            bui.textwidget(
128                parent=self._subcontainer,
129                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
130                maxwidth=20,
131                scale=0.5,
132                flatness=1.0,
133                shadow=0.0,
134                text=entry,
135                size=(0, 0),
136                h_align='right',
137                v_align='center',
138            )
139
140    @override
141    def get_main_window_state(self) -> bui.MainWindowState:
142        # Support recreating our window for back/refresh purposes.
143        cls = type(self)
144        return bui.BasicMainWindowState(
145            create_call=lambda transition, origin_widget: cls(
146                transition=transition, origin_widget=origin_widget
147            )
148        )
149
150    # def _on_cancel_press(self) -> None:
151    #     self._transition_out()
152
153    # def _transition_out(self) -> None:
154    #     if not self._transitioning_out:
155    #         self._transitioning_out = True
156    #         bui.containerwidget(
157    # edit=self._root_widget, transition='out_scale')
158
159    # @override
160    # def on_popup_cancel(self) -> None:
161    #     bui.getsound('swish').play()
162    #     self._transition_out()
class InboxWindow(bauiv1._uitypes.MainWindow):
 14class InboxWindow(bui.MainWindow):
 15    """Popup window to show account messages."""
 16
 17    def __init__(
 18        self,
 19        transition: str | None = 'in_right',
 20        origin_widget: bui.Widget | None = None,
 21    ):
 22        assert bui.app.classic is not None
 23        uiscale = bui.app.ui_v1.uiscale
 24        self._width = 600 if uiscale is bui.UIScale.SMALL else 450
 25        self._height = (
 26            380
 27            if uiscale is bui.UIScale.SMALL
 28            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 29        )
 30        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 31
 32        super().__init__(
 33            root_widget=bui.containerwidget(
 34                size=(self._width, self._height),
 35                toolbar_visibility=(
 36                    'menu_minimal'
 37                    if uiscale is bui.UIScale.SMALL
 38                    else 'menu_full'
 39                ),
 40                scale=(
 41                    2.3
 42                    if uiscale is bui.UIScale.SMALL
 43                    else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 44                ),
 45                stack_offset=(
 46                    (0, 0)
 47                    if uiscale is bui.UIScale.SMALL
 48                    else (0, 0) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 49                ),
 50            ),
 51            transition=transition,
 52            origin_widget=origin_widget,
 53        )
 54
 55        if uiscale is bui.UIScale.SMALL:
 56            bui.containerwidget(
 57                edit=self._root_widget, on_cancel_call=self.main_window_back
 58            )
 59            self._back_button = None
 60        else:
 61            self._back_button = bui.buttonwidget(
 62                parent=self._root_widget,
 63                autoselect=True,
 64                position=(50, self._height - 38 + yoffs),
 65                size=(60, 60),
 66                scale=0.6,
 67                label=bui.charstr(bui.SpecialChar.BACK),
 68                button_type='backSmall',
 69                on_activate_call=self.main_window_back,
 70            )
 71            bui.containerwidget(
 72                edit=self._root_widget, cancel_button=self._back_button
 73            )
 74
 75        self._title_text = bui.textwidget(
 76            parent=self._root_widget,
 77            position=(
 78                self._width * 0.5,
 79                self._height
 80                - (27 if uiscale is bui.UIScale.SMALL else 20)
 81                + yoffs,
 82            ),
 83            size=(0, 0),
 84            h_align='center',
 85            v_align='center',
 86            scale=0.6,
 87            text='INBOX (UNDER CONSTRUCTION)',
 88            maxwidth=200,
 89            color=bui.app.ui_v1.title_color,
 90        )
 91
 92        self._scrollwidget = bui.scrollwidget(
 93            parent=self._root_widget,
 94            size=(
 95                self._width - 60,
 96                self._height - (150 if uiscale is bui.UIScale.SMALL else 70),
 97            ),
 98            position=(
 99                30,
100                (110 if uiscale is bui.UIScale.SMALL else 30) + yoffs,
101            ),
102            capture_arrows=True,
103            simple_culling_v=10,
104        )
105        bui.widget(edit=self._scrollwidget, autoselect=True)
106        if uiscale is bui.UIScale.SMALL:
107            bui.widget(
108                edit=self._scrollwidget,
109                left_widget=bui.get_special_widget('back_button'),
110            )
111
112        bui.containerwidget(
113            edit=self._root_widget, cancel_button=self._back_button
114        )
115
116        entries: list[str] = []
117        incr = 20
118        sub_width = self._width - 90
119        sub_height = 40 + len(entries) * incr
120
121        self._subcontainer = bui.containerwidget(
122            parent=self._scrollwidget,
123            size=(sub_width, sub_height),
124            background=False,
125        )
126
127        for i, entry in enumerate(entries):
128            bui.textwidget(
129                parent=self._subcontainer,
130                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
131                maxwidth=20,
132                scale=0.5,
133                flatness=1.0,
134                shadow=0.0,
135                text=entry,
136                size=(0, 0),
137                h_align='right',
138                v_align='center',
139            )
140
141    @override
142    def get_main_window_state(self) -> bui.MainWindowState:
143        # Support recreating our window for back/refresh purposes.
144        cls = type(self)
145        return bui.BasicMainWindowState(
146            create_call=lambda transition, origin_widget: cls(
147                transition=transition, origin_widget=origin_widget
148            )
149        )
150
151    # def _on_cancel_press(self) -> None:
152    #     self._transition_out()
153
154    # def _transition_out(self) -> None:
155    #     if not self._transitioning_out:
156    #         self._transitioning_out = True
157    #         bui.containerwidget(
158    # edit=self._root_widget, transition='out_scale')
159
160    # @override
161    # def on_popup_cancel(self) -> None:
162    #     bui.getsound('swish').play()
163    #     self._transition_out()

Popup window to show account messages.

InboxWindow( transition: str | None = 'in_right', origin_widget: _bauiv1.Widget | None = None)
 17    def __init__(
 18        self,
 19        transition: str | None = 'in_right',
 20        origin_widget: bui.Widget | None = None,
 21    ):
 22        assert bui.app.classic is not None
 23        uiscale = bui.app.ui_v1.uiscale
 24        self._width = 600 if uiscale is bui.UIScale.SMALL else 450
 25        self._height = (
 26            380
 27            if uiscale is bui.UIScale.SMALL
 28            else 370 if uiscale is bui.UIScale.MEDIUM else 450
 29        )
 30        yoffs = -45 if uiscale is bui.UIScale.SMALL else 0
 31
 32        super().__init__(
 33            root_widget=bui.containerwidget(
 34                size=(self._width, self._height),
 35                toolbar_visibility=(
 36                    'menu_minimal'
 37                    if uiscale is bui.UIScale.SMALL
 38                    else 'menu_full'
 39                ),
 40                scale=(
 41                    2.3
 42                    if uiscale is bui.UIScale.SMALL
 43                    else 1.65 if uiscale is bui.UIScale.MEDIUM else 1.23
 44                ),
 45                stack_offset=(
 46                    (0, 0)
 47                    if uiscale is bui.UIScale.SMALL
 48                    else (0, 0) if uiscale is bui.UIScale.MEDIUM else (0, 0)
 49                ),
 50            ),
 51            transition=transition,
 52            origin_widget=origin_widget,
 53        )
 54
 55        if uiscale is bui.UIScale.SMALL:
 56            bui.containerwidget(
 57                edit=self._root_widget, on_cancel_call=self.main_window_back
 58            )
 59            self._back_button = None
 60        else:
 61            self._back_button = bui.buttonwidget(
 62                parent=self._root_widget,
 63                autoselect=True,
 64                position=(50, self._height - 38 + yoffs),
 65                size=(60, 60),
 66                scale=0.6,
 67                label=bui.charstr(bui.SpecialChar.BACK),
 68                button_type='backSmall',
 69                on_activate_call=self.main_window_back,
 70            )
 71            bui.containerwidget(
 72                edit=self._root_widget, cancel_button=self._back_button
 73            )
 74
 75        self._title_text = bui.textwidget(
 76            parent=self._root_widget,
 77            position=(
 78                self._width * 0.5,
 79                self._height
 80                - (27 if uiscale is bui.UIScale.SMALL else 20)
 81                + yoffs,
 82            ),
 83            size=(0, 0),
 84            h_align='center',
 85            v_align='center',
 86            scale=0.6,
 87            text='INBOX (UNDER CONSTRUCTION)',
 88            maxwidth=200,
 89            color=bui.app.ui_v1.title_color,
 90        )
 91
 92        self._scrollwidget = bui.scrollwidget(
 93            parent=self._root_widget,
 94            size=(
 95                self._width - 60,
 96                self._height - (150 if uiscale is bui.UIScale.SMALL else 70),
 97            ),
 98            position=(
 99                30,
100                (110 if uiscale is bui.UIScale.SMALL else 30) + yoffs,
101            ),
102            capture_arrows=True,
103            simple_culling_v=10,
104        )
105        bui.widget(edit=self._scrollwidget, autoselect=True)
106        if uiscale is bui.UIScale.SMALL:
107            bui.widget(
108                edit=self._scrollwidget,
109                left_widget=bui.get_special_widget('back_button'),
110            )
111
112        bui.containerwidget(
113            edit=self._root_widget, cancel_button=self._back_button
114        )
115
116        entries: list[str] = []
117        incr = 20
118        sub_width = self._width - 90
119        sub_height = 40 + len(entries) * incr
120
121        self._subcontainer = bui.containerwidget(
122            parent=self._scrollwidget,
123            size=(sub_width, sub_height),
124            background=False,
125        )
126
127        for i, entry in enumerate(entries):
128            bui.textwidget(
129                parent=self._subcontainer,
130                position=(sub_width * 0.08 - 5, sub_height - 20 - incr * i),
131                maxwidth=20,
132                scale=0.5,
133                flatness=1.0,
134                shadow=0.0,
135                text=entry,
136                size=(0, 0),
137                h_align='right',
138                v_align='center',
139            )

Create a MainWindow given a root widget and transition info.

Automatically handles in and out transitions on the provided widget, so there is no need to set transitions when creating it.

@override
def get_main_window_state(self) -> bauiv1.MainWindowState:
141    @override
142    def get_main_window_state(self) -> bui.MainWindowState:
143        # Support recreating our window for back/refresh purposes.
144        cls = type(self)
145        return bui.BasicMainWindowState(
146            create_call=lambda transition, origin_widget: cls(
147                transition=transition, origin_widget=origin_widget
148            )
149        )

Return a WindowState to recreate this window, if supported.