UI:
* Added very basic loading of .py files on startup to define panels. It now executes all .py files in .blender/ui on startup. Right now this contains the object buttons, the C code for it is commented out. These files should get embedded in the blender executable as well eventually, that's a bit more complicated so this works for now. * For scons and cmake it seems to copy & find the files OK, for make only "make release" works (same with scripts/ folder it seems). * Added BLI_gethome_folder function in BLI_util.h. This is adapted from bpy_gethome, and gives the path to a folder in .blender like scripts or ui. There's plenty of things to figure out here about paths, embedding, caching, user configs ...
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <dirent.h>
|
||||
#else
|
||||
#include "BLI_winstuff.h"
|
||||
#endif
|
||||
|
||||
#include <Python.h>
|
||||
#include "compile.h" /* for the PyCodeObject */
|
||||
#include "eval.h" /* for PyEval_EvalCode */
|
||||
|
||||
#include "BKE_context.h"
|
||||
|
||||
#include "bpy_compat.h"
|
||||
|
||||
#include "bpy_rna.h"
|
||||
@@ -15,11 +21,15 @@
|
||||
#include "bpy_ui.h"
|
||||
|
||||
#include "DNA_space_types.h"
|
||||
|
||||
#include "BKE_text.h"
|
||||
#include "DNA_text_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_util.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_text.h"
|
||||
|
||||
void BPY_free_compiled_text( struct Text *text )
|
||||
{
|
||||
if( text->compiled ) {
|
||||
@@ -293,3 +303,41 @@ int BPY_run_python_script_space(const char *modulename, const char *func)
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* XXX this is temporary, need a proper script registration system for 2.5 */
|
||||
void BPY_run_ui_scripts(bContext *C)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
struct stat status;
|
||||
char *file_extension;
|
||||
char path[FILE_MAX];
|
||||
char *dirname= BLI_gethome_folder("ui");
|
||||
|
||||
if(!dirname)
|
||||
return;
|
||||
|
||||
dir = opendir(dirname);
|
||||
|
||||
if(!dir)
|
||||
return;
|
||||
|
||||
if (dir != NULL) {
|
||||
while((de = readdir(dir)) != NULL) {
|
||||
BLI_make_file_string("/", path, dirname, de->d_name);
|
||||
|
||||
stat(path, &status);
|
||||
|
||||
/* run if it is a .py file */
|
||||
if(S_ISREG(status.st_mode)) {
|
||||
file_extension = strstr(de->d_name, ".py");
|
||||
|
||||
if(file_extension && *(file_extension + 3) == '\0')
|
||||
BPY_run_python_script(C, path, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user