Commit Graph

2888 Commits

Author SHA1 Message Date
Campbell Barton
094f7235bb Cleanup: replace own Py_INCREF_RET with CPython's Py_NewRef
These are both simple functions that serve the same purpose.
Py_NewRef didn't exist when Py_INCREF_RET was added to Blender.
2024-10-12 00:20:55 +11:00
nutti
933fb1978f PyAPI: correct types in doc-strings
Ref !116245
2024-10-09 15:45:23 +11:00
Bastien Montagne
76e7770bc9 Python API: Add link/append pre/post handlers.
The `pre` handler is called after blender internal code is done populating
the link/append context with data to be processed, and before this data
starts being linked from library files.

The `post` handler is called after blender is done linking, and
potentailly appending and/or instantiating, the requested data and all
of their dependencies.

Both handlers are called with a single argument, the link/append
context.

An new RNA sets of wrappers have been added to expose relevant info from
these internal C++ structures.

NOTE: !113658 is very similar (but tied to asset drag & drop), whereas
this PR is more general (these could probably live hand-in-hand / side-
by-side).

Implements #122357

Pull Request: https://projects.blender.org/blender/blender/pulls/128279

-----------------

Some quick py example  code:

```python
import bpy

def my_handler_pre(lapp_context):
    print("About to {}:\n\t".format("link" if "LINK" in lapp_context.options else "append"),
          "\n\t".join("{} '{}', from libs ['{}']".format(item.id_type, item.name,
                                                         "', '".join([l.filepath for l in item.source_libraries]))
                      for item in lapp_context.import_items))

def my_handler_post(lapp_context):
    print("{}:\n\t".format("Linked" if "LINK" in lapp_context.options else "Appended"),
          "\n\t".join("{} '{}', from lib '{}'".format(item.id.id_type, item.id.name, item.source_library.filepath)
                      for item in lapp_context.import_items))

bpy.app.handlers.link_append_pre.append(my_handler_pre)
bpy.app.handlers.link_append_post.append(my_handler_post)
```
2024-10-02 16:44:38 +02:00
Campbell Barton
c6fd26a3f5 Cleanup: spelling in comments 2024-10-01 09:59:33 +10:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Bastien Montagne
22477956e2 Refactor: Move BPY main/public extern headers to proper C++ ones.
Pull Request: https://projects.blender.org/blender/blender/pulls/128081
2024-09-25 18:04:33 +02:00
Bastien Montagne
6c0c53161e Refactor: Move BPY bmesh headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
c3247aa4f0 Refactor: Move BPY generic headers to proper C++ ones.
NOTE: `bgl.h` was left unchanged, as it is deprecated code anyway, and
its conversion to C++ does not seem immediately trivial.
2024-09-25 18:04:27 +02:00
Bastien Montagne
4fac7828e4 Refactor: Move BPY mathutils headers to proper C++ ones.
This module actually was confusing, since only a few headers were
effectively still C ones (using the `extern "C"` blocks)...
2024-09-25 18:04:27 +02:00
Bastien Montagne
4dd11465bc Refactor: Move BPY intern remaining headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
198a1ec7a9 Refactor: Move BPY intern bpy_app headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Bastien Montagne
91e4bcd204 Refactor: Move BPY intern bpy_rna headers to proper C++ ones. 2024-09-25 18:04:27 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Campbell Barton
9e68066a4d Logging: suppress "Info" prints when calling bpy.ops.* in quiet mode 2024-09-19 14:49:05 +10:00
Campbell Barton
9b39b4c91c Cleanup: use const pointers/references 2024-09-15 23:14:09 +10:00
Campbell Barton
6a1bd2ff40 Cleanup: use C++ comments for disabled code 2024-09-14 12:35:00 +10:00
Campbell Barton
c6afb0e270 Core: remove sdlew/WITH_SDL_DYNLOAD & disable SDL by default
Disable dynamic SDL loading as well as disable SDL for release builds.

This was only used for audio output which can already use OpenAL
if there are back-ends not natively supported by Blender.

- Remove extern/sdlew/
- Remove the WITH_SDL_DYNLOAD build option.
- Remove `bpy.app.sdl.available`.

