Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-embree3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-embree3
Commits
7532bc23
Commit
7532bc23
authored
Sep 1, 2010
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
poll function for py api operator access
eg: if bpy.ops.object.mode_set.poll(): ...
parent
4a427fa4
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
release/scripts/modules/bpy/ops.py
+4
-0
4 additions, 0 deletions
release/scripts/modules/bpy/ops.py
source/blender/python/intern/bpy_operator.c
+47
-6
47 additions, 6 deletions
source/blender/python/intern/bpy_operator.c
with
51 additions
and
6 deletions
release/scripts/modules/bpy/ops.py
+
4
−
0
View file @
7532bc23
...
...
@@ -23,6 +23,7 @@ from _bpy import ops as ops_module
# op_add = ops_module.add
op_dir
=
ops_module
.
dir
op_poll
=
ops_module
.
poll
op_call
=
ops_module
.
call
op_as_string
=
ops_module
.
as_string
op_get_rna
=
ops_module
.
get_rna
...
...
@@ -120,6 +121,9 @@ class bpy_ops_submodule_op(object):
self
.
module
=
module
self
.
func
=
func
def
poll
(
self
,
context
=
None
):
return
op_poll
(
self
.
idname_py
(),
context
)
def
idname
(
self
):
# submod.foo -> SUBMOD_OT_foo
return
self
.
module
.
upper
()
+
"
_OT_
"
+
self
.
func
...
...
This diff is collapsed.
Click to expand it.
source/blender/python/intern/bpy_operator.c
+
47
−
6
View file @
7532bc23
...
...
@@ -40,6 +40,45 @@
#include
"MEM_guardedalloc.h"
#include
"BKE_report.h"
static
PyObject
*
pyop_poll
(
PyObject
*
self
,
PyObject
*
args
)
{
wmOperatorType
*
ot
;
char
*
opname
;
PyObject
*
context_dict
=
NULL
;
/* optional args */
PyObject
*
context_dict_back
;
PyObject
*
ret
;
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
bContext
*
C
=
BPy_GetContext
();
if
(
!
PyArg_ParseTuple
(
args
,
"s|O:_bpy.ops.poll"
,
&
opname
,
&
context_dict
))
return
NULL
;
ot
=
WM_operatortype_find
(
opname
,
TRUE
);
if
(
ot
==
NULL
)
{
PyErr_Format
(
PyExc_SystemError
,
"Polling operator
\"
bpy.ops.%s
\"
error, could not be found"
,
opname
);
return
NULL
;
}
if
(
!
PyDict_Check
(
context_dict
))
context_dict
=
NULL
;
context_dict_back
=
CTX_py_dict_get
(
C
);
CTX_py_dict_set
(
C
,
(
void
*
)
context_dict
);
Py_XINCREF
(
context_dict
);
/* so we done loose it */
/* main purpose of thsi function */
ret
=
WM_operator_poll
((
bContext
*
)
C
,
ot
)
?
Py_True
:
Py_False
;
/* restore with original context dict, probably NULL but need this for nested operator calls */
Py_XDECREF
(
context_dict
);
CTX_py_dict_set
(
C
,
(
void
*
)
context_dict_back
);
Py_INCREF
(
ret
);
return
ret
;
}
static
PyObject
*
pyop_call
(
PyObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -252,6 +291,7 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value)
PyObject
*
BPY_operator_module
(
void
)
{
static
PyMethodDef
pyop_poll_meth
=
{
"poll"
,
(
PyCFunction
)
pyop_poll
,
METH_VARARGS
,
NULL
};
static
PyMethodDef
pyop_call_meth
=
{
"call"
,
(
PyCFunction
)
pyop_call
,
METH_VARARGS
,
NULL
};
static
PyMethodDef
pyop_as_string_meth
=
{
"as_string"
,
(
PyCFunction
)
pyop_as_string
,
METH_VARARGS
,
NULL
};
static
PyMethodDef
pyop_dir_meth
=
{
"dir"
,
(
PyCFunction
)
pyop_dir
,
METH_NOARGS
,
NULL
};
...
...
@@ -261,6 +301,7 @@ PyObject *BPY_operator_module( void )
PyObject
*
submodule
=
PyModule_New
(
"_bpy.ops"
);
PyDict_SetItemString
(
PyImport_GetModuleDict
(),
"_bpy.ops"
,
submodule
);
PyModule_AddObject
(
submodule
,
"poll"
,
PyCFunction_New
(
&
pyop_poll_meth
,
NULL
)
);
PyModule_AddObject
(
submodule
,
"call"
,
PyCFunction_New
(
&
pyop_call_meth
,
NULL
)
);
PyModule_AddObject
(
submodule
,
"as_string"
,
PyCFunction_New
(
&
pyop_as_string_meth
,
NULL
)
);
PyModule_AddObject
(
submodule
,
"dir"
,
PyCFunction_New
(
&
pyop_dir_meth
,
NULL
)
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment