[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20891] branches/soc-2009-kazanbas: File selector working.
Arystanbek Dyussenov
arystan.d at gmail.com
Mon Jun 15 10:12:28 CEST 2009
Revision: 20891
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20891
Author: kazanbas
Date: 2009-06-15 10:12:28 +0200 (Mon, 15 Jun 2009)
Log Message:
-----------
File selector working. For now it is accessed as
context.add_fileselect(self.__operator__).
To allow file selector, I made the following changes:
- moved property definition funcs (FloatProperty, etc.) to "bpy.props"
to make them accessible from io scripts. Previously they were only
accessible in scripts running from Text Editor.
- added the "__operator__" instance attribute to py operators. The value
is RNA operator pointer.
Note that "context.add_fileselect" changes were mistakenly committed
with my last merge.
Modified Paths:
--------------
branches/soc-2009-kazanbas/release/io/export_obj.py
branches/soc-2009-kazanbas/source/blender/python/intern/bpy_interface.c
branches/soc-2009-kazanbas/source/blender/python/intern/bpy_operator_wrap.c
branches/soc-2009-kazanbas/source/blender/python/intern/bpy_rna.c
Modified: branches/soc-2009-kazanbas/release/io/export_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_obj.py 2009-06-15 07:47:09 UTC (rev 20890)
+++ branches/soc-2009-kazanbas/release/io/export_obj.py 2009-06-15 08:12:28 UTC (rev 20891)
@@ -1,3 +1,4 @@
+
import bpy
class SCRIPT_OT_export_obj(bpy.types.Operator):
@@ -7,6 +8,7 @@
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
__props__ = [
+ bpy.props["StringProperty"](attr="filename", name="filename", default="/tmp")
# FloatProperty(attr="setting_1", name="Example 1", default=10.0, min=0, max=10, description="Add info here"),
# StringProperty(attr="filename")
]
@@ -17,11 +19,13 @@
def exec(self, context):
# print(self.setting_1)
self.debug("exec")
- return 'FINISHED'
+ self.debug("filename = " + self.filename)
+ return ('FINISHED',)
def invoke(self, context, event):
self.debug("invoke")
- return self.exec(context)
+ context.add_fileselect(self.__operator__)
+ return ('RUNNING_MODAL',) #self.exec(context)
def poll(self, context): # poll isnt working yet
self.debug("poll")
Modified: branches/soc-2009-kazanbas/source/blender/python/intern/bpy_interface.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/python/intern/bpy_interface.c 2009-06-15 07:47:09 UTC (rev 20890)
+++ branches/soc-2009-kazanbas/source/blender/python/intern/bpy_interface.c 2009-06-15 08:12:28 UTC (rev 20891)
@@ -60,6 +60,7 @@
PyModule_AddObject( mod, "types", BPY_rna_types() );
PyModule_AddObject( mod, "ops", BPY_operator_module() );
PyModule_AddObject( mod, "ui", BPY_ui_module() ); // XXX very experemental, consider this a test, especially PyCObject is not meant to be perminant
+ PyModule_AddObject( mod, "props", BPY_rna_props() );
/* add the module so we can import it */
PyDict_SetItemString(PySys_GetObject("modules"), "bpy", mod);
@@ -95,22 +96,6 @@
// XXX - evil, need to access context
BPy_SetContext(C);
- // XXX - put somewhere more logical
- {
- PyMethodDef *ml;
- static PyMethodDef bpy_prop_meths[] = {
- {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""},
- {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""},
- {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""},
- {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""},
- {NULL, NULL, 0, NULL}
- };
-
- for(ml = bpy_prop_meths; ml->ml_name; ml++) {
- PyDict_SetItemString( dict, ml->ml_name, PyCFunction_New(ml, NULL));
- }
- }
-
/* add bpy to global namespace */
mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
PyDict_SetItemString( dict, "bpy", mod );
Modified: branches/soc-2009-kazanbas/source/blender/python/intern/bpy_operator_wrap.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/python/intern/bpy_operator_wrap.c 2009-06-15 07:47:09 UTC (rev 20890)
+++ branches/soc-2009-kazanbas/source/blender/python/intern/bpy_operator_wrap.c 2009-06-15 08:12:28 UTC (rev 20891)
@@ -225,6 +225,8 @@
PyObject *ret= NULL, *py_class_instance, *item= NULL;
int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
PointerRNA ptr_context;
+ PyObject ptr_operator;
+ PyObject *py_operator;
PyGILState_STATE gilstate = PyGILState_Ensure();
@@ -261,6 +263,12 @@
RNA_property_collection_end(&iter);
}
+ /* set operator pointer RNA as instance "__operator__" attribute */
+ RNA_pointer_create(NULL, &RNA_Operator, op, &ptr_operator);
+ py_operator= pyrna_struct_CreatePyObject(&ptr_operator);
+ PyObject_SetAttrString(py_class_instance, "__operator__", py_operator);
+ Py_DECREF(py_operator);
+
RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
if (mode==PYOP_INVOKE) {
Modified: branches/soc-2009-kazanbas/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/python/intern/bpy_rna.c 2009-06-15 07:47:09 UTC (rev 20890)
+++ branches/soc-2009-kazanbas/source/blender/python/intern/bpy_rna.c 2009-06-15 08:12:28 UTC (rev 20891)
@@ -1750,7 +1750,24 @@
return (PyObject *)self;
}
+PyObject *BPY_rna_props( void )
+{
+ PyObject *dict = PyDict_New( );
+ PyMethodDef *ml;
+ static PyMethodDef bpy_prop_meths[] = {
+ {"FloatProperty", (PyCFunction)BPy_FloatProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {"StringProperty", (PyCFunction)BPy_StringProperty, METH_VARARGS|METH_KEYWORDS, ""},
+ {NULL, NULL, 0, NULL}
+ };
+
+ for(ml = bpy_prop_meths; ml->ml_name; ml++) {
+ PyDict_SetItemString( dict, ml->ml_name, PyCFunction_New(ml, NULL));
+ }
+ return dict;
+}
/* Orphan functions, not sure where they should go */
More information about the Bf-blender-cvs
mailing list