Ref !127554
2024-09-13 22:44:35 +10:00
Campbell Barton
11187aa9dc CMake: don't link sdlew when WITH_SDL=OFF
This caused a build error building Blender as a Python module
with !125556 applied.
2024-09-06 21:01:36 +10:00
Campbell Barton
43f7b50df3 Fix #127127: bpy.types sometimes reference their parent's "bl_rna"
Accessing `bl_rna` for type defined in `scripts/modules/bpy_types.py`
could return their parent-classes RNA when accessed via their parent
types __subclasses__() method.
2024-09-06 14:57:26 +10:00
Campbell Barton
1235404cfe Fix #127165: crash accessing cls.bl_rna after unregistering 2024-09-05 17:56:56 +10:00
Campbell Barton
d19c13eb82 Cleanup: spelling & punctuation in comments 2024-09-03 12:59:37 +10:00
Campbell Barton
21b820cd33 Fix the type value of 'bpy.types.*.bl_rna'
The type of an RNA types "bl_rna" should be `bpy.types.Struct`,
it was being set to the type it represented so:
`type(bpy.types.Object.bl_rna) == bpy.types.Object`
which wasn't correct.

Ref !126877

Co-authored-by: Bastien Montagne <bastien@blender.org>
2024-08-28 19:07:14 +10:00
Campbell Barton
83ffadb248 Cleanup: reduce right-shift 2024-08-28 16:30:57 +10:00
Campbell Barton
b30bbcb17d Cleanup: remove duplicate function call & null check 2024-08-28 15:42:13 +10:00
Lleu Yang
166c921a44 UI: Add Frequency unit
This adds the unit of frequency Hertz (Hz) and Kilohertz (kHz) for
expressing pitch of a sound.

This will be used for the ongoing Sample Sound node in #122228.

Pull Request: https://projects.blender.org/blender/blender/pulls/125915
2024-08-22 17:05:48 +02:00
Bastien Montagne
2853a4c4db Refactor: Blendfile Link/Append: make callback of foreach item a function ref. 2024-08-20 12:51:47 +02:00
Lukas Tönne
400c738db9 GPv3: Import and export for SVG and PDF
Implements the SVG import/export and PDF export operators for GPv3.

Pull Request: https://projects.blender.org/blender/blender/pulls/123996
2024-08-20 11:41:37 +02:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Campbell Barton
976062c771 Cleanup: use prefix comments before struct members 2024-08-19 11:37:20 +10:00
Campbell Barton
b5e0b59736 Cleanup: remove space around identifiers in C-style comments 2024-08-15 20:46:00 +10:00
Jacques Lucke
5861b078f7 Core: rename ID.flag and ID.tag values
Previously, values for `ID.flag` and `ID.tag` used the prefixes `LIB_` and
`LIB_TAG` respectively. This was somewhat confusing because it's not really
related to libraries in general. This patch changes the prefix to `ID_FLAG_` and
`ID_TAG_`. This makes it more obvious what they correspond to, simplifying code.

Pull Request: https://projects.blender.org/blender/blender/pulls/125811
2024-08-07 12:12:17 +02:00
nutti
1c3a2d1f5f Fix: temp_override doc not to take the positional arguments
Add positional argument to `temp_override` pyapi docs

Pull Request: https://projects.blender.org/blender/blender/pulls/125132
2024-08-05 13:28:25 +02:00
Campbell Barton
14b03fca3c PyAPI: add bpy.app.python_args, use when calling Python from Blender
Expose arguments to use when creating a Python sub-process.

Python could fail to start when loaded in a customized environment,
with PYTHONPATH set for e.g. Blender ignores these and loads but a
Python sub-process attempts to use these environment variables which
may point to incompatible Python versions.

Resolve the root cause of #124731.
2024-07-31 11:59:23 +10:00
Falk David
cd577f02b9 Python: Trigger property update in foreach_get/set
Calling `foreach_get/set` on a collection property did not trigger
a property update. In the attribute API, this lead to missing
updates after e.g. setting the values of an attribute.

This adds a call to `RNA_property_update` for the getter/setter
bpy rna function and adds a property update callback to all the
different attribute collection properties.

Pull Request: https://projects.blender.org/blender/blender/pulls/125518
2024-07-29 11:14:20 +02:00
Campbell Barton
111a40239a Cleanup: match argument names for function & declarations
Match function and declaration names, picking names based on
consistency with related code & clarity.

Also changes for old conventions, missed in previous cleanups:

- name -> filepath
- tname -> newname
- maxlen -> maxncpy
2024-07-27 13:32:51 +10:00
Christoph Lendenfeld
ebd123c90b Refactor: delete_keyframe function arguments
No functional changes intended.

This simplifies the arguments for the `delete_keyframe` function.
The `bAction *` was always a `nullptr` so I just removed it.
The rna path char array and the array index were merged into the `RNAPath` struct.

