Skip to content
Snippets Groups Projects
Commit c7b58710 authored by Brecht Van Lommel's avatar Brecht Van Lommel
Browse files

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 ...
parent 3ed5e215
No related branches found
No related tags found
No related merge requests found
......@@ -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 = []
......
......@@ -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
......
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")
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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
}
......@@ -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
......
#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);
}
}
......@@ -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}\\\"
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment