Commit Graph

68 Commits

Author SHA1 Message Date
bce3f7e019 PyAPI Mathutils Vector callbacks, referencing other PyObjects rather then thin wrapping vectors which is crash prone.
in short, vectors can work as if they are thin wrapped but not crash blender if the original data is removed.

* RNA vector's return Mathutils vector types.
* BGE vectors for GameObject's localPosition, worldPosition, localPosition, localScale, worldScale, localInertia.
* Comment USE_MATHUTILS define to disable returning vectors.

Example...

* 2.49... *
 loc = gameOb.worldPosition
 loc[1] = 0
 gameOb.worldPosition = loc

* With vectors... *
 gameOb.worldPosition[1] = 0


* But this wont crash... *
 loc = gameOb.worldPosition
 gameOb.endObject()
 loc[1] = 0 # will raise an error that the objects removed.

This breaks games which assume return values are lists.

Will add this to eulers, matrix and quaternion types later.
2009-06-22 04:26:48 +00:00
ad07fc19c0 Context
Python dir(context) now gives the items from the data context
too, modified context callbacks to also return a list of items
in the context.
2009-06-20 14:55:28 +00:00
a68ebbbccd RNA Fixes
* Python apis iterator didnt work, for example [f for f in mesh.faces] # failed.
* Python apis collection.items(), collections without names now return (index,value) pairs, better then returning nothing.
* bpy.ui and bpy.props modules were incorrectly named
* Mesh vertex colors red/blue needed to be swapped on getting/setting.
* Mesh vertex colors were not clamped.
2009-06-20 13:53:14 +00:00
7785ead4eb ObColor wasnt converted into an RNA string.
Updated Mathutils.Vector/Euler/Quaternion/Matrix so these are types rather then module methods, each type now has a tp_new function, matching python builtins float/int/str.
Also cleaned up float conversion and arg passing.

Changed buttons_objects.py...
 if ob in groups.objects: # no longer works
 if ob.name in groups.objects: # is the new syntax
...its more dict like and a lot faster (avoids python iterating over each item and comparing each, use a single rna lookup instead).
2009-06-20 02:44:57 +00:00
94dbb3bbdd 2.5 Python
Merging changes made by Arystanbek in the soc-2009-kazanbas branch,
plus some things modified and added by me.

* Operator exec is called execute in python now, due to conflicts
  with python exec keyword.
* Operator invoke/execute now get context argument.
* Fix crash executing operators due to bpy_import_main_set not being
  set with Main pointer.
* The bpy.props module now has the FloatProperty/IntProperty/
  StringProperty/BoolProperty functions to define RNA properties for
  operators.
* Operators now have an __operator__ property to get the actual RNA
  operator pointers, this is only temporary though.
* bpy.ops.add now allows the operator to be already registered, it
  will simply overwrite the existing one.
* Both the ui and io directories are now scanned and run on startup.
2009-06-18 19:51:22 +00:00
4cd24cf058 RNA
Merging changes made by Arystanbek in the soc-2009-kazanbas branch,
plus some things modified and added by me.

* The API files now all in the makesrna module, convention is to
  call them e.g. rna_mesh_api.c for rna_mesh.c. Note for visual
  studio build maintainers, the rna_*_api.c files are compiled as
  part of "makesrna", but do not have rna_*_gen.c generated as part
  of the library. SCons/cmake/make were updated.

* Added function flags FUNC_USE_CONTEXT and FUNC_USE_REPORTS, to
  allow RNA functions to get context and error reporting parameters
  optionally. Renamed FUNC_TYPESTATIC to FUNC_NO_SELF.

* RNA collections now have a pointer to add/remove FunctionRNA's, this
  isn't actually used anywhere yet, purpose is to make an alias
  main.meshes.add() for main.add_mesh() in python.

* Fixes to make autogenerating property set/get for multidimensional
  arrays work, though a 4x4 matrix will be exposed as a length 16
  one dimensional RNA array.

* Functions and properties added:
	* Main.add_mesh()
	* Main.remove_mesh()
	* Object.matrix
	* Object.create_render_mesh()
	* WindowManager.add_fileselect()
2009-06-18 19:48:55 +00:00
51fbc95e8c RNA
* Added icon to property and enum property items. The latter is
  responsible for the large number of files changed.
* For RNA functions, added PROP_RNAPTR flag to ask for a PointerRNA
  as argument instead of a C pointer, instead of doing it implicitly
  with the AnyType type.

* Material: properly wrap diffuse/specular param variables, and
  rename some things for consistency.
