diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2020-06-15 09:19:52 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2020-06-15 09:20:05 +0300 |
commit | 8397b98b8cb6510869d28a84592b8d7213c3b6c2 (patch) | |
tree | 8d4223bd13a65d71ba3603effebb0f2959d7890e /blenderkit | |
parent | a26d6216858fd5e37e65fa2dafb3ff6fa073f9ff (diff) |
BlenderKit: fix subdirectory path for users if they input absolute/nonvalid relative path
Diffstat (limited to 'blenderkit')
-rw-r--r-- | blenderkit/__init__.py | 25 |
1 files changed, 24 insertions, 1 deletions
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( |