Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-11 06:18:24 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-04-11 06:18:24 +0400
commitc7b587105fae174c47bd29291ac384037af06685 (patch)
treea2f8c88ea1bffb2864350ba3a494f2ceb9601117 /source
parent3ed5e2153796fb633f20d49ce7eac0db6bb82a74 (diff)
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 ...
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenlib/BLI_util.h2
-rw-r--r--source/blender/blenlib/intern/util.c96
-rw-r--r--source/blender/blenloader/intern/readfile.c1
-rw-r--r--source/blender/editors/space_buttons/buttons_object.c4
-rw-r--r--source/blender/python/BPY_extern.h1
-rw-r--r--source/blender/python/intern/bpy_interface.c56
-rw-r--r--source/creator/CMakeLists.txt4
-rw-r--r--source/creator/creator.c2
8 files changed, 162 insertions, 4 deletions
diff --git a/source/blender/blenlib/BLI_util.h b/source/blender/blenlib/BLI_util.h
index e78a58b2282..9f0c3504ef8 100644
--- a/source/blender/blenlib/BLI_util.h
+++ b/source/blender/blenlib/BLI_util.h
@@ -42,6 +42,8 @@ struct ListBase;
struct direntry;
char *BLI_gethome(void);
+char *BLI_gethome_folder(char *folder_name);
+
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
void BLI_make_existing_file(char *name);
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index f363e9c4cc5..78fc78f67f7 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -827,6 +827,102 @@ char *BLI_gethome(void) {
#endif
}
+/* this function returns the path to a blender folder, if it exists,
+ * trying in this order:
+ *
+ * $HOME/.blender/folder_name
+ * path_to_executable/.blender/folder_name
+ * release/folder_name (in svn)
+ *
+ * returns NULL if none is found. */
+
+char *BLI_gethome_folder(char *folder_name)
+{
+ extern char bprogname[]; /* argv[0] from creator.c */
+ static char homedir[FILE_MAXDIR] = "";
+ static char fulldir[FILE_MAXDIR] = "";
+ char tmpdir[FILE_MAXDIR];
+ char bprogdir[FILE_MAXDIR];
+ char *s;
+ int i;
+
+ if(folder_name) {
+ if(fulldir[0] != '\0')
+ return fulldir;
+ }
+ else if(homedir[0] != '\0')
+ return homedir;
+
+ /* BLI_gethome() can return NULL if env vars are not set */
+ s = BLI_gethome();
+
+ if(!s) { /* bail if no $HOME */
+ printf("$HOME is NOT set\n");
+ return NULL;
+ }
+
+ if(strstr(s, ".blender"))
+ BLI_strncpy(homedir, s, FILE_MAXDIR);
+ else
+ BLI_make_file_string("/", homedir, s, ".blender");
+
+ /* if $HOME/.blender/folder_name exists, return it */
+ if(BLI_exists(homedir)) {
+ if (folder_name) {
+ BLI_make_file_string("/", fulldir, homedir, folder_name);
+ if(BLI_exists(fulldir))
+ return fulldir;
+ }
+ else
+ return homedir;
+ }
+ else
+ homedir[0] = '\0';
+
+ /* if either:
+ * no homedir was found or
+ * folder_name = 1 but there's no folder_name/ inside homedir,
+ * use argv[0] (bprogname) to get .blender/ in
+ * Blender's installation dir */
+ s = BLI_last_slash(bprogname);
+
+ i = s - bprogname + 1;
+ BLI_strncpy(bprogdir, bprogname, i);
+
+ /* using tmpdir to preserve homedir (if) found above:
+ * the ideal is to have a home dir with folder_name dir inside
+ * it, but if that isn't available, it's possible to
+ * have a 'broken' home dir somewhere and a folder_name dir in the
+ * svn sources */
+ BLI_make_file_string("/", tmpdir, bprogdir, ".blender");
+
+ if(BLI_exists(tmpdir)) {
+ if(folder_name) {
+ BLI_make_file_string("/", fulldir, tmpdir, folder_name);
+ if(BLI_exists(fulldir)) {
+ BLI_strncpy(homedir, tmpdir, FILE_MAXDIR);
+ return fulldir;
+ }
+ else {
+ homedir[0] = '\0';
+ fulldir[0] = '\0';
+ }
+ }
+ else return homedir;
+ }
+
+ /* last try for folder_name dir: blender in svn dir, folder_name/ inside release/: */
+ if (folder_name) {
+ BLI_snprintf(tmpdir, sizeof(tmpdir), "release/%s", folder_name);
+ BLI_make_file_string("/", fulldir, bprogdir, tmpdir);
+ if (BLI_exists(fulldir)) return fulldir;
+ else fulldir[0] = '\0';
+ }
+
+ return NULL;
+}
+
+
void BLI_clean(char *path)
{
if(path==0) return;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a0b086ec962..4a0f8206613 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4458,6 +4458,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
pa->active= 0;
pa->sortcounter= 0;
pa->activedata= NULL;
+ pa->type= NULL;
}
ar->regiondata= newdataadr(fd, ar->regiondata);
diff --git a/source/blender/editors/space_buttons/buttons_object.c b/source/blender/editors/space_buttons/buttons_object.c
index c1c9a920921..03fd8d7768a 100644
--- a/source/blender/editors/space_buttons/buttons_object.c
+++ b/source/blender/editors/space_buttons/buttons_object.c
@@ -51,6 +51,7 @@
#include "WM_types.h"
+#if 0
static void object_panel_transform(const bContext *C, Panel *pnl)
{
uiLayout *layout= pnl->layout;
@@ -166,9 +167,11 @@ static void object_panel_animation(const bContext *C, Panel *pnl)
uiItemR(layout, "Up Axis: ", 0, &obptr, "up_axis");
uiItemR(layout, "Rotation", 0, &obptr, "track_rotation");
}
+#endif
void buttons_object_register(ARegionType *art)
{
+#if 0
PanelType *pt;
/* panels: transform */
@@ -210,5 +213,6 @@ void buttons_object_register(ARegionType *art)
pt->context= "object";
pt->draw= object_panel_animation;
BLI_addtail(&art->paneltypes, pt);
+#endif
}
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 690dc7144e6..f46ef0fa670 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -99,6 +99,7 @@ extern "C" {
/* 2.5 UI Scripts */
int BPY_run_python_script( struct bContext *C, const char *filename, struct Text *text ); // 2.5 working
int BPY_run_script_space_draw(struct bContext *C, struct SpaceScript * sc); // 2.5 working
+ void BPY_run_ui_scripts(struct bContext *C);
// int BPY_run_script_space_listener(struct bContext *C, struct SpaceScript * sc, struct ARegion *ar, struct wmNotifier *wmn); // 2.5 working
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index f8031368f06..667dd14283f 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -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);
+ }
+}
+
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 170d49fc1d8..884a6b47c14 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -100,6 +100,7 @@ IF(UNIX AND NOT APPLE)
COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/.blender/
COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/.blender/
COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/.blender/
+ COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/ui ${TARGETDIR}/.blender/
COMMAND find ${TARGETDIR} -name CVS -prune -exec rm -rf {} "\;"
)
ENDIF(UNIX AND NOT APPLE)
@@ -124,6 +125,7 @@ IF(APPLE)
COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/Resources/
COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
+ COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/ui ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
COMMAND find ${TARGETDIR}/blender.app -name CVS -prune -exec rm -rf {} "\;"
COMMAND find ${TARGETDIR}/blender.app -name CVS.sandboxinfo -prune -exec rm -rf {} "\;"
COMMAND find ${TARGETDIR}/blender.app -name .DS_Store -prune -exec rm -rf {} "\;"
@@ -139,11 +141,13 @@ IF(WIN32)
COMMAND if not exist \"${TARGETDIR}\\.blender\" mkdir \"${TARGETDIR}\\.blender\"
COMMAND if not exist \"${TARGETDIR}\\.blender\\locale\" mkdir \"${TARGETDIR}\\.blender\\locale\"
COMMAND if not exist \"${TARGETDIR}\\.blender\\scripts\" mkdir \"${TARGETDIR}\\.blender\\scripts\"
+ COMMAND if not exist \"${TARGETDIR}\\.blender\\ui\" mkdir \"${TARGETDIR}\\.blender\\ui\"
COMMAND if not exist \"${TARGETDIR}\\plugins\" mkdir \"${TARGETDIR}\\plugins\"
COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.Blanguages\" \"${TARGETDIR}\\.blender\\\"
COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.bfont.ttf\" \"${TARGETDIR}\\.blender\\\"
COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\locale\\*.*\" \"${TARGETDIR}\\.blender\\locale\"
COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\scripts\\*.*\" \"${TARGETDIR}\\.blender\\scripts\"
+ COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\ui\\*.*\" \"${TARGETDIR}\\.blender\\ui\"
COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\plugins\\*.*\" \"${TARGETDIR}\\plugins\"
COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\text\\*.*\" \"${TARGETDIR}\"
COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\windows\\extra\\python25.zip\" \"${TARGETDIR}\\\"
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 69f80570334..082f2395b3f 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -528,6 +528,8 @@ int main(int argc, char **argv)
* on U.pythondir.
*/
BPY_post_start_python();
+
+ BPY_run_ui_scripts(C);
#endif
#ifdef WITH_QUICKTIME