mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-13 06:53:36 +00:00
Operator to disable BBIM and restart Blender
as it's needed to reload the translations Update bbim_setup_translations.py Update bbim_setup_translations.py
This commit is contained in:
@@ -24,7 +24,7 @@ ADDON_NAME = "localization_test"
|
|||||||
BRANCHES_DIR = Path(context.preferences.filepaths.i18n_branches_directory)
|
BRANCHES_DIR = Path(context.preferences.filepaths.i18n_branches_directory)
|
||||||
|
|
||||||
|
|
||||||
def is_addon_loaded(addon_name):
|
def is_addon_loaded(addon_name) -> bool:
|
||||||
loaded_default, loaded_state = addon_utils.check(addon_name)
|
loaded_default, loaded_state = addon_utils.check(addon_name)
|
||||||
return loaded_state
|
return loaded_state
|
||||||
|
|
||||||
@@ -183,9 +183,6 @@ class SetupTranslationUI(bpy.types.Operator):
|
|||||||
|
|
||||||
context.scene.translation_ui_is_loaded = True
|
context.scene.translation_ui_is_loaded = True
|
||||||
|
|
||||||
# TODO: restart blender
|
|
||||||
# https://blender.stackexchange.com/questions/282431/restarting-blender-with-a-script
|
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -276,6 +273,30 @@ class UpdateTranslationsFromPo(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class DisableEnableAddon(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.disable_enable_addon"
|
||||||
|
bl_label = "Disable/Enable addon"
|
||||||
|
bl_description = "Will enable addon if it's disabled, will disable it and restart Blender otherwise"
|
||||||
|
bl_options = set()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if not is_addon_loaded(ADDON_NAME):
|
||||||
|
addon_utils.enable("blenderbim", default_set=True)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
addon_utils.disable("blenderbim", default_set=True)
|
||||||
|
|
||||||
|
blender_exe = bpy.app.binary_path
|
||||||
|
head, tail = os.path.split(blender_exe)
|
||||||
|
blender_launcher = os.path.join(head, "blender-launcher.exe")
|
||||||
|
subprocess.run([blender_launcher, "-con", "--python-expr", "import bpy; bpy.ops.wm.recover_last_session()"])
|
||||||
|
bpy.ops.wm.quit_blender()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class BBIM_PT_translations(bpy.types.Panel):
|
class BBIM_PT_translations(bpy.types.Panel):
|
||||||
bl_label = "BlenderBIM Translations"
|
bl_label = "BlenderBIM Translations"
|
||||||
bl_idname = "BBIM_PT_translations"
|
bl_idname = "BBIM_PT_translations"
|
||||||
@@ -290,6 +311,11 @@ class BBIM_PT_translations(bpy.types.Panel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
layout.operator("bim.reload_py_translations", icon="FILE_REFRESH")
|
layout.operator("bim.reload_py_translations", icon="FILE_REFRESH")
|
||||||
|
addon_enabled = is_addon_loaded(ADDON_NAME)
|
||||||
|
layout.operator("bim.disable_enable_addon",
|
||||||
|
icon="QUIT" if addon_enabled else "PLUGIN",
|
||||||
|
text="Disable Addon And Restart Blender" if addon_enabled else "Enable Addon")
|
||||||
|
layout.separator()
|
||||||
layout.operator("bim.convert_translations_to_po", icon="EXPORT")
|
layout.operator("bim.convert_translations_to_po", icon="EXPORT")
|
||||||
layout.operator("bim.update_translations_from_po", icon="IMPORT")
|
layout.operator("bim.update_translations_from_po", icon="IMPORT")
|
||||||
|
|
||||||
@@ -299,6 +325,7 @@ classes = (
|
|||||||
ConvertTranslationsToPo,
|
ConvertTranslationsToPo,
|
||||||
UpdateTranslationsFromPo,
|
UpdateTranslationsFromPo,
|
||||||
SetupTranslationUI,
|
SetupTranslationUI,
|
||||||
|
DisableEnableAddon,
|
||||||
BBIM_PT_translations,
|
BBIM_PT_translations,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user