UI:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 11 Apr 2009 02:18:24 +0000 (02:18 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 11 Apr 2009 02:18:24 +0000 (02:18 +0000)
* 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 ...

SConstruct
release/Makefile
release/ui/buttons_objects.py [new file with mode: 0644]
source/blender/blenlib/BLI_util.h
source/blender/blenlib/intern/util.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_buttons/buttons_object.c
source/blender/python/BPY_extern.h
source/blender/python/intern/bpy_interface.c
source/creator/CMakeLists.txt
source/creator/creator.c

index c91b44e3659166161ca687a4ee6ebf60a17c0533..cfe48257c3eb0b95dc8741e34309b869f92afca0 100644 (file)
@@ -472,6 +472,17 @@ if  env['OURPLATFORM']!='darwin':
                                source=[dp+os.sep+f for f in df]
                                scriptinstall.append(env.Install(dir=dir,source=source))
 
+                       #-- .blender/ui 
+                       scriptpath='release/ui'
+                       for dp, dn, df in os.walk(scriptpath):
+                               if 'CVS' in dn:
+                                       dn.remove('CVS')
+                               if '.svn' in dn:
+                                       dn.remove('.svn')
+                               dir=env['BF_INSTALLDIR']+'/.blender/ui'+dp[len(scriptpath):]
+                               source=[dp+os.sep+f for f in df]
+                               scriptinstall.append(env.Install(dir=dir,source=source))
+
 #-- icons
 if env['OURPLATFORM']=='linux2':
        iconlist = []
index 43a369d8f77f10377673ee62e029b67237062e8c..79258f0376742457ad8e5a9bf6d74ff0b9c08779 100644 (file)
@@ -163,6 +163,9 @@ endif
        @echo "----> Copy python infrastructure"
        @[ ! -d scripts ] || cp -r scripts $(CONFDIR)/scripts
 
+       @echo "----> Copy python UI files"
+       @[ ! -d ui ] || cp -r ui $(CONFDIR)/ui
+
     ifeq ($(OS),darwin)
        @echo "----> Move .blender to .app/Contents/MacOS/"
        @rm -fr $(DISTDIR)/blender$(EXT0)/Contents/MacOS/.blender
diff --git a/release/ui/buttons_objects.py b/release/ui/buttons_objects.py
new file mode 100644 (file)
index 0000000..48c113a
--- /dev/null
@@ -0,0 +1,124 @@
+
+class OBJECT_PT_transform(bpy.types.Panel):
+       __label__ = "Transform"
+       __context__ = "object"
+
+       def draw(self, context):
+               ob = context.active_object
+               layout = self.layout
+
+               if not ob:
+                       return
+
+               layout.template_column_flow(3)
+               layout.itemR(ob, "location")
+               layout.itemR(ob, "rotation")
+               layout.itemR(ob, "scale")
+
+class OBJECT_PT_groups(bpy.types.Panel):
+       __label__ = "Groups"
+       __context__ = "object"
+
+       def draw(self, context):
+               ob = context.active_object
+               layout = self.layout
+
+               if not ob:
+                       return
+
+               layout.template_column_flow(2)
+               layout.itemR(ob, "pass_index")
+               layout.itemR(ob, "parent")
+
+               # layout.template_left_right()
+               # layout.itemO("OBJECT_OT_add_group");
+
+               for group in bpy.data.groups:
+                       if ob in group.objects:
+                               sublayout = layout.template_stack()
+
+                               sublayout.template_left_right()
+                               sublayout.itemR(group, "name")
+                               # sublayout.itemO("OBJECT_OT_remove_group")
+
+                               sublayout.template_column_flow(2)
+                               sublayout.itemR(group, "layer")
+                               sublayout.itemR(group, "dupli_offset")
+
+class OBJECT_PT_display(bpy.types.Panel):
+       __label__ = "Display"
+       __context__ = "object"
+
+       def draw(self, context):
+               ob = context.active_object
+               layout = self.layout
+
+               if not ob:
+                       return
+
+               layout.template_column_flow(2)
+               layout.itemR(ob, "max_draw_type", text="Type")
+               layout.itemR(ob, "draw_bounds_type", text="Bounds")
+
+               layout.template_column_flow(2)
+               layout.itemR(ob, "draw_name", text="Name")
+               layout.itemR(ob, "draw_axis", text="Axis")
+               layout.itemR(ob, "draw_wire", text="Wire")
+               layout.itemR(ob, "draw_texture_space", text="Texture Space")
+               layout.itemR(ob, "x_ray", text="X-Ray")
+               layout.itemR(ob, "draw_transparent", text="Transparency")
+
+class OBJECT_PT_duplication(bpy.types.Panel):
+       __label__ = "Duplication"
+       __context__ = "object"
+
+       def draw(self, context):
+               ob = context.active_object
+               layout = self.layout
+
+               if not ob:
+                       return
+
+               layout.template_column()
+               layout.itemR(ob, "dupli_type", text="")
+
+               if ob.dupli_type == "FRAMES":
+                       layout.template_column_flow(2)
+                       layout.itemR(ob, "dupli_frames_start", text="Start:")
+                       layout.itemR(ob, "dupli_frames_end", text="End:")
+                       layout.itemR(ob, "dupli_frames_on", text="On:")
+                       layout.itemR(ob, "dupli_frames_off", text="Off:")
+
+class OBJECT_PT_animation(bpy.types.Panel):
+       __label__ = "Animation"
+       __context__ = "object"
+
+       def draw(self, context):
+               ob = context.active_object
+               layout = self.layout
+
+               if not ob:
+                       return
+
+               layout.template_column()
+               
+               layout.template_slot("COLUMN_1")
+               layout.itemL(text="Time Offset:")
+               layout.itemR(ob, "time_offset_edit", text="Edit")
+               layout.itemR(ob, "time_offset_particle", text="Particle")
+               layout.itemR(ob, "time_offset_parent", text="Parent")
+               layout.itemR(ob, "slow_parent")
+               layout.itemR(ob, "time_offset", text="Offset:")
+               
+               layout.template_slot("COLUMN_2")
+               layout.itemL(text="Tracking:")
+               layout.itemR(ob, "track_axis", text="Axis")
+               layout.itemR(ob, "up_axis", text="Up Axis")
+               layout.itemR(ob, "track_rotation", text="Rotation")
+
+bpy.ui.addPanel(OBJECT_PT_transform, "BUTTONS_WINDOW", "WINDOW")
+bpy.ui.addPanel(OBJECT_PT_groups, "BUTTONS_WINDOW", "WINDOW")
+bpy.ui.addPanel(OBJECT_PT_display, "BUTTONS_WINDOW", "WINDOW")
+bpy.ui.addPanel(OBJECT_PT_duplication, "BUTTONS_WINDOW", "WINDOW")
+bpy.ui.addPanel(OBJECT_PT_animation, "BUTTONS_WINDOW", "WINDOW")
+
index e78a58b2282a505817d2f22b361dccd364268231..9f0c3504ef80b2ad0b3023413a655be7acb4324c 100644 (file)
@@ -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);
index f363e9c4cc511f4837cbf148877b9ece63f36867..78fc78f67f76a64822f32e24e083890fa4cfb5c6 100644 (file)
@@ -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;
index a0b086ec96276208fd4d64b834c1343b1af0ba8e..4a0f8206613e3469c70aa2793ed195f47f344193 100644 (file)
@@ -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);
index c1c9a920921bf2b7a1b07cdec6ea8cda42d94b33..03fd8d7768a2ea1b29721842840c5dcb1b295ff1 100644 (file)
@@ -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
 }
 
index 690dc7144e603382144b245a65ae718e24f9bfdc..f46ef0fa670e7948f72806bbe9a2321f4250a2de 100644 (file)
@@ -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
        
        
index f8031368f064d01a5ffa6b9a312a195c55882524..667dd14283f0d1b8bdd545286e8291ea5679829e 100644 (file)
@@ -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"
 #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);
+       }
+}
+
index 170d49fc1d8c8868c4c6adabbbe4e748e0b3ffb1..884a6b47c1479f764c1374f3396d9b83d9b36686 100644 (file)
@@ -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}\\\"
index 69f805703343e7ff0b1343d55c8c222890299387..082f2395b3f442c44a7a8590b514d5a14e545a1b 100644 (file)
@@ -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