fix [#26494] Auto run Python scripts option in User Preferences problem

- opening a file with blender by passing it as an argument would and loading it once in blender left script auto execute flag in a different state.
- command line args --enable/disable-autoexec were being overridden by the user prefs.
This commit is contained in:
Campbell Barton
2011-03-15 08:04:11 +00:00
parent b332a27429
commit b65a56ccb5
5 changed files with 24 additions and 13 deletions

View File

@@ -111,6 +111,7 @@ typedef struct Global {
#define G_DEBUG (1 << 12)
#define G_SCRIPT_AUTOEXEC (1 << 13)
#define G_SCRIPT_OVERRIDE_PREF (1 << 14) /* when this flag is set ignore the userprefs */
/* #define G_NOFROZEN (1 << 17) also removed */
#define G_GREASEPENCIL (1 << 17)

View File

@@ -271,12 +271,11 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, const char *filename
}
/* special cases, override loaded flags: */
if (G.f & G_DEBUG) bfd->globalf |= G_DEBUG;
else bfd->globalf &= ~G_DEBUG;
if (G.f & G_SWAP_EXCHANGE) bfd->globalf |= G_SWAP_EXCHANGE;
else bfd->globalf &= ~G_SWAP_EXCHANGE;
if (G.f & G_SCRIPT_AUTOEXEC) bfd->globalf |= G_SCRIPT_AUTOEXEC;
else bfd->globalf &= ~G_SCRIPT_AUTOEXEC;
if(G.f != bfd->globalf) {
const int flags_keep= (G_DEBUG | G_SWAP_EXCHANGE | G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
bfd->globalf= (bfd->globalf & ~flags_keep) | (G.f & flags_keep);
}
G.f= bfd->globalf;

View File

@@ -267,8 +267,11 @@ static void wm_init_userdef(bContext *C)
else G.fileflags &= ~G_FILE_NO_UI;
/* set the python auto-execute setting from user prefs */
/* disabled by default, unless explicitly enabled in the command line */
if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) G.f |= G_SCRIPT_AUTOEXEC;
/* enabled by default, unless explicitly enabled in the command line which overrides */
if((G.f & G_SCRIPT_OVERRIDE_PREF) == 0) {
if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) G.f |= G_SCRIPT_AUTOEXEC;
else G.f &= ~G_SCRIPT_AUTOEXEC;
}
if(U.tempdir[0]) BLI_where_is_temp(btempdir, FILE_MAX, 1);
}
@@ -300,8 +303,10 @@ void WM_read_file(bContext *C, const char *name, ReportList *reports)
/* this flag is initialized by the operator but overwritten on read.
* need to re-enable it here else drivers + registered scripts wont work. */
if(G_f & G_SCRIPT_AUTOEXEC) G.f |= G_SCRIPT_AUTOEXEC;
else G.f &= ~G_SCRIPT_AUTOEXEC;
if(G.f != G_f) {
const int flags_keep= (G_SCRIPT_AUTOEXEC | G_SCRIPT_OVERRIDE_PREF);
G.f= (G.f & ~flags_keep) | (G_f & flags_keep);
}
/* match the read WM with current WM */
wm_window_match_do(C, &wmbase);

View File

@@ -1391,8 +1391,12 @@ static void open_set_load_ui(wmOperator *op)
static void open_set_use_scripts(wmOperator *op)
{
if(!RNA_property_is_set(op->ptr, "use_scripts"))
RNA_boolean_set(op->ptr, "use_scripts", !(U.flag & USER_SCRIPT_AUTOEXEC_DISABLE));
if(!RNA_property_is_set(op->ptr, "use_scripts")) {
/* use G_SCRIPT_AUTOEXEC rather then the userpref because this means if
* the flag has been disabled from the command line, then opening
* from the menu wont enable this setting. */
RNA_boolean_set(op->ptr, "use_scripts", (G.f & G_SCRIPT_AUTOEXEC));
}
}
static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))

View File

@@ -356,12 +356,14 @@ static int end_arguments(int UNUSED(argc), const char **UNUSED(argv), void *UNUS
static int enable_python(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
{
G.f |= G_SCRIPT_AUTOEXEC;
G.f |= G_SCRIPT_OVERRIDE_PREF;
return 0;
}
static int disable_python(int UNUSED(argc), const const char **UNUSED(argv), void *UNUSED(data))
static int disable_python(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
{
G.f &= ~G_SCRIPT_AUTOEXEC;
G.f |= G_SCRIPT_OVERRIDE_PREF;
return 0;
}