bauiv1lib.resourcetypeinfo

Provides a window which shows info about resource types.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Provides a window which shows info about resource types."""
 4
 5from __future__ import annotations
 6
 7from typing_extensions import override
 8
 9from bauiv1lib.popup import PopupWindow
10import bauiv1 as bui
11
12
13class ResourceTypeInfoWindow(PopupWindow):
14    """Popup window providing info about resource types."""
15
16    def __init__(self, origin_widget: bui.Widget):
17        assert bui.app.classic is not None
18        uiscale = bui.app.ui_v1.uiscale
19        scale = (
20            2.3
21            if uiscale is bui.UIScale.SMALL
22            else 1.65
23            if uiscale is bui.UIScale.MEDIUM
24            else 1.23
25        )
26        self._transitioning_out = False
27        self._width = 570
28        self._height = 350
29        bg_color = (0.5, 0.4, 0.6)
30        super().__init__(
31            size=(self._width, self._height),
32            toolbar_visibility='inherit',
33            scale=scale,
34            bg_color=bg_color,
35            position=origin_widget.get_screen_space_center(),
36        )
37        self._cancel_button = bui.buttonwidget(
38            parent=self.root_widget,
39            position=(50, self._height - 30),
40            size=(50, 50),
41            scale=0.5,
42            label='',
43            color=bg_color,
44            on_activate_call=self._on_cancel_press,
45            autoselect=True,
46            icon=bui.gettexture('crossOut'),
47            iconscale=1.2,
48        )
49
50    def _on_cancel_press(self) -> None:
51        self._transition_out()
52
53    def _transition_out(self) -> None:
54        if not self._transitioning_out:
55            self._transitioning_out = True
56            bui.containerwidget(edit=self.root_widget, transition='out_scale')
57
58    @override
59    def on_popup_cancel(self) -> None:
60        bui.getsound('swish').play()
61        self._transition_out()
class ResourceTypeInfoWindow(bauiv1lib.popup.PopupWindow):
14class ResourceTypeInfoWindow(PopupWindow):
15    """Popup window providing info about resource types."""
16
17    def __init__(self, origin_widget: bui.Widget):
18        assert bui.app.classic is not None
19        uiscale = bui.app.ui_v1.uiscale
20        scale = (
21            2.3
22            if uiscale is bui.UIScale.SMALL
23            else 1.65
24            if uiscale is bui.UIScale.MEDIUM
25            else 1.23
26        )
27        self._transitioning_out = False
28        self._width = 570
29        self._height = 350
30        bg_color = (0.5, 0.4, 0.6)
31        super().__init__(
32            size=(self._width, self._height),
33            toolbar_visibility='inherit',
34            scale=scale,
35            bg_color=bg_color,
36            position=origin_widget.get_screen_space_center(),
37        )
38        self._cancel_button = bui.buttonwidget(
39            parent=self.root_widget,
40            position=(50, self._height - 30),
41            size=(50, 50),
42            scale=0.5,
43            label='',
44            color=bg_color,
45            on_activate_call=self._on_cancel_press,
46            autoselect=True,
47            icon=bui.gettexture('crossOut'),
48            iconscale=1.2,
49        )
50
51    def _on_cancel_press(self) -> None:
52        self._transition_out()
53
54    def _transition_out(self) -> None:
55        if not self._transitioning_out:
56            self._transitioning_out = True
57            bui.containerwidget(edit=self.root_widget, transition='out_scale')
58
59    @override
60    def on_popup_cancel(self) -> None:
61        bui.getsound('swish').play()
62        self._transition_out()

Popup window providing info about resource types.

ResourceTypeInfoWindow(origin_widget: _bauiv1.Widget)
17    def __init__(self, origin_widget: bui.Widget):
18        assert bui.app.classic is not None
19        uiscale = bui.app.ui_v1.uiscale
20        scale = (
21            2.3
22            if uiscale is bui.UIScale.SMALL
23            else 1.65
24            if uiscale is bui.UIScale.MEDIUM
25            else 1.23
26        )
27        self._transitioning_out = False
28        self._width = 570
29        self._height = 350
30        bg_color = (0.5, 0.4, 0.6)
31        super().__init__(
32            size=(self._width, self._height),
33            toolbar_visibility='inherit',
34            scale=scale,
35            bg_color=bg_color,
36            position=origin_widget.get_screen_space_center(),
37        )
38        self._cancel_button = bui.buttonwidget(
39            parent=self.root_widget,
40            position=(50, self._height - 30),
41            size=(50, 50),
42            scale=0.5,
43            label='',
44            color=bg_color,
45            on_activate_call=self._on_cancel_press,
46            autoselect=True,
47            icon=bui.gettexture('crossOut'),
48            iconscale=1.2,
49        )
@override
def on_popup_cancel(self) -> None:
59    @override
60    def on_popup_cancel(self) -> None:
61        bui.getsound('swish').play()
62        self._transition_out()

Called when the popup is canceled.

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