forked from bartvdbraak/blender
- PyLineSpit() - used to print the filename and line number for internal errors now works when executing class functions in a module.
- replaced PySys_GetObject("modules") with PyImport_GetModuleDict() - use defaults for keymap import/export rather then setting the same value every time from the UI scripts.
This commit is contained in:
parent
ae6a632534
commit
04f619d8af
@ -91,15 +91,12 @@ class USERPREF_HT_header(bpy.types.Header):
|
||||
layout.operator_context = 'INVOKE_DEFAULT'
|
||||
|
||||
if userpref.active_section == 'INPUT':
|
||||
op = layout.operator("wm.keyconfig_export")
|
||||
op.filepath = "keymap.py"
|
||||
op = layout.operator("wm.keyconfig_import")
|
||||
op.filepath = "keymap.py"
|
||||
layout.operator("wm.keyconfig_export")
|
||||
layout.operator("wm.keyconfig_import")
|
||||
elif userpref.active_section == 'ADDONS':
|
||||
op = layout.operator("wm.addon_install")
|
||||
op.filepath = "*.py"
|
||||
layout.operator("wm.addon_install")
|
||||
elif userpref.active_section == 'THEMES':
|
||||
op = layout.operator("ui.reset_default_theme")
|
||||
layout.operator("ui.reset_default_theme")
|
||||
|
||||
|
||||
class USERPREF_PT_tabs(bpy.types.Panel):
|
||||
|
@ -513,7 +513,7 @@ class WM_OT_keyconfig_import(bpy.types.Operator):
|
||||
bl_idname = "wm.keyconfig_import"
|
||||
bl_label = "Import Key Configuration..."
|
||||
|
||||
filepath = StringProperty(name="File Path", description="Filepath to write file to")
|
||||
filepath = StringProperty(name="File Path", description="Filepath to write file to", default="keymap.py")
|
||||
filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
|
||||
filter_text = BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
|
||||
filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
|
||||
@ -522,7 +522,7 @@ class WM_OT_keyconfig_import(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
import shutil
|
||||
if not self.properties.filepath:
|
||||
if not self.properties.is_property_set("filepath"):
|
||||
raise Exception("Filepath not set")
|
||||
|
||||
f = open(self.properties.filepath, "r")
|
||||
@ -582,14 +582,14 @@ class WM_OT_keyconfig_export(bpy.types.Operator):
|
||||
bl_idname = "wm.keyconfig_export"
|
||||
bl_label = "Export Key Configuration..."
|
||||
|
||||
filepath = StringProperty(name="File Path", description="Filepath to write file to")
|
||||
filepath = StringProperty(name="File Path", description="Filepath to write file to", default="keymap.py")
|
||||
filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
|
||||
filter_text = BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
|
||||
filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
|
||||
kc_name = StringProperty(name="KeyConfig Name", description="Name to save the key config as")
|
||||
|
||||
def execute(self, context):
|
||||
if not self.properties.filepath:
|
||||
if not self.properties.is_property_set("filepath"):
|
||||
raise Exception("Filepath not set")
|
||||
|
||||
f = open(self.properties.filepath, "w")
|
||||
|
@ -1117,7 +1117,7 @@ PyObject *BGL_Init(void)
|
||||
{
|
||||
PyObject *mod, *dict, *item;
|
||||
mod = PyModule_Create(&BGL_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), BGL_module_def.m_name, mod);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), BGL_module_def.m_name, mod);
|
||||
dict= PyModule_GetDict(mod);
|
||||
|
||||
if( PyType_Ready( &BGL_bufferType) < 0)
|
||||
|
@ -394,7 +394,7 @@ PyObject *BLF_Init(void)
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&BLF_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), BLF_module_def.m_name, submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), BLF_module_def.m_name, submodule);
|
||||
|
||||
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
|
||||
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
|
||||
|
@ -304,7 +304,7 @@ PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", (PyCFunction)blender_reloa
|
||||
|
||||
void bpy_text_clear_modules(int clear_all)
|
||||
{
|
||||
PyObject *modules= PySys_GetObject("modules");
|
||||
PyObject *modules= PyImport_GetModuleDict();
|
||||
|
||||
char *fname;
|
||||
char *file_extension;
|
||||
|
@ -835,7 +835,7 @@ PyObject *Geometry_Init(void)
|
||||
PyObject *submodule;
|
||||
|
||||
submodule = PyModule_Create(&M_Geometry_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), M_Geometry_module_def.m_name, submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), M_Geometry_module_def.m_name, submodule);
|
||||
|
||||
return (submodule);
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ PyObject *Mathutils_Init(void)
|
||||
return NULL;
|
||||
|
||||
submodule = PyModule_Create(&M_Mathutils_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), M_Mathutils_module_def.m_name, submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), M_Mathutils_module_def.m_name, submodule);
|
||||
|
||||
/* each type has its own new() function */
|
||||
PyModule_AddObject( submodule, "Vector", (PyObject *)&vector_Type );
|
||||
|
@ -658,7 +658,7 @@ static struct PyModuleDef noise_module_def = {
|
||||
PyObject *Noise_Init(void)
|
||||
{
|
||||
PyObject *submodule = PyModule_Create(&noise_module_def);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), noise_module_def.m_name, submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), noise_module_def.m_name, submodule);
|
||||
|
||||
/* use current time as seed for random number generator by default */
|
||||
setRndSeed(0);
|
||||
|
@ -158,7 +158,7 @@ void BPy_init_modules( void )
|
||||
mod = PyModule_New("_bpy");
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy", mod);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
|
||||
/* run first, initializes rna types */
|
||||
|
@ -259,7 +259,7 @@ PyObject *BPY_operator_module( void )
|
||||
static PyMethodDef pyop_macro_def_meth ={"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL};
|
||||
|
||||
PyObject *submodule = PyModule_New("_bpy.ops");
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), "_bpy.ops", submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy.ops", submodule);
|
||||
|
||||
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
|
||||
PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) );
|
||||
|
@ -919,7 +919,7 @@ PyObject *BPY_rna_props( void )
|
||||
{
|
||||
PyObject *submodule;
|
||||
submodule= PyModule_Create(&props_module);
|
||||
PyDict_SetItemString(PySys_GetObject("modules"), props_module.m_name, submodule);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
|
||||
|
||||
/* INCREF since its its assumed that all these functions return the
|
||||
* module with a new ref like PyDict_New, since they are passed to
|
||||
|
@ -54,7 +54,7 @@ void PyObSpit(char *name, PyObject *var) {
|
||||
}
|
||||
|
||||
void PyLineSpit(void) {
|
||||
char *filename;
|
||||
const char *filename;
|
||||
int lineno;
|
||||
|
||||
PyErr_Clear();
|
||||
@ -63,7 +63,7 @@ void PyLineSpit(void) {
|
||||
fprintf(stderr, "%s:%d\n", filename, lineno);
|
||||
}
|
||||
|
||||
void BPY_getFileAndNum(char **filename, int *lineno)
|
||||
void BPY_getFileAndNum(const char **filename, int *lineno)
|
||||
{
|
||||
PyObject *getframe, *frame;
|
||||
PyObject *f_lineno= NULL, *co_filename= NULL;
|
||||
@ -83,6 +83,7 @@ void BPY_getFileAndNum(char **filename, int *lineno)
|
||||
return;
|
||||
}
|
||||
|
||||
/* when executing a script */
|
||||
if (filename) {
|
||||
co_filename= PyObject_GetAttrStringArgs(frame, 1, "f_code", "co_filename");
|
||||
if (co_filename==NULL) {
|
||||
@ -95,6 +96,25 @@ void BPY_getFileAndNum(char **filename, int *lineno)
|
||||
Py_DECREF(co_filename);
|
||||
}
|
||||
|
||||
/* when executing a module */
|
||||
if(filename && *filename == NULL) {
|
||||
/* try an alternative method to get the filename - module based
|
||||
* references below are all borrowed (double checked) */
|
||||
PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
|
||||
if(mod_name) {
|
||||
PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
|
||||
if(mod) {
|
||||
*filename= PyModule_GetFilename(mod);
|
||||
}
|
||||
|
||||
/* unlikely, fallback */
|
||||
if(*filename == NULL) {
|
||||
*filename= _PyUnicode_AsString(mod_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (lineno) {
|
||||
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
|
||||
if (f_lineno==NULL) {
|
||||
@ -330,7 +350,7 @@ int BPy_errors_to_report(ReportList *reports)
|
||||
PyObject *pystring_format= NULL; // workaround, see below
|
||||
char *cstring;
|
||||
|
||||
char *filename;
|
||||
const char *filename;
|
||||
int lineno;
|
||||
|
||||
if (!PyErr_Occurred())
|
||||
|
@ -38,7 +38,7 @@ struct ReportList;
|
||||
|
||||
void PyObSpit(char *name, PyObject *var);
|
||||
void PyLineSpit(void);
|
||||
void BPY_getFileAndNum(char **filename, int *lineno);
|
||||
void BPY_getFileAndNum(const char **filename, int *lineno);
|
||||
|
||||
PyObject *BPY_exception_buffer(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user