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 self._width = 1200.0 if uiscale is bui.UIScale.SMALL else 470.0 25 self._height = 900.0 if uiscale is bui.UIScale.SMALL else 360.0 26 27 # Do some fancy math to fill all available screen area up to the 28 # size of our backing container. This lets us fit to the exact 29 # screen shape at small ui scale. 30 screensize = bui.get_virtual_screen_size() 31 scale = ( 32 2.06 33 if uiscale is bui.UIScale.SMALL 34 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 35 ) 36 # Calc screen size in our local container space and clamp to a 37 # bit smaller than our container size. 38 # target_width = min(self._width - 60, screensize[0] / scale) 39 target_height = min(self._height - 100, screensize[1] / scale) 40 41 # To get top/left coords, go to the center of our window and 42 # offset by half the width/height of our target area. 43 self._yoffs = 0.5 * self._height + 0.5 * target_height + 30.0 44 45 super().__init__( 46 root_widget=bui.containerwidget( 47 size=(self._width, self._height), 48 toolbar_visibility=( 49 'menu_minimal' 50 if uiscale is bui.UIScale.SMALL 51 else 'menu_full' 52 ), 53 scale=scale, 54 ), 55 transition=transition, 56 origin_widget=origin_widget, 57 # We're affected by screen size only at small ui-scale. 58 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 59 ) 60 61 if uiscale is bui.UIScale.SMALL: 62 self._back_button = bui.get_special_widget('back_button') 63 bui.containerwidget( 64 edit=self._root_widget, on_cancel_call=self.main_window_back 65 ) 66 else: 67 self._back_button = bui.buttonwidget( 68 parent=self._root_widget, 69 position=(55, self._yoffs - 33), 70 size=(60, 60), 71 scale=0.8, 72 autoselect=True, 73 label=bui.charstr(bui.SpecialChar.BACK), 74 button_type='backSmall', 75 on_activate_call=self.main_window_back, 76 ) 77 bui.containerwidget( 78 edit=self._root_widget, cancel_button=self._back_button 79 ) 80 81 self._title_text = bui.textwidget( 82 parent=self._root_widget, 83 position=( 84 self._width * 0.5, 85 self._yoffs - (55 if uiscale is bui.UIScale.SMALL else 10), 86 ), 87 size=(0, 0), 88 text=bui.Lstr(resource='pluginSettingsText'), 89 maxwidth=230, 90 color=bui.app.ui_v1.title_color, 91 h_align='center', 92 v_align='center', 93 ) 94 95 # Roughly center our few bits of content. 96 x = self._width * 0.5 - 175 97 y = self._height * 0.5 + 30 98 99 self._enable_plugins_button = bui.buttonwidget( 100 parent=self._root_widget, 101 position=(x, y), 102 size=(350, 60), 103 autoselect=True, 104 label=bui.Lstr(resource='pluginsEnableAllText'), 105 text_scale=1.0, 106 on_activate_call=lambda: ConfirmWindow( 107 action=self._enable_all_plugins, 108 ), 109 ) 110 111 y -= 70 112 self._disable_plugins_button = bui.buttonwidget( 113 parent=self._root_widget, 114 position=(x, y), 115 size=(350, 60), 116 autoselect=True, 117 label=bui.Lstr(resource='pluginsDisableAllText'), 118 text_scale=1.0, 119 on_activate_call=lambda: ConfirmWindow( 120 action=self._disable_all_plugins, 121 ), 122 ) 123 124 y -= 70 125 self._enable_new_plugins_check_box = bui.checkboxwidget( 126 parent=self._root_widget, 127 position=(x, y), 128 size=(350, 60), 129 value=bui.app.config.get( 130 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY, 131 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT, 132 ), 133 text=bui.Lstr(resource='pluginsAutoEnableNewText'), 134 scale=1.0, 135 maxwidth=308, 136 on_value_change_call=self._update_value, 137 ) 138 139 if uiscale is not bui.UIScale.SMALL: 140 bui.widget( 141 edit=self._back_button, down_widget=self._enable_plugins_button 142 ) 143 144 bui.widget( 145 edit=self._disable_plugins_button, 146 left_widget=self._disable_plugins_button, 147 ) 148 149 bui.widget( 150 edit=self._enable_new_plugins_check_box, 151 left_widget=self._enable_new_plugins_check_box, 152 right_widget=self._enable_new_plugins_check_box, 153 down_widget=self._enable_new_plugins_check_box, 154 ) 155 156 @override 157 def get_main_window_state(self) -> bui.MainWindowState: 158 # Support recreating our window for back/refresh purposes. 159 cls = type(self) 160 return bui.BasicMainWindowState( 161 create_call=lambda transition, origin_widget: cls( 162 transition=transition, origin_widget=origin_widget 163 ) 164 ) 165 166 def _enable_all_plugins(self) -> None: 167 cfg = bui.app.config 168 plugs: dict[str, dict] = cfg.setdefault('Plugins', {}) 169 for plug in plugs.values(): 170 plug['enabled'] = True 171 cfg.apply_and_commit() 172 173 bui.screenmessage( 174 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 175 color=(1.0, 0.5, 0.0), 176 ) 177 178 def _disable_all_plugins(self) -> None: 179 cfg = bui.app.config 180 plugs: dict[str, dict] = cfg.setdefault('Plugins', {}) 181 for plug in plugs.values(): 182 plug['enabled'] = False 183 cfg.apply_and_commit() 184 185 bui.screenmessage( 186 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 187 color=(1.0, 0.5, 0.0), 188 ) 189 190 def _update_value(self, val: bool) -> None: 191 cfg = bui.app.config 192 cfg[bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY] = val 193 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 self._width = 1200.0 if uiscale is bui.UIScale.SMALL else 470.0 26 self._height = 900.0 if uiscale is bui.UIScale.SMALL else 360.0 27 28 # Do some fancy math to fill all available screen area up to the 29 # size of our backing container. This lets us fit to the exact 30 # screen shape at small ui scale. 31 screensize = bui.get_virtual_screen_size() 32 scale = ( 33 2.06 34 if uiscale is bui.UIScale.SMALL 35 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 36 ) 37 # Calc screen size in our local container space and clamp to a 38 # bit smaller than our container size. 39 # target_width = min(self._width - 60, screensize[0] / scale) 40 target_height = min(self._height - 100, screensize[1] / scale) 41 42 # To get top/left coords, go to the center of our window and 43 # offset by half the width/height of our target area. 44 self._yoffs = 0.5 * self._height + 0.5 * target_height + 30.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=scale, 55 ), 56 transition=transition, 57 origin_widget=origin_widget, 58 # We're affected by screen size only at small ui-scale. 59 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 60 ) 61 62 if uiscale is bui.UIScale.SMALL: 63 self._back_button = bui.get_special_widget('back_button') 64 bui.containerwidget( 65 edit=self._root_widget, on_cancel_call=self.main_window_back 66 ) 67 else: 68 self._back_button = bui.buttonwidget( 69 parent=self._root_widget, 70 position=(55, self._yoffs - 33), 71 size=(60, 60), 72 scale=0.8, 73 autoselect=True, 74 label=bui.charstr(bui.SpecialChar.BACK), 75 button_type='backSmall', 76 on_activate_call=self.main_window_back, 77 ) 78 bui.containerwidget( 79 edit=self._root_widget, cancel_button=self._back_button 80 ) 81 82 self._title_text = bui.textwidget( 83 parent=self._root_widget, 84 position=( 85 self._width * 0.5, 86 self._yoffs - (55 if uiscale is bui.UIScale.SMALL else 10), 87 ), 88 size=(0, 0), 89 text=bui.Lstr(resource='pluginSettingsText'), 90 maxwidth=230, 91 color=bui.app.ui_v1.title_color, 92 h_align='center', 93 v_align='center', 94 ) 95 96 # Roughly center our few bits of content. 97 x = self._width * 0.5 - 175 98 y = self._height * 0.5 + 30 99 100 self._enable_plugins_button = bui.buttonwidget( 101 parent=self._root_widget, 102 position=(x, y), 103 size=(350, 60), 104 autoselect=True, 105 label=bui.Lstr(resource='pluginsEnableAllText'), 106 text_scale=1.0, 107 on_activate_call=lambda: ConfirmWindow( 108 action=self._enable_all_plugins, 109 ), 110 ) 111 112 y -= 70 113 self._disable_plugins_button = bui.buttonwidget( 114 parent=self._root_widget, 115 position=(x, y), 116 size=(350, 60), 117 autoselect=True, 118 label=bui.Lstr(resource='pluginsDisableAllText'), 119 text_scale=1.0, 120 on_activate_call=lambda: ConfirmWindow( 121 action=self._disable_all_plugins, 122 ), 123 ) 124 125 y -= 70 126 self._enable_new_plugins_check_box = bui.checkboxwidget( 127 parent=self._root_widget, 128 position=(x, y), 129 size=(350, 60), 130 value=bui.app.config.get( 131 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY, 132 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT, 133 ), 134 text=bui.Lstr(resource='pluginsAutoEnableNewText'), 135 scale=1.0, 136 maxwidth=308, 137 on_value_change_call=self._update_value, 138 ) 139 140 if uiscale is not bui.UIScale.SMALL: 141 bui.widget( 142 edit=self._back_button, down_widget=self._enable_plugins_button 143 ) 144 145 bui.widget( 146 edit=self._disable_plugins_button, 147 left_widget=self._disable_plugins_button, 148 ) 149 150 bui.widget( 151 edit=self._enable_new_plugins_check_box, 152 left_widget=self._enable_new_plugins_check_box, 153 right_widget=self._enable_new_plugins_check_box, 154 down_widget=self._enable_new_plugins_check_box, 155 ) 156 157 @override 158 def get_main_window_state(self) -> bui.MainWindowState: 159 # Support recreating our window for back/refresh purposes. 160 cls = type(self) 161 return bui.BasicMainWindowState( 162 create_call=lambda transition, origin_widget: cls( 163 transition=transition, origin_widget=origin_widget 164 ) 165 ) 166 167 def _enable_all_plugins(self) -> None: 168 cfg = bui.app.config 169 plugs: dict[str, dict] = cfg.setdefault('Plugins', {}) 170 for plug in plugs.values(): 171 plug['enabled'] = True 172 cfg.apply_and_commit() 173 174 bui.screenmessage( 175 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 176 color=(1.0, 0.5, 0.0), 177 ) 178 179 def _disable_all_plugins(self) -> None: 180 cfg = bui.app.config 181 plugs: dict[str, dict] = cfg.setdefault('Plugins', {}) 182 for plug in plugs.values(): 183 plug['enabled'] = False 184 cfg.apply_and_commit() 185 186 bui.screenmessage( 187 bui.Lstr(resource='settingsWindowAdvanced.mustRestartText'), 188 color=(1.0, 0.5, 0.0), 189 ) 190 191 def _update_value(self, val: bool) -> None: 192 cfg = bui.app.config 193 cfg[bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY] = val 194 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 self._width = 1200.0 if uiscale is bui.UIScale.SMALL else 470.0 26 self._height = 900.0 if uiscale is bui.UIScale.SMALL else 360.0 27 28 # Do some fancy math to fill all available screen area up to the 29 # size of our backing container. This lets us fit to the exact 30 # screen shape at small ui scale. 31 screensize = bui.get_virtual_screen_size() 32 scale = ( 33 2.06 34 if uiscale is bui.UIScale.SMALL 35 else 1.4 if uiscale is bui.UIScale.MEDIUM else 1.0 36 ) 37 # Calc screen size in our local container space and clamp to a 38 # bit smaller than our container size. 39 # target_width = min(self._width - 60, screensize[0] / scale) 40 target_height = min(self._height - 100, screensize[1] / scale) 41 42 # To get top/left coords, go to the center of our window and 43 # offset by half the width/height of our target area. 44 self._yoffs = 0.5 * self._height + 0.5 * target_height + 30.0 45 46 super().__init__( 47 root_widget=bui.containerwidget( 48 size=(self._width, self._height), 49 toolbar_visibility=( 50 'menu_minimal' 51 if uiscale is bui.UIScale.SMALL 52 else 'menu_full' 53 ), 54 scale=scale, 55 ), 56 transition=transition, 57 origin_widget=origin_widget, 58 # We're affected by screen size only at small ui-scale. 59 refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL, 60 ) 61 62 if uiscale is bui.UIScale.SMALL: 63 self._back_button = bui.get_special_widget('back_button') 64 bui.containerwidget( 65 edit=self._root_widget, on_cancel_call=self.main_window_back 66 ) 67 else: 68 self._back_button = bui.buttonwidget( 69 parent=self._root_widget, 70 position=(55, self._yoffs - 33), 71 size=(60, 60), 72 scale=0.8, 73 autoselect=True, 74 label=bui.charstr(bui.SpecialChar.BACK), 75 button_type='backSmall', 76 on_activate_call=self.main_window_back, 77 ) 78 bui.containerwidget( 79 edit=self._root_widget, cancel_button=self._back_button 80 ) 81 82 self._title_text = bui.textwidget( 83 parent=self._root_widget, 84 position=( 85 self._width * 0.5, 86 self._yoffs - (55 if uiscale is bui.UIScale.SMALL else 10), 87 ), 88 size=(0, 0), 89 text=bui.Lstr(resource='pluginSettingsText'), 90 maxwidth=230, 91 color=bui.app.ui_v1.title_color, 92 h_align='center', 93 v_align='center', 94 ) 95 96 # Roughly center our few bits of content. 97 x = self._width * 0.5 - 175 98 y = self._height * 0.5 + 30 99 100 self._enable_plugins_button = bui.buttonwidget( 101 parent=self._root_widget, 102 position=(x, y), 103 size=(350, 60), 104 autoselect=True, 105 label=bui.Lstr(resource='pluginsEnableAllText'), 106 text_scale=1.0, 107 on_activate_call=lambda: ConfirmWindow( 108 action=self._enable_all_plugins, 109 ), 110 ) 111 112 y -= 70 113 self._disable_plugins_button = bui.buttonwidget( 114 parent=self._root_widget, 115 position=(x, y), 116 size=(350, 60), 117 autoselect=True, 118 label=bui.Lstr(resource='pluginsDisableAllText'), 119 text_scale=1.0, 120 on_activate_call=lambda: ConfirmWindow( 121 action=self._disable_all_plugins, 122 ), 123 ) 124 125 y -= 70 126 self._enable_new_plugins_check_box = bui.checkboxwidget( 127 parent=self._root_widget, 128 position=(x, y), 129 size=(350, 60), 130 value=bui.app.config.get( 131 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_CONFIG_KEY, 132 bui.app.plugins.AUTO_ENABLE_NEW_PLUGINS_DEFAULT, 133 ), 134 text=bui.Lstr(resource='pluginsAutoEnableNewText'), 135 scale=1.0, 136 maxwidth=308, 137 on_value_change_call=self._update_value, 138 ) 139 140 if uiscale is not bui.UIScale.SMALL: 141 bui.widget( 142 edit=self._back_button, down_widget=self._enable_plugins_button 143 ) 144 145 bui.widget( 146 edit=self._disable_plugins_button, 147 left_widget=self._disable_plugins_button, 148 ) 149 150 bui.widget( 151 edit=self._enable_new_plugins_check_box, 152 left_widget=self._enable_new_plugins_check_box, 153 right_widget=self._enable_new_plugins_check_box, 154 down_widget=self._enable_new_plugins_check_box, 155 )
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.
157 @override 158 def get_main_window_state(self) -> bui.MainWindowState: 159 # Support recreating our window for back/refresh purposes. 160 cls = type(self) 161 return bui.BasicMainWindowState( 162 create_call=lambda transition, origin_widget: cls( 163 transition=transition, origin_widget=origin_widget 164 ) 165 )
Return a WindowState to recreate this window, if supported.