Leenkx Theme

This commit is contained in:
2026-09-12 19:57:45 -07:00
parent 365c624d73
commit cf68067343
7 changed files with 1610 additions and 3 deletions

View File

@ -12,6 +12,7 @@ bl_info = {
"tracker_url": "https://leenkx.com/support"
}
from enum import IntEnum
import json
import os
from pathlib import Path
import platform
@ -32,6 +33,41 @@ from bpy.app.handlers import persistent
from bpy.props import *
from bpy.types import Operator, AddonPreferences
LEENKX_PREFS_ENV = 'LEENKX_ADDON_PREFS'
persist_props = [
'apply_theme', 'show_advanced', 'sdk_path', 'tabs',
'code_editor', 'ide_bin', 'ui_scale', 'viewport_controls',
'khamake_threads', 'khamake_threads_use_auto', 'compilation_server',
'renderdoc_path', 'ffmpeg_path', 'save_on_build', 'open_build_directory',
'cmft_use_opencl', 'legacy_shaders', 'relative_paths',
'debug_console_auto', 'debug_console_visible_sc',
'debug_console_scale_in_sc', 'debug_console_scale_out_sc',
'android_sdk_root_path', 'android_open_build_apk_directory',
'android_apk_copy_path', 'android_apk_copy_open_directory',
'html5_copy_path', 'html5_server_port',
'html5_server_log', 'profile_exporter', 'khamake_debug',
'haxe_times', 'use_leenkx_py_symlink', 'update_submodules',
]
def save_prefs():
prefs = LeenkxAddonPreferences.get_prefs()
data = {k: getattr(prefs, k) for k in persist_props}
os.environ[LEENKX_PREFS_ENV] = json.dumps(data)
def restore_prefs():
raw = os.environ.get(LEENKX_PREFS_ENV)
if not raw:
return
data = json.loads(raw)
prefs = LeenkxAddonPreferences.get_prefs()
prefs.skip_update = True
for k, v in data.items():
if hasattr(prefs, k):
setattr(prefs, k, v)
if bpy.app.version < (2, 90, 0):
ListType = List
@ -116,7 +152,9 @@ class LeenkxAddonPreferences(AddonPreferences):
return
self.skip_update = True
self.sdk_path = bpy.path.reduce_dirs([bpy.path.abspath(self.sdk_path)])[0] + '/'
save_prefs()
restart_leenkx(context)
update_theme(context)
def ide_bin_update(self, context):
if self.skip_update:
@ -311,6 +349,11 @@ class LeenkxAddonPreferences(AddonPreferences):
" development. Warning: this will invalidate the installation if the SDK is removed"),
update=lambda self, context: update_leenkx_py(get_sdk_path(context)),
)
apply_theme: BoolProperty(
name="Apply Leenkx Theme", default=True,
description="Automatically apply the Leenkx Blender theme on addon registration",
update=lambda self, context: update_theme(context),
)
def draw(self, context):
self.skip_update = False
@ -450,6 +493,7 @@ class LeenkxAddonPreferences(AddonPreferences):
col = box.column(align=True)
col.prop(self, "use_leenkx_py_symlink")
col.prop(self, "apply_theme")
@staticmethod
def get_prefs() -> 'LeenkxAddonPreferences':
@ -458,9 +502,10 @@ class LeenkxAddonPreferences(AddonPreferences):
def get_fp():
if bpy.data.filepath == '':
filepath = getattr(bpy.data, 'filepath', '')
if filepath == '':
return ''
s = bpy.data.filepath.split(os.path.sep)
s = filepath.split(os.path.sep)
s.pop()
return os.path.sep.join(s)
@ -934,13 +979,47 @@ def on_load_post(context):
bpy.app.timers.register(lambda: restart_leenkx(bpy.context), first_interval=0.1)
def remove_leenkx_theme():
if "leenkx.theme" in sys.modules:
sys.modules["leenkx.theme"].unregister()
del sys.modules["leenkx.theme"]
def apply_leenkx_theme(sdk_path: str):
remove_leenkx_theme()
import importlib.util
theme_path = os.path.join(sdk_path, "leenkx", "blender", "theme", "theme.py")
if os.path.exists(theme_path):
spec = importlib.util.spec_from_file_location(
"leenkx.theme", theme_path)
theme = importlib.util.module_from_spec(spec)
sys.modules["leenkx.theme"] = theme
spec.loader.exec_module(theme)
theme.register(sdk_path)
else:
print("Leenkx theme: theme.py not found at", theme_path)
def update_theme(context):
prefs = LeenkxAddonPreferences.get_prefs()
if prefs.apply_theme:
sdk_path = get_sdk_path(context)
if sdk_path != "":
apply_leenkx_theme(sdk_path)
else:
remove_leenkx_theme()
def on_register_post():
detect_sdk_path()
save_prefs()
restart_leenkx(bpy.context)
update_theme(bpy.context)
def register():
bpy.utils.register_class(LeenkxAddonPreferences)
restore_prefs()
bpy.utils.register_class(LnxAddonPrintVersionInfoButton)
bpy.utils.register_class(LnxAddonInstallButton)
bpy.utils.register_class(LnxAddonUpdateButton)
@ -953,7 +1032,11 @@ def register():
def unregister():
if bpy.app.timers.is_registered(on_register_post):
bpy.app.timers.unregister(on_register_post)
remove_leenkx_theme()
stop_leenkx()
save_prefs()
bpy.utils.unregister_class(LeenkxAddonPreferences)
bpy.utils.unregister_class(LnxAddonInstallButton)
bpy.utils.unregister_class(LnxAddonPrintVersionInfoButton)