Pull Request: https://projects.blender.org/blender/blender/pulls/125479
2024-07-26 13:29:25 +02:00
Campbell Barton
e2bc41598d Fix drivers showing "Python restricted for security" when they weren't
Regression from [0], drivers were tagged as being disabled with a flag
that was never cleared. Causing the label to be displayed for files
where the expressions were enabled and in use.

Resolve by clearing this flag on file load and when re-compiling
expressions - since an expressions block flag may be cleared if it
becomes a simple expression.

[0]: 1a8053939b
2024-07-22 10:39:50 +10:00
Andrej730
627bd7e51c Fix: API docs: bpy.app.timers function argument types
Fixed the "function" argument types of `is_registered` and `unregistered`
to be consistent with the correct typing from `bpy.app.timers.register`

Pull Request: https://projects.blender.org/blender/blender/pulls/125052
2024-07-20 14:52:37 +02:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
Campbell Barton
8fcd1812b4 Merge branch 'blender-v4.2-release' 2024-07-15 11:07:54 +10:00
Nathan Burnham
988bf2b88f Fix incorrect exception message on collection key type error
String keys aren't supported.

Ref: !123577
2024-07-15 11:07:27 +10:00
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Christoph Lendenfeld
1a8053939b Fix #106372: Wrong message in driver for disabled execution
When using a python expression, its execution is disabled by
default unless specified differently in the user preferences.
Previously this only produced the error
"Error: Invalid Python expression". However that isn't really the correct error.

Now the error reads "Python restricted for security".

I've added a new flag to the driver `DRIVER_FLAG_PYTHON_BLOCKED` that is set
if the driver can't run because python is blocked

Co-authored by Phillip Oeser

Pull Request: https://projects.blender.org/blender/blender/pulls/124587
2024-07-12 12:37:15 +02:00
Bastien Montagne
57e9abb564 Cleanup: Remove left-over call to BKE_blendfile_write_partial_end.
BPY `library.write` has been moved to new PartialWriteContext code a few
weeks ago, removing this call to `BKE_blendfile_write_partial_end` was
somehow missed then.
2024-07-09 15:27:12 +02:00
Campbell Barton
bf68ce401d Merge branch 'blender-v4.2-release' 2024-07-09 13:47:12 +10:00
nutti
5523662414 Docs: add default parameters to Context.temp_override
Ref: !124348
2024-07-09 13:44:09 +10:00
Campbell Barton
48383cf20e Cleanup: avoid shadowing, redundant assignment & minor changes
Quiet cppecheck warnings, use const pointers, ELEM(..) macro,
replace NULL -> nullptr, unsigned int -> uint.
2024-07-07 00:18:00 +10:00
Bastien Montagne
96198e88e1 Refactor: BPY: make 'libraries.write' code use the new PartialWriteContext class.
This makes code behind the `bpy.data.libraries.write()` API use the new
`PartialWriteContext` class, instead of the old
`BKE_blendfile_write_partial` API.

NOTE: This also means that the `blendfile_io` tests using this python
API are now using the new class.

No behavioral changes are expected here.

Pull Request: https://projects.blender.org/blender/blender/pulls/122118
2024-07-01 15:28:15 +02:00
Nathan Vegdahl
38f889d07a Fix #123538: Crossfade sounds sets volume to 0
The issue was that the Python keyframing code was already resolving the
RNA path fully to the owning ID, but then erroneously passing the
non-ID RNA pointer (in this case the sound sequence pointer) to the
keyframing code with that fully resolved path.

Notably, it wasn't just the VSE keyframing that was broken: keying any
non-ID structs via the Python API was broken. A good example is pose
bones: the Python keyframing code was resolving e.g. "location" on
the bone to "pose.bones["Bone"].location", but then passing that
path along with the pose bone struct to the keyframing code.  Since
that fully resolved path of course doesn't exist on the bone itself,
keying would fail.

This fixes it by simply passing the owning ID's RNA pointer instead,
which it should have been doing in the first place.

Pull Request: https://projects.blender.org/blender/blender/pulls/123719
2024-06-25 14:16:55 +02:00
Lukas Stockner
25d4d645cd UI: Add Color Temperature unit
The current temperature unit adjusts to Celsius or Fahrenheit based on
unit system, but specifically for color temperatures the convention is
to display them in Kelvin, and it'd be strange to e.g. see 11240°F when
opening the white balance panel.

Therefore, this adds a dedicated Color Temperature unit, and uses it
for the two existing blackbody temperature inputs in shader nodes.

Pull Request: https://projects.blender.org/blender/blender/pulls/123337
2024-06-17 23:50:05 +02:00