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