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

Plugin Settings Window

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