Download tasks/t19-blender-rig-full/environment/nocode_guard.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.76 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t19-blender-rig-full/environment/nocode_guard.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t19-blender-rig-full/environment/nocode_guard.py
-
curl -L -o nocode_guard.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t19-blender-rig-full/environment/nocode_guard.py
3.76 kB
| # Blender startup script (installed by nocode-patch.py into scripts/startup/). | |
| # | |
| # Keeps the coding surfaces closed at run time, complementing the build-time | |
| # removal of the console backend and the Run Script UI: | |
| # * removes the "Scripting" workspace (from the startup file, and again if | |
| # it is re-added through the "+" workspace menu); | |
| # * converts any Python Console / Text Editor area back to the Info editor; | |
| # * drops the Alt+P "Run Script" keymap entry; | |
| # * pins the preferences: no Python tooltips, no Developer Extras (F3 search | |
| # stays menu-only), no auto-run of file-embedded scripts, no splash. | |
| # Runs as a persistent 1 s timer plus a load_post handler. Silent on errors — | |
| # the guard must never break the editor the agent is working in. | |
| import bpy | |
| from bpy.app.handlers import persistent | |
| BANNED_AREAS = {"CONSOLE", "TEXT_EDITOR"} | |
| BANNED_WORKSPACES = ("scripting",) | |
| def _pin_prefs(): | |
| try: | |
| p = bpy.context.preferences | |
| p.view.show_splash = False | |
| p.view.show_tooltips_python = False | |
| p.view.show_developer_ui = False | |
| p.filepaths.use_scripts_auto_execute = False | |
| except Exception: | |
| pass | |
| def _drop_run_script_keymap(): | |
| try: | |
| wm = bpy.context.window_manager | |
| for kc in (wm.keyconfigs.default, wm.keyconfigs.addon, wm.keyconfigs.user, wm.keyconfigs.active): | |
| if kc is None: | |
| continue | |
| km = kc.keymaps.get("Text") | |
| if km is None: | |
| continue | |
| for kmi in list(km.keymap_items): | |
| if kmi.idname in ("text.run_script", "console.execute"): | |
| km.keymap_items.remove(kmi) | |
| except Exception: | |
| pass | |
| def _remove_scripting_workspaces(): | |
| try: | |
| doomed = [ws for ws in bpy.data.workspaces if ws.name.lower().startswith(BANNED_WORKSPACES)] | |
| if doomed and len(bpy.data.workspaces) > len(doomed): | |
| # never leave a window on a workspace we are about to delete | |
| fallback = next(ws for ws in bpy.data.workspaces if ws not in doomed) | |
| for win in bpy.context.window_manager.windows: | |
| if win.workspace in doomed: | |
| win.workspace = fallback | |
| bpy.data.batch_remove(ids=doomed) | |
| except Exception: | |
| pass | |
| def _convert_banned_areas(): | |
| try: | |
| for win in bpy.context.window_manager.windows: | |
| for area in win.screen.areas: | |
| if area.type in BANNED_AREAS: | |
| try: | |
| with bpy.context.temp_override(window=win, area=area): | |
| area.type = "INFO" | |
| except Exception: | |
| try: | |
| area.type = "INFO" | |
| except Exception: | |
| pass | |
| except Exception: | |
| pass | |
| def _guard(): | |
| _remove_scripting_workspaces() | |
| _convert_banned_areas() | |
| return 1.0 | |
| def _on_load(_dummy=None): | |
| _pin_prefs() | |
| _drop_run_script_keymap() | |
| _remove_scripting_workspaces() | |
| _convert_banned_areas() | |
| def register(): | |
| if bpy.app.background: | |
| return # the verifier / oracle run Blender headless; leave them alone | |
| _pin_prefs() | |
| if _on_load not in bpy.app.handlers.load_post: | |
| bpy.app.handlers.load_post.append(_on_load) | |
| if not bpy.app.timers.is_registered(_guard): | |
| bpy.app.timers.register(_guard, first_interval=2.0, persistent=True) | |
| bpy.app.timers.register(lambda: (_on_load(), None)[1], first_interval=1.0) | |
| def unregister(): | |
| try: | |
| bpy.app.handlers.load_post.remove(_on_load) | |
| except ValueError: | |
| pass | |
| if bpy.app.timers.is_registered(_guard): | |
| bpy.app.timers.unregister(_guard) | |