* MaterialTextureSlot: added "enabled" property (ma->septex).
* Image: make animated property editable.
* Image Editor: make some things editable, notifiers, respect state.
* Context: fix issue with screen not being set as ID.
2009-06-16 00:52:21 +00:00
e10e1ac04e adding __contains__ to python rna props.
example usage.
 if "Scene" in bpy.data.scenes: print(True)
 
Only works for strings with collection property types.
2009-06-13 08:04:43 +00:00
bb06e311a1 added item_enumO() so python menu items can call enum types with string args.
Example sequencer menu
		self.layout.column()
		self.layout.item_enumO("SEQUENCER_OT_effect_strip_add", property='type', value='ADD', text="Effect Strip (Add)")
2009-06-07 14:53:08 +00:00
673a39dab1 RNA:
* Accept None as NULL pointers through python function calls.
* Added type callback for pointers back, it's useful still in
  some cases. Made Object.data editable using this, the pointer
  type varying based on object type.
* Wrap pin ID pointer in buttons space.
* Added subclasses for text and surface curve ID blocks, to
  organize data better and get proper icons.
* Added RNA_type_to_ID_code and ID_code_to_RNA_type functions.
* Update RNA_access.h with new RNA types.
2009-06-07 13:09:18 +00:00
52d8e64b85 PyRNA
- Support for python to convert a PyObject into a collection (uses a list of dicts - quite verbose :/)
- Operators can now take collection args when called from python.
- Support for printing operators that use collections (macro recording).
- Added RNA_pointer_as_string which prints all pointer prop values as a python dict.

Example that can run in the in test.py (F7 key)
bpy.ops.VIEW3D_OT_select_lasso(path=[{"loc":(0, 0), "time":0}, {"loc":(1000, 0), "time":0}, {"loc":(1000, 1000), "time":0}], type='SELECT')

for some reason lasso locations always print as 0,0. Need to look into why this is.
2009-06-05 12:48:58 +00:00
a843d7e316 Needed to cast to a PyObject* 2009-05-28 10:31:56 +00:00
a804ae7b3f rna_define.c, RNA_def_struct - set the py_type to NULL when making an rna struct based on another.
bpy_util.c, PyObSpit - print refcount with PyObject
2009-05-28 02:03:48 +00:00
c590dd3e8c minor ref-counting changes, means new subclasses will get the correct ref count though there are big problems with this still.
Found that subclassing an RNA struct (without even registering or instancing adds a reference to Py_None).
Unlikely a python bug, tested with py2.6 and 3.1
2009-05-26 06:29:15 +00:00
6d156a1bab Store the context for python in a static variable with assessor functions - BPy_GetContext/BPy_SetContext,
Still not happy with this in the long term but its less problematic then storing the context in pythons namespace which couldn't be set before importing modules.

This might fix a crash quite a few people have reported (but I cant reproduce).
2009-05-25 13:48:44 +00:00
d80911b867 RNA: ID properties were not being shown as RNA properties anymore, fixed.
Python: fix two warnings (initialize to NULL).
2009-05-20 09:17:21 +00:00
a1cc5ef8eb fix for crash drawing the UI, normally this would cause a memory leak but for some reason it crashed with py2.6 and not 3.1. 2009-05-20 05:35:53 +00:00
e948fe3078 - fix for python refcounting crashes, remember PyDict_GetItem and PyDict_GetItemString borrow a ref.
- the namespace dictionary wasn't being de-allocated for each run.
- clear every error after printing it to avoid stale PyObjects hanging about.
2009-04-23 09:15:42 +00:00
d00c3ef2d6 Small changes
- font->blur was uninitialized
- Use Ctrl+Alt+Shift+P to run scripts from the 3d view not Pkey. (still useful for testing)
2009-04-23 05:56:09 +00:00
5146540095 changed some {} to {0}, these were causing errors on msvc. also got rid of some spurious prototypes I forgot to get rid off. 2009-04-19 20:09:31 +00:00
adff6aeb1c RNA: Generic Type Registration
The Python API to define Panels and Operators is based on subclassing,
this makes that system more generic, and based on RNA. Hopefully that
will make it easy to make various parts of Blender more extensible.

* The system simply uses RNA properties and functions and marks them
  with REGISTER to make them part of the type registration process.
  Additionally, the struct must provide a register/unregister callback
  to create/free the PanelType or similar.
* From the python side there were some small changes, mainly that
  registration now goes trough bpy.types.register instead of
  bpy.ui.addPanel.

* Only Panels have been wrapped this way now.  Check rna_ui.c to see
  how this code works. There's still some rough edges and possibilities
  to make it cleaner, though it works without any manual python code.
