[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21933] branches/blender2.5/blender: misc py/rna changes
Campbell Barton
ideasman42 at gmail.com
Sun Jul 26 20:18:15 CEST 2009
Revision: 21933
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21933
Author: campbellbarton
Date: 2009-07-26 20:18:14 +0200 (Sun, 26 Jul 2009)
Log Message:
-----------
misc py/rna changes
- running a script from a file now uses the PyRun_File(FILE *, ...) rather then PyRun_String("exec(open(r'/somepath.py').read())"...), aparently FILE struct on windows could not ensured to be the same between blender and python, since we use our own python on windows now it should be ok.
- generating docs works again (operator update for py style syntax broke them)
- python operator doc strings was being overwritten
- added rna property attribute "default" to get the default value of a property, not working on arrays currently because variable length arrays are not supported.
Modified Paths:
--------------
branches/blender2.5/blender/release/ui/bpy_ops.py
branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
branches/blender2.5/blender/source/blender/python/epy_doc_gen.py
branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
branches/blender2.5/blender/source/blender/python/intern/bpy_operator_wrap.c
branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_operators.c
Modified: branches/blender2.5/blender/release/ui/bpy_ops.py
===================================================================
--- branches/blender2.5/blender/release/ui/bpy_ops.py 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/release/ui/bpy_ops.py 2009-07-26 18:18:14 UTC (rev 21933)
@@ -3,6 +3,7 @@
from bpy.__ops__ import remove as op_remove
from bpy.__ops__ import dir as op_dir
from bpy.__ops__ import call as op_call
+from bpy.__ops__ import get_rna as op_get_rna
class bpy_ops(object):
'''
@@ -89,13 +90,22 @@
self.module = module
self.func = func
+ def idname(self):
+ # submod.foo -> SUBMOD_OT_foo
+ return self.module.upper() + '_OT_' + self.func
+
def __call__(self, **kw):
- # submod.foo -> SUBMOD_OT_foo
- id_name = self.module.upper() + '_OT_' + self.func
- # Get the operator from
- return op_call(id_name, kw)
-
+ # Get the operator from blender
+ return op_call(self.idname(), kw)
+
+ def get_rna(self):
+ '''
+ currently only used for '__rna__'
+ '''
+ return op_get_rna(self.idname())
+
+
def __repr__(self):
return "<function bpy.ops.%s.%s at 0x%x'>" % (self.module, self.func, id(self))
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/screen.c 2009-07-26 18:18:14 UTC (rev 21933)
@@ -112,7 +112,7 @@
if(art->regionid==regionid)
return art;
- printf("Error, region type missing in %s\n", st->name);
+ printf("Error, region type missing in - name:\"%s\", id:%d\n", st->name, st->spaceid);
return st->regiontypes.first;
}
Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_rna.c 2009-07-26 18:18:14 UTC (rev 21933)
@@ -432,6 +432,19 @@
return prop->flag & PROP_REGISTER_OPTIONAL;
}
+static int rna_BoolProperty_default_get(PointerRNA *ptr)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ return ((BooleanPropertyRNA*)prop)->defaultvalue;
+}
+
+static int rna_IntProperty_default_get(PointerRNA *ptr)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ return ((IntPropertyRNA*)prop)->defaultvalue;
+}
static int rna_IntProperty_hard_min_get(PointerRNA *ptr)
{
PropertyRNA *prop= (PropertyRNA*)ptr->data;
@@ -467,6 +480,12 @@
return ((IntPropertyRNA*)prop)->step;
}
+static float rna_FloatProperty_default_get(PointerRNA *ptr)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ return ((FloatPropertyRNA*)prop)->defaultvalue;
+}
static float rna_FloatProperty_hard_min_get(PointerRNA *ptr)
{
PropertyRNA *prop= (PropertyRNA*)ptr->data;
@@ -509,6 +528,19 @@
return ((FloatPropertyRNA*)prop)->precision;
}
+static void rna_StringProperty_default_get(PointerRNA *ptr, char *value)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ strcpy(value, ((StringPropertyRNA*)prop)->defaultvalue);
+}
+static int rna_StringProperty_default_length(PointerRNA *ptr)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ return strlen(((StringPropertyRNA*)prop)->defaultvalue);
+}
+
static int rna_StringProperty_max_length_get(PointerRNA *ptr)
{
PropertyRNA *prop= (PropertyRNA*)ptr->data;
@@ -516,6 +548,28 @@
return ((StringPropertyRNA*)prop)->maxlength;
}
+static EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C, PointerRNA *ptr, int *free)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ EnumPropertyRNA *eprop;
+
+ rna_idproperty_check(&prop, ptr);
+ eprop= (EnumPropertyRNA*)prop;
+
+ if(eprop->itemf==NULL || eprop->itemf==rna_EnumProperty_default_itemf)
+ return eprop->item;
+
+ return eprop->itemf(C, ptr, free);
+}
+
+/* XXX - not sore this is needed? */
+static int rna_EnumProperty_default_get(PointerRNA *ptr)
+{
+ PropertyRNA *prop= (PropertyRNA*)ptr->data;
+ rna_idproperty_check(&prop, ptr);
+ return ((EnumPropertyRNA*)prop)->defaultvalue;
+}
+
static int rna_enum_check_separator(CollectionPropertyIterator *iter, void *data)
{
EnumPropertyItem *item= (EnumPropertyItem*)data;
@@ -816,6 +870,31 @@
{
PropertyRNA *prop;
+ prop= RNA_def_property(srna, "default", type, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Default", "Default value for this number");
+
+ switch(type) {
+ case PROP_BOOLEAN:
+ RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_get", NULL);
+ break;
+ case PROP_INT:
+ RNA_def_property_int_funcs(prop, "rna_IntProperty_default_get", NULL, NULL);
+ break;
+ case PROP_FLOAT:
+ RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_get", NULL, NULL);
+ break;
+ }
+
+
+#if 0 // XXX - Variable length arrays
+ prop= RNA_def_property(srna, "default_array", type, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", NULL, NULL);
+ else RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Default", "Default value for this number");
+#endif
+
prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", NULL, NULL);
@@ -866,6 +945,11 @@
{
PropertyRNA *prop;
+ prop= RNA_def_property(srna, "default", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_funcs(prop, "rna_StringProperty_default_get", "rna_StringProperty_default_length", NULL);
+ RNA_def_property_ui_text(prop, "Default", "string default value.");
+
prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_UNSIGNED);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL, NULL);
@@ -876,6 +960,17 @@
{
PropertyRNA *prop;
+ /* the itemf func is used instead, keep blender happy */
+ static EnumPropertyItem default_dummy_items[] = {
+ {PROP_NONE, "DUMMY", 0, "Dummy", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+ prop= RNA_def_property(srna, "default", PROP_ENUM, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_enum_items(prop, default_dummy_items);
+ RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf");
+ RNA_def_property_ui_text(prop, "Default", "Default value for this enum");
+
prop= RNA_def_property(srna, "items", PROP_COLLECTION, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "EnumPropertyItem");
Modified: branches/blender2.5/blender/source/blender/python/epy_doc_gen.py
===================================================================
--- branches/blender2.5/blender/source/blender/python/epy_doc_gen.py 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/source/blender/python/epy_doc_gen.py 2009-07-26 18:18:14 UTC (rev 21933)
@@ -503,20 +503,21 @@
def op2epy(target_path):
out = open(target_path, 'w')
- operators = dir(bpy.ops)
- operators.remove('add')
- operators.remove('remove')
- operators.sort()
+ op_mods = dir(bpy.ops)
+ op_mods.remove('add')
+ op_mods.remove('remove')
- for op in operators:
-
- if op.startswith('__'):
+ for op_mod_name in sorted(op_mods):
+ if op_mod_name.startswith('__'):
continue
+
+ op_mod = getattr(bpy.ops, op_mod_name)
- # rna = getattr(bpy.types, op).__rna__
- rna = bpy.ops.__rna__(op)
-
- write_func(rna, '', out, 'OPERATOR')
+ operators = dir(op_mod)
+ for op in sorted(operators):
+ # rna = getattr(bpy.types, op).__rna__
+ rna = getattr(op_mod, op).get_rna()
+ write_func(rna, '', out, 'OPERATOR')
out.write('\n')
out.close()
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_interface.c 2009-07-26 18:18:14 UTC (rev 21933)
@@ -260,10 +260,16 @@
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
} else {
- char pystring[512];
- /* TODO - look into a better way to run a file */
- sprintf(pystring, "exec(open(r'%s').read())", fn);
- py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
+ FILE *fp= fopen(fn, "r");
+ if(fp) {
+ py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
+ fclose(fp);
+ }
+ else {
+ PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
+ py_result= NULL;
+ }
+
}
if (!py_result) {
Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-07-26 17:29:25 UTC (rev 21932)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_operator.c 2009-07-26 18:18:14 UTC (rev 21933)
@@ -38,6 +38,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
+#include "BKE_utildefines.h"
/* 'self' stores the operator string */
@@ -77,14 +78,14 @@
}
- ot= WM_operatortype_find(opname, 1);
+ ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "bpy.__ops__.call: operator \"%s\"could not be found", opname);
return NULL;
}
- if(ot->poll && (ot->poll(C) == 0)) {
+ if(ot->poll && (ot->poll(C) == FALSE)) {
PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
return NULL;
}
@@ -146,10 +147,38 @@
return list;
}
+static PyObject *pyop_getrna(PyObject *self, PyObject *value)
+{
+ wmOperatorType *ot;
+ PointerRNA ptr;
+ char *opname= _PyUnicode_AsString(value);
+ BPy_StructRNA *pyrna= NULL;
+
+ if(opname==NULL) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list