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