bastd.ui.settings.pluginsettings

Plugin Settings UI.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Plugin Settings UI."""
  4
  5from __future__ import annotations
  6
  7from typing import TYPE_CHECKING
  8
  9import ba
 10from bastd.ui.confirm import ConfirmWindow
 11
 12if TYPE_CHECKING:
 13    pass
 14
 15
 16class PluginSettingsWindow(ba.Window):
 17    """Plugin Settings Window"""
 18
 19    def __init__(self, transition: str = 'in_right'):
 20
 21        scale_origin: tuple[float, float] | None
 22        self._transition_out = 'out_right'
 23        scale_origin = None
 24
 25        uiscale = ba.app.ui.uiscale
 26        width = 470.0 if uiscale is ba.UIScale.SMALL else 470.0
 27        height = (
 28            365.0
 29            if uiscale is ba.UIScale.SMALL
 30            else 300.0
 31            if uiscale is ba.UIScale.MEDIUM
 32            else 370.0
 33        )
 34        top_extra = 10 if uiscale is ba.UIScale.SMALL else 0
 35
 36        super().__init__(
 37            root_widget=ba.containerwidget(
 38                size=(width, height + top_extra),
 39                transition=transition,
 40                toolbar_visibility='menu_minimal',
 41                scale_origin_stack_offset=scale_origin,
 42                scale=(
 43                    2.06
 44                    if uiscale is ba.UIScale.SMALL
 45                    else 1.4
 46                    if uiscale is ba.UIScale.MEDIUM
 47                    else 1.0
 48                ),
 49                stack_offset=(0, -25)
 50                if uiscale is ba.UIScale.SMALL
 51                else (0, 0),
 52            )
 53        )
 54
 55        self._back_button = ba.buttonwidget(
 56            parent=self._root_widget,
 57            position=(53, height - 60),
 58            size=(60, 60),
 59            scale=0.8,
 60            autoselect=True,
 61            label=ba.charstr(ba.SpecialChar.BACK),
 62            button_type='backSmall',
 63            on_activate_call=self._do_back,
 64        )
 65        ba.containerwidget(
 66            edit=self._root_widget, cancel_button=self._back_button
 67        )
 68
 69        self._title_text = ba.textwidget(
 70            parent=self._root_widget,
 71            position=(0, height - 52),
 72            size=(width, 25),
 73            text=ba.Lstr(resource='pluginSettingsText'),
 74            color=ba.app.ui.title_color,
 75            h_align='center',
 76            v_align='top',
 77        )
 78
 79        self._y_position = 170 if uiscale is ba.UIScale.MEDIUM else 205
 80        self._enable_plugins_button = ba.buttonwidget(
 81            parent=self._root_widget,
 82            position=(65, self._y_position),
 83            size=(350, 60),
 84            autoselect=True,
 85            label=ba.Lstr(resource='pluginsEnableAllText'),
 86            text_scale=1.0,
 87            on_activate_call=lambda: ConfirmWindow(
 88                action=self._enable_all_plugins,
 89            ),
 90        )
 91
 92        self._y_position -= 70
 93        self._disable_plugins_button = ba.buttonwidget(
 94            parent=self._root_widget,
 95            position=(65, self._y_position),
 96            size=(350, 60),
 97            autoselect=True,
 98            label=ba.Lstr(resource='pluginsDisableAllText'),
 99            text_scale=1.0,
100            on_activate_call=lambda: ConfirmWindow(
101                action=self._disable_all_plugins,
102            ),
103        )
104
105        self._y_position -= 70
106        self._enable_new_plugins_check_box = ba.checkboxwidget(
107            parent=self._root_widget,
108            position=(65, self._y_position),
109            size=(350, 60),
110            value=ba.app.config.get(
111                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY,
112                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT,
113            ),
114            text=ba.Lstr(resource='pluginsAutoEnableNewText'),
115            scale=1.0,
116            maxwidth=308,
117            on_value_change_call=self._update_value,
118        )
119
120        ba.widget(
121            edit=self._back_button, down_widget=self._enable_plugins_button
122        )
123
124        ba.widget(
125            edit=self._disable_plugins_button,
126            left_widget=self._disable_plugins_button,
127        )
128
129        ba.widget(
130            edit=self._enable_new_plugins_check_box,
131            left_widget=self._enable_new_plugins_check_box,
132            right_widget=self._enable_new_plugins_check_box,
133            down_widget=self._enable_new_plugins_check_box,
134        )
135
136    def _enable_all_plugins(self) -> None:
137        cfg = ba.app.config
138        plugs: dict[str, dict] = cfg.setdefault('Plugins', {})
139        for plug in plugs.values():
140            plug['enabled'] = True
141        cfg.apply_and_commit()
142
143        ba.screenmessage(
144            ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
145            color=(1.0, 0.5, 0.0),
146        )
147
148    def _disable_all_plugins(self) -> None:
149        cfg = ba.app.config
150        plugs: dict[str, dict] = cfg.setdefault('Plugins', {})
151        for plug in plugs.values():
152            plug['enabled'] = False
153        cfg.apply_and_commit()
154
155        ba.screenmessage(
156            ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
157            color=(1.0, 0.5, 0.0),
158        )
159
160    def _update_value(self, val: bool) -> None:
161        cfg = ba.app.config
162        cfg[ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY] = val
163        cfg.apply_and_commit()
164
165    def _do_back(self) -> None:
166        # pylint: disable=cyclic-import
167        from bastd.ui.settings.plugins import PluginWindow
168
169        ba.containerwidget(
170            edit=self._root_widget, transition=self._transition_out
171        )
172        ba.app.ui.set_main_menu_window(
173            PluginWindow(transition='in_left').get_root_widget()
174        )
class PluginSettingsWindow(ba.ui.Window):
 17class PluginSettingsWindow(ba.Window):
 18    """Plugin Settings Window"""
 19
 20    def __init__(self, transition: str = 'in_right'):
 21
 22        scale_origin: tuple[float, float] | None
 23        self._transition_out = 'out_right'
 24        scale_origin = None
 25
 26        uiscale = ba.app.ui.uiscale
 27        width = 470.0 if uiscale is ba.UIScale.SMALL else 470.0
 28        height = (
 29            365.0
 30            if uiscale is ba.UIScale.SMALL
 31            else 300.0
 32            if uiscale is ba.UIScale.MEDIUM
 33            else 370.0
 34        )
 35        top_extra = 10 if uiscale is ba.UIScale.SMALL else 0
 36
 37        super().__init__(
 38            root_widget=ba.containerwidget(
 39                size=(width, height + top_extra),
 40                transition=transition,
 41                toolbar_visibility='menu_minimal',
 42                scale_origin_stack_offset=scale_origin,
 43                scale=(
 44                    2.06
 45                    if uiscale is ba.UIScale.SMALL
 46                    else 1.4
 47                    if uiscale is ba.UIScale.MEDIUM
 48                    else 1.0
 49                ),
 50                stack_offset=(0, -25)
 51                if uiscale is ba.UIScale.SMALL
 52                else (0, 0),
 53            )
 54        )
 55
 56        self._back_button = ba.buttonwidget(
 57            parent=self._root_widget,
 58            position=(53, height - 60),
 59            size=(60, 60),
 60            scale=0.8,
 61            autoselect=True,
 62            label=ba.charstr(ba.SpecialChar.BACK),
 63            button_type='backSmall',
 64            on_activate_call=self._do_back,
 65        )
 66        ba.containerwidget(
 67            edit=self._root_widget, cancel_button=self._back_button
 68        )
 69
 70        self._title_text = ba.textwidget(
 71            parent=self._root_widget,
 72            position=(0, height - 52),
 73            size=(width, 25),
 74            text=ba.Lstr(resource='pluginSettingsText'),
 75            color=ba.app.ui.title_color,
 76            h_align='center',
 77            v_align='top',
 78        )
 79
 80        self._y_position = 170 if uiscale is ba.UIScale.MEDIUM else 205
 81        self._enable_plugins_button = ba.buttonwidget(
 82            parent=self._root_widget,
 83            position=(65, self._y_position),
 84            size=(350, 60),
 85            autoselect=True,
 86            label=ba.Lstr(resource='pluginsEnableAllText'),
 87            text_scale=1.0,
 88            on_activate_call=lambda: ConfirmWindow(
 89                action=self._enable_all_plugins,
 90            ),
 91        )
 92
 93        self._y_position -= 70
 94        self._disable_plugins_button = ba.buttonwidget(
 95            parent=self._root_widget,
 96            position=(65, self._y_position),
 97            size=(350, 60),
 98            autoselect=True,
 99            label=ba.Lstr(resource='pluginsDisableAllText'),
100            text_scale=1.0,
101            on_activate_call=lambda: ConfirmWindow(
102                action=self._disable_all_plugins,
103            ),
104        )
105
106        self._y_position -= 70
107        self._enable_new_plugins_check_box = ba.checkboxwidget(
108            parent=self._root_widget,
109            position=(65, self._y_position),
110            size=(350, 60),
111            value=ba.app.config.get(
112                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY,
113                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT,
114            ),
115            text=ba.Lstr(resource='pluginsAutoEnableNewText'),
116            scale=1.0,
117            maxwidth=308,
118            on_value_change_call=self._update_value,
119        )
120
121        ba.widget(
122            edit=self._back_button, down_widget=self._enable_plugins_button
123        )
124
125        ba.widget(
126            edit=self._disable_plugins_button,
127            left_widget=self._disable_plugins_button,
128        )
129
130        ba.widget(
131            edit=self._enable_new_plugins_check_box,
132            left_widget=self._enable_new_plugins_check_box,
133            right_widget=self._enable_new_plugins_check_box,
134            down_widget=self._enable_new_plugins_check_box,
135        )
136
137    def _enable_all_plugins(self) -> None:
138        cfg = ba.app.config
139        plugs: dict[str, dict] = cfg.setdefault('Plugins', {})
140        for plug in plugs.values():
141            plug['enabled'] = True
142        cfg.apply_and_commit()
143
144        ba.screenmessage(
145            ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
146            color=(1.0, 0.5, 0.0),
147        )
148
149    def _disable_all_plugins(self) -> None:
150        cfg = ba.app.config
151        plugs: dict[str, dict] = cfg.setdefault('Plugins', {})
152        for plug in plugs.values():
153            plug['enabled'] = False
154        cfg.apply_and_commit()
155
156        ba.screenmessage(
157            ba.Lstr(resource='settingsWindowAdvanced.mustRestartText'),
158            color=(1.0, 0.5, 0.0),
159        )
160
161    def _update_value(self, val: bool) -> None:
162        cfg = ba.app.config
163        cfg[ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY] = val
164        cfg.apply_and_commit()
165
166    def _do_back(self) -> None:
167        # pylint: disable=cyclic-import
168        from bastd.ui.settings.plugins import PluginWindow
169
170        ba.containerwidget(
171            edit=self._root_widget, transition=self._transition_out
172        )
173        ba.app.ui.set_main_menu_window(
174            PluginWindow(transition='in_left').get_root_widget()
175        )

Plugin Settings Window

PluginSettingsWindow(transition: str = 'in_right')
 20    def __init__(self, transition: str = 'in_right'):
 21
 22        scale_origin: tuple[float, float] | None
 23        self._transition_out = 'out_right'
 24        scale_origin = None
 25
 26        uiscale = ba.app.ui.uiscale
 27        width = 470.0 if uiscale is ba.UIScale.SMALL else 470.0
 28        height = (
 29            365.0
 30            if uiscale is ba.UIScale.SMALL
 31            else 300.0
 32            if uiscale is ba.UIScale.MEDIUM
 33            else 370.0
 34        )
 35        top_extra = 10 if uiscale is ba.UIScale.SMALL else 0
 36
 37        super().__init__(
 38            root_widget=ba.containerwidget(
 39                size=(width, height + top_extra),
 40                transition=transition,
 41                toolbar_visibility='menu_minimal',
 42                scale_origin_stack_offset=scale_origin,
 43                scale=(
 44                    2.06
 45                    if uiscale is ba.UIScale.SMALL
 46                    else 1.4
 47                    if uiscale is ba.UIScale.MEDIUM
 48                    else 1.0
 49                ),
 50                stack_offset=(0, -25)
 51                if uiscale is ba.UIScale.SMALL
 52                else (0, 0),
 53            )
 54        )
 55
 56        self._back_button = ba.buttonwidget(
 57            parent=self._root_widget,
 58            position=(53, height - 60),
 59            size=(60, 60),
 60            scale=0.8,
 61            autoselect=True,
 62            label=ba.charstr(ba.SpecialChar.BACK),
 63            button_type='backSmall',
 64            on_activate_call=self._do_back,
 65        )
 66        ba.containerwidget(
 67            edit=self._root_widget, cancel_button=self._back_button
 68        )
 69
 70        self._title_text = ba.textwidget(
 71            parent=self._root_widget,
 72            position=(0, height - 52),
 73            size=(width, 25),
 74            text=ba.Lstr(resource='pluginSettingsText'),
 75            color=ba.app.ui.title_color,
 76            h_align='center',
 77            v_align='top',
 78        )
 79
 80        self._y_position = 170 if uiscale is ba.UIScale.MEDIUM else 205
 81        self._enable_plugins_button = ba.buttonwidget(
 82            parent=self._root_widget,
 83            position=(65, self._y_position),
 84            size=(350, 60),
 85            autoselect=True,
 86            label=ba.Lstr(resource='pluginsEnableAllText'),
 87            text_scale=1.0,
 88            on_activate_call=lambda: ConfirmWindow(
 89                action=self._enable_all_plugins,
 90            ),
 91        )
 92
 93        self._y_position -= 70
 94        self._disable_plugins_button = ba.buttonwidget(
 95            parent=self._root_widget,
 96            position=(65, self._y_position),
 97            size=(350, 60),
 98            autoselect=True,
 99            label=ba.Lstr(resource='pluginsDisableAllText'),
100            text_scale=1.0,
101            on_activate_call=lambda: ConfirmWindow(
102                action=self._disable_all_plugins,
103            ),
104        )
105
106        self._y_position -= 70
107        self._enable_new_plugins_check_box = ba.checkboxwidget(
108            parent=self._root_widget,
109            position=(65, self._y_position),
110            size=(350, 60),
111            value=ba.app.config.get(
112                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY,
113                ba.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT,
114            ),
115            text=ba.Lstr(resource='pluginsAutoEnableNewText'),
116            scale=1.0,
117            maxwidth=308,
118            on_value_change_call=self._update_value,
119        )
120
121        ba.widget(
122            edit=self._back_button, down_widget=self._enable_plugins_button
123        )
124
125        ba.widget(
126            edit=self._disable_plugins_button,
127            left_widget=self._disable_plugins_button,
128        )
129
130        ba.widget(
131            edit=self._enable_new_plugins_check_box,
132            left_widget=self._enable_new_plugins_check_box,
133            right_widget=self._enable_new_plugins_check_box,
134            down_widget=self._enable_new_plugins_check_box,
135        )
Inherited Members
ba.ui.Window
get_root_widget