[Bf-extensions-cvs] [8397b98b] master: BlenderKit: fix subdirectory path for users if they input absolute/nonvalid relative path

Vilém Duha noreply at git.blender.org
Mon Jun 15 08:20:17 CEST 2020


Commit: 8397b98b8cb6510869d28a84592b8d7213c3b6c2
Author: Vilém Duha
Date:   Mon Jun 15 08:19:52 2020 +0200
Branches: master
https://developer.blender.org/rBA8397b98b8cb6510869d28a84592b8d7213c3b6c2

BlenderKit: fix subdirectory path for users if they input absolute/nonvalid relative path

===================================================================

M	blenderkit/__init__.py

===================================================================

diff --git a/blenderkit/__init__.py b/blenderkit/__init__.py
index 575538f8..2baee337 100644
--- a/blenderkit/__init__.py
+++ b/blenderkit/__init__.py
@@ -57,6 +57,7 @@ import math
 import time
 # import logging
 import bpy
+import pathlib
 
 from bpy.app.handlers import persistent
 import bpy.utils.previews
@@ -1391,6 +1392,27 @@ class BlenderKitSceneSearchProps(PropertyGroup, BlenderKitCommonSearchProps):
         update=search.search_update
     )
 
+def fix_subdir(self, context):
+    '''Fixes project subdicrectory settings if people input invalid path.'''
+
+    # pp = pathlib.PurePath(self.project_subdir)
+    pp = self.project_subdir[:]
+    pp = pp.replace('\\','')
+    pp = pp.replace('/','')
+    pp = pp.replace(':','')
+    pp = '//' + pp
+    if self.project_subdir != pp:
+        self.project_subdir = pp
+
+        title = "Fixed to relative path"
+        message = "This path should be always realative.\n" \
+                  " It's a directory BlenderKit creates where your .blend is \n " \
+                  "and uses it for storing assets."
+
+        def draw_message(self, context):
+            ui_panels.label_multiline(self.layout, text=message, icon='NONE', width=400)
+
+        bpy.context.window_manager.popup_menu(draw_message, title=title, icon='INFO')
 
 class BlenderKitAddonPreferences(AddonPreferences):
     # this must match the addon name, use '__package__'
@@ -1469,8 +1491,9 @@ class BlenderKitAddonPreferences(AddonPreferences):
     project_subdir: StringProperty(
         name="Project Assets Subdirectory",
         description="where data will be stored for individual projects",
-        subtype='DIR_PATH',
+        # subtype='DIR_PATH',
         default="//assets",
+        update = fix_subdir
     )
 
     directory_behaviour: EnumProperty(



More information about the Bf-extensions-cvs mailing list