Page MenuHome
Paste P1045

T63775_resource_datafiles
ActivePublic

Authored by Philipp Oeser (lichtwerk) on Jul 19 2019, 4:58 PM.
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index e6424de0742..8d913f54a70 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -44,6 +44,7 @@ __all__ = (
"manual_map",
"previews",
"resource_path",
+ "resource_datafiles",
"script_path_user",
"script_path_pref",
"script_paths",
@@ -62,6 +63,7 @@ from _bpy import (
escape_identifier,
register_class,
resource_path,
+ resource_datafiles,
script_paths as _bpy_script_paths,
unregister_class,
user_resource as _user_resource,
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index e7e95c26b55..565ee121744 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -195,11 +195,11 @@ class ToolSelectPanelHelper:
assert(type(icon_name) is str)
icon_value = _icon_cache.get(icon_name)
if icon_value is None:
- dirname = bpy.utils.resource_path('LOCAL')
+ dirname = bpy.utils.resource_datafiles()
if not os.path.exists(dirname):
- # TODO(campbell): use a better way of finding datafiles.
- dirname = bpy.utils.resource_path('SYSTEM')
- filename = os.path.join(dirname, "datafiles", "icons", icon_name + ".dat")
+ # TODO(philipp): what to do then?
+ pass
+ filename = os.path.join(dirname, "icons", icon_name + ".dat")
try:
icon_value = bpy.app.icons.new_triangles_from_file(filename)
except Exception as ex:
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index 92ba7704b19..b436336844d 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -231,6 +231,22 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
return PyC_UnicodeFromByte(path ? path : "");
}
+PyDoc_STRVAR(bpy_resource_datafiles_doc,
+ ".. function:: script_paths()\n"
+ "\n"
+ " Return the resource datafiles path.\n"
+ "\n"
+ " :return: the resource datafiles path.\n"
+ " :rtype: string\n");
+static PyObject *bpy_resource_datafiles(PyObject *UNUSED(self))
+{
+ const char *path;
+
+ path = BKE_appdir_folder_id(BLENDER_DATAFILES, NULL);
+
+ return PyC_UnicodeFromByte(path ? path : "");
+}
+
PyDoc_STRVAR(bpy_escape_identifier_doc,
".. function:: escape_identifier(string)\n"
"\n"
@@ -298,6 +314,12 @@ static PyMethodDef meth_bpy_resource_path = {
METH_VARARGS | METH_KEYWORDS,
bpy_resource_path_doc,
};
+static PyMethodDef meth_bpy_resource_datafiles = {
+ "resource_datafiles",
+ (PyCFunction)bpy_resource_datafiles,
+ METH_NOARGS,
+ bpy_resource_datafiles_doc,
+};
static PyMethodDef meth_bpy_escape_identifier = {
"escape_identifier",
(PyCFunction)bpy_escape_identifier,
@@ -400,6 +422,9 @@ void BPy_init_modules(void)
PyModule_AddObject(mod,
meth_bpy_resource_path.ml_name,
(PyObject *)PyCFunction_New(&meth_bpy_resource_path, NULL));
+ PyModule_AddObject(mod,
+ meth_bpy_resource_datafiles.ml_name,
+ (PyObject *)PyCFunction_New(&meth_bpy_resource_datafiles, NULL));
PyModule_AddObject(mod,
meth_bpy_escape_identifier.ml_name,
(PyObject *)PyCFunction_New(&meth_bpy_escape_identifier, NULL));

Event Timeline

Docstring refers to script_paths, think this should be using system datafiles in all cases, will reply to T63775