forked from LeenkxTeam/LNXSDK
Blender 2.8 - 4.5 Support
This commit is contained in:
58
leenkx.py
58
leenkx.py
@ -24,7 +24,7 @@ import textwrap
|
||||
import threading
|
||||
import traceback
|
||||
import typing
|
||||
from typing import Callable, Optional
|
||||
from typing import Callable, Optional, List
|
||||
import webbrowser
|
||||
|
||||
import bpy
|
||||
@ -33,6 +33,12 @@ from bpy.props import *
|
||||
from bpy.types import Operator, AddonPreferences
|
||||
|
||||
|
||||
if bpy.app.version < (2, 90, 0):
|
||||
ListType = List
|
||||
else:
|
||||
ListType = list
|
||||
|
||||
|
||||
class SDKSource(IntEnum):
|
||||
PREFS = 0
|
||||
LOCAL = 1
|
||||
@ -58,8 +64,45 @@ def get_os():
|
||||
else:
|
||||
return 'linux'
|
||||
|
||||
|
||||
def detect_sdk_path():
|
||||
"""Auto-detect the SDK path after Leenkx installation."""
|
||||
preferences = bpy.context.preferences
|
||||
addon_prefs = preferences.addons["leenkx"].preferences
|
||||
|
||||
# Don't overwrite if already set
|
||||
if addon_prefs.sdk_path:
|
||||
return
|
||||
|
||||
# For all versions, try to get the path from the current file location first
|
||||
current_file = os.path.realpath(__file__)
|
||||
if os.path.exists(current_file):
|
||||
# Go up one level from the current file's directory to get the SDK root
|
||||
sdk_path = os.path.dirname(os.path.dirname(current_file))
|
||||
if os.path.exists(os.path.join(sdk_path, "leenkx")):
|
||||
addon_prefs.sdk_path = sdk_path
|
||||
return
|
||||
|
||||
# Fallback for Blender 2.92+ with the original method
|
||||
if bpy.app.version >= (2, 92, 0):
|
||||
try:
|
||||
win = bpy.context.window_manager.windows[0]
|
||||
area = win.screen.areas[0]
|
||||
area_type = area.type
|
||||
area.type = "INFO"
|
||||
|
||||
with bpy.context.temp_override(window=win, screen=win.screen, area=area):
|
||||
bpy.ops.info.select_all(action='SELECT')
|
||||
bpy.ops.info.report_copy()
|
||||
|
||||
clipboard = bpy.context.window_manager.clipboard
|
||||
match = re.findall(r"^Modules Installed .* from '(.*leenkx.py)' into",
|
||||
clipboard, re.MULTILINE)
|
||||
if match:
|
||||
addon_prefs.sdk_path = os.path.dirname(match[-1])
|
||||
finally:
|
||||
area.type = area_type
|
||||
|
||||
def detect_sdk_path22():
|
||||
"""Auto-detect the SDK path after Leenkx installation."""
|
||||
# Do not overwrite the SDK path (this method gets
|
||||
# called after each registration, not after
|
||||
@ -73,6 +116,7 @@ def detect_sdk_path():
|
||||
area = win.screen.areas[0]
|
||||
area_type = area.type
|
||||
area.type = "INFO"
|
||||
|
||||
with bpy.context.temp_override(window=win, screen=win.screen, area=area):
|
||||
bpy.ops.info.select_all(action='SELECT')
|
||||
bpy.ops.info.report_copy()
|
||||
@ -558,7 +602,7 @@ def remove_readonly(func, path, excinfo):
|
||||
func(path)
|
||||
|
||||
|
||||
def run_proc(cmd: list[str], done: Optional[Callable[[bool], None]] = None):
|
||||
def run_proc(cmd: ListType[str], done: Optional[Callable[[bool], None]] = None):
|
||||
def fn(p, done):
|
||||
p.wait()
|
||||
if done is not None:
|
||||
@ -840,7 +884,13 @@ def update_leenkx_py(sdk_path: str, force_relink=False):
|
||||
else:
|
||||
raise err
|
||||
else:
|
||||
lnx_module_file.unlink(missing_ok=True)
|
||||
if bpy.app.version < (2, 92, 0):
|
||||
try:
|
||||
lnx_module_file.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
lnx_module_file.unlink(missing_ok=True)
|
||||
shutil.copy(Path(sdk_path) / 'leenkx.py', lnx_module_file)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user