* Started some docs here:

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/RNATypeRegistration

* Also changed some RNA_property and RNA_struct functions to not
  require a PointerRNA anymore, where they were not required (which
  is actually the cause of most changed files).
2009-04-19 13:37:59 +00:00
82f710fb33 merged pyrna_py_to_param and pyrna_py_to_prop since they are almost the same 2009-04-16 13:21:18 +00:00
3f98b7ac35 Added back importing UI scripts rather then running,
The bug was todo with bpy.data and bpy.types becoming invalid, temporary fix is to re-assign them to the bpy module before running python operators or panels.
will look into a nicer way to get this working.
2009-04-11 16:17:39 +00:00
a406c15d93 Python Api
own error with refcounting and raise an error when bpy.types cant generate a subtype (though it shouldn't happen)
2009-04-11 15:05:42 +00:00
9d922b4c24 Changed the script UI registration to import rather then run each python script,
this means it caches the compiled pyc files after importing fro the first time.

My times for importing 501 buttons_objects.py files were.
- running each as a script 1.9sec
- importing for the first time 1.8sec
- importing a second time (using pyc files) 0.57sec

Also added "bpy" to sys.modules so it can be imported.
2009-04-11 05:46:40 +00:00
9814ea4bcb RNA: python support for REQUIRED flag for function parameters. 2009-04-11 01:45:05 +00:00
46d8c1ebc7 talked to vekoon and he's ok about using pythons CFunction rather then our own pytype.
If printing PyTypes becomes important we can do it a different way which is still less then 10 lines.
2009-04-09 17:31:23 +00:00
bca1ca9d1e Added rna functions so they get included in a dir(rna_struct) from python.
Added a check that a panel panel is a subclass of bpy.types.Panel (need a better way to access this type)
2009-04-09 16:52:18 +00:00
9196d88242 Experimental removal of pyrna_func_Type (ifdef'd out)
Since adding a new type gives quite a lot of extra boiler plate functions.

Return PyCFunction's main disadvantage is it does not have a uniqie name when you print it.
2009-04-09 13:20:48 +00:00
0482325805 RNA: fix for compile error on msvc, and a warning fix. 2009-04-07 15:20:12 +00:00
767db1b716 RNA: Commit of the API patch by vekoon. This adds Functions to RNA,
which can be defined to call C functions with defined parameters.

* Parameters are RNA properties, with the same types.
* Parameters are stored in a ParameterList, which is like a small
  stack with the values. This is then used to call the C function.
* Includes Python integration.

* Only one test function is part of this commit, ID.rename.
* Integration with the editors/ module is not included in this
  commit, there's some issues to be worked out for that still.
2009-04-07 00:49:39 +00:00
3224efc384 Python Panels WIP
- Register python panels
- Added a generic class checking function BPY_class_validate() for panels/operators.
- No button drawing yet

Brecht, Added RNA_enum_value_from_id() and RNA_enum_id_from_value() to rna_access.c to do lookups between identifiers and values of EnumPropertyItem's, Not sure if these should go here.
2009-04-01 12:43:07 +00:00
b450313b8d - python api was returning incorrect int values from rna because it was using PyLong_FromSize_t rather than PyLong_FromSsize_t, this messed up the default values in documentation.
- renamed POSE_OT_select_hierarchy "add_to_sel" property to "extend"
- some property names were wrong (giving errors in the console at startup)
2009-03-29 04:34:20 +00:00
e04b27ca42 Python
* Add support for setting RNA pointers.
* Fix __repr__ for structs and properties, it was printing
  a garbage string here, but not sure I did what was intended.
2009-03-23 13:28:42 +00:00
935f10dc45 get rid of warnings, fix for a refcount error 2009-03-21 16:03:26 +00:00
6ab2d7ad65 - lazy subtype initialization rna, was initializing every type in bpy.types at startup, which is slow and doesn't allow access to dynamically added types.
- bpy.types isnt a module anymore, defined as its own PyType, getattr looks up the rna collection each time.
- refcounting fixes
- fixe epydoc generation with undefined values
2009-03-21 06:55:30 +00:00
bcddeaa699 2.5 compiles again with scons. Commented out some lines referring to code in the missing file rna_context.c 2009-03-20 03:32:56 +00:00
1b94cb752c Context
* Made it based on string lookups rather than fixed enum, to make
  it extensible by python scripts.
* Context callbacks now also have to specify RNA type when returning
  pointers or collections. For non-RNA wrapped data, UnknownType can
  be used.
* RNA wrapped context. The WM entries are fixed, for data context
  only main and scene are defined properties. Other data entries have
  to be dynamically looked up.
* I've added some special code in python for the dynamic context
  lookups. Tried to hide it behind RNA but didn't find a clean way to
  do it yet. Still unused/untested.

* Also minor fix for warning about propertional edit property in
  transform code, and fix for usage of operator poll with checking if
  it was NULL.
2009-03-19 19:03:38 +00:00
3aab50f775 * removed warnings and fixed some python refcount errors
* operator class names
- Changed 'name' to '__label__' (since __name__ is already used for the class name)
- Changed 'properties' to '__props__'

* added a PyObject_GetAttrStringArgs(), utility function which Id like to see in pythons C api.
PyObject_GetAttrStringArgs(pyob, "someattr", "foo", "bar") /* pyob.someattr.foo.bar */
2009-03-18 22:22:58 +00:00
16fe92f868 2.5 PyAPI
Support for subclassing blenders operator, to be registered as a new operator.

Still need to... 
* add constants like Operator.FINISHED
* wrap context (with rna?)
* poll() cant work right now because there is no way to access the operatorType that holds the python class.
* Only float, int and bool properties can be added so far.

working example operator.
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/WinterCamp/TechnicalDesign#Operator_Example_Code
2009-03-16 15:54:43 +00:00
d297058910 return operators as a PyCFunction rather then having our own callable operator type 2009-03-14 13:43:30 +00:00
a4793a3b4a 2.5 Python api
- rearranged modules bpyui -> bpy.ui, bpy -> bpy.data, remove bpydoc
- new module bpy.types, stores a list of all struct types
- added __rna__ attribute to types - eg bpy.types.World.__rna__ so you can access the rna data from a type. (so bpydoc.structs isnt needed anymore)
- removed unused subtyping method (use python subclassing rather then C PyTypeObject)
2009-03-13 07:50:07 +00:00
64512d3e8e WIP PyAPI from winter camp discussions, make subtypes of the base RNA python type, eventually allowing us to have python defined RNA classes in
python - lux/pov/renderman materials, lamps etc as well as operators.

At the moment there are 2 ways to do this, The first is like subclassing from python, another (disabled) method copies the base PyTypeObject struct 
and makes some changes.

The PyType is stored in the RNA Struct for reuse, right now there are no access functions - needs to be improved.

Added a python script for printing all blend file data to the console which helps testing the api.

dir(rna) wont work for python 2.x now, use rna.__dir__() instead.
2009-03-11 17:28:37 +00:00
63456cefda added python api function to register an operator into a keymap
example...
bpyui.registerKey( C, bpyui.spaceTypes.SEQ, 0, "Sequencer", "SEQUENCER_OT_view_selected",  bpyui.keyTypes.A, bpyui.keyValTypes.PRESS, 0,0, {})
May want to split this into multiple functions.
2009-03-07 09:46:33 +00:00
c3df168539 PyRNA API: some RNA types were crashing on looping, also return None rather then an RNA struct when the ptr->data is NULL 2009-03-05 16:24:30 +00:00
a7c4009267 Make RNA an Operator dir() work in py 2.5 - 3.0
removed epy docstrings from RNA python api, since Python can get this info from rna. (could be redone in python if getting doc's on RNA is needed)
epy_doc_gen works again
2009-03-05 12:09:30 +00:00
Nathan Letwory
0229621b51 2.5 / PyRNA
* a collection of small changes after review together with Campbell.
2009-03-05 08:53:29 +00:00
b49b02842a update to build with python 3.0.1 which removed Py_InitModule3, added richcompare functions to the operator api. 2009-02-26 05:50:19 +00:00
284db61572 RNA: C API
* RNA_blender.h is now generated along with the other files. It is not
  used anywhere yet, and still located quite hidden next to the other
  rna_*_gen.c files. Read only access for now.
* Inherited properties are not copied from the base anymore but
  iterated over. Patch by Vekoon, thanks!
* Array get/set callbacks now do the whole array instead of getting an
  index. This is needed for some layers for example so python can set
  the array as a whole, otherwise the check that one layer has to be
  enabled at all times gets in the way. Also nicer for the C API.
* Also some changes to returning pointers to make the API cleaner, got
  rid of the type() callback and instead let get() return PointerRNA
  with the type included.

The C API looks like this currently:
http://users.pandora.be/blendix/RNA_blender.h
2009-02-02 19:57:57 +00:00
ca36e04362 python3 couldn't generate epydocs because python3 needs richcompare functions for C defined PyTypes (it seems). 2009-01-29 09:38:52 +00:00