Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-12-31 13:15:29 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-12-31 13:20:41 +0300
commit0ffc603553bb6a5dd3ce96e88bc9be34356fc0cf (patch)
tree1415890bf433ac933fee88fb80e37c322e26e281 /source/blender
parent16e1bbf1dbbefde14533b0de5b68ae3ac269e05c (diff)
Cleanup: Py API naming
Use BPY_execute_* prefix for all Python execution commands
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/interface/interface.c4
-rw-r--r--source/blender/editors/space_script/script_edit.c4
-rw-r--r--source/blender/editors/space_text/text_ops.c2
-rw-r--r--source/blender/editors/util/numinput.c2
-rw-r--r--source/blender/freestyle/intern/system/PythonInterpreter.h14
-rw-r--r--source/blender/python/BPY_extern.h12
-rw-r--r--source/blender/python/generic/py_capi_utils.c12
-rw-r--r--source/blender/python/generic/py_capi_utils.h2
-rw-r--r--source/blender/python/intern/bpy_interface.c39
-rw-r--r--source/blender/python/intern/bpy_utils_units.c2
-rw-r--r--source/blender/windowmanager/intern/wm_files.c2
11 files changed, 48 insertions, 47 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 79a7f4fc57a..95187bbd005 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2272,7 +2272,7 @@ static bool ui_set_but_string_eval_num_unit(bContext *C, uiBut *but, const char
bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), but->drawstr,
ui_get_but_scale_unit(but, 1.0), but->block->unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type));
- return (BPY_button_exec(C, str_unit_convert, value, true) != -1);
+ return BPY_execute_string_as_number(C, str_unit_convert, value, true);
}
#endif /* WITH_PYTHON */
@@ -2287,7 +2287,7 @@ bool ui_but_string_set_eval_num(bContext *C, uiBut *but, const char *str, double
if (str[0] != '\0') {
bool is_unit_but = (ui_but_is_float(but) && ui_but_is_unit(but));
/* only enable verbose if we won't run again with units */
- if (BPY_button_exec(C, str, value, is_unit_but == false) != -1) {
+ if (BPY_execute_string_as_number(C, str, value, is_unit_but == false)) {
/* if the value parsed ok without unit conversion this button may still need a unit multiplier */
if (is_unit_but) {
char str_new[128];
diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c
index d265ae62db6..6bfb51d07c6 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -59,7 +59,7 @@ static int run_pyfile_exec(bContext *C, wmOperator *op)
char path[512];
RNA_string_get(op->ptr, "filepath", path);
#ifdef WITH_PYTHON
- if (BPY_filepath_exec(C, path, op->reports)) {
+ if (BPY_execute_filepath(C, path, op->reports)) {
ARegion *ar = CTX_wm_region(C);
ED_region_tag_redraw(ar);
return OPERATOR_FINISHED;
@@ -125,7 +125,7 @@ static int script_reload_exec(bContext *C, wmOperator *op)
/* TODO, this crashes on netrender and keying sets, need to look into why
* disable for now unless running in debug mode */
WM_cursor_wait(1);
- BPY_string_exec(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)");
+ BPY_execute_string(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)");
WM_cursor_wait(0);
WM_event_add_notifier(C, NC_WINDOW, NULL);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 948293d150b..4ded3e9be0d 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -598,7 +598,7 @@ static int text_run_script(bContext *C, ReportList *reports)
void *curl_prev = text->curl;
int curc_prev = text->curc;
- if (BPY_text_exec(C, text, reports, !is_live)) {
+ if (BPY_execute_text(C, text, reports, !is_live)) {
if (is_live) {
/* for nice live updates */
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c
index d2bc8bc80c0..9bb4e050ae6 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -496,7 +496,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
n->unit_sys, n->unit_type[idx]);
/* Note: with angles, we always get values as radians here... */
- if (BPY_button_exec(C, str_unit_convert, &val, false) != -1) {
+ if (BPY_execute_string_as_number(C, str_unit_convert, &val, false)) {
n->val[idx] = (float)val;
n->val_flag[idx] &= ~NUM_INVALID;
}
diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h
index ddb79b2df0b..5403ec6b13b 100644
--- a/source/blender/freestyle/intern/system/PythonInterpreter.h
+++ b/source/blender/freestyle/intern/system/PythonInterpreter.h
@@ -78,22 +78,22 @@ public:
BKE_reports_clear(reports);
char *fn = const_cast<char*>(filename.c_str());
#if 0
- int status = BPY_filepath_exec(_context, fn, reports);
+ bool ok = BPY_execute_filepath(_context, fn, reports);
#else
- int status;
+ bool ok;
Text *text = BKE_text_load(&_freestyle_bmain, fn, G.main->name);
if (text) {
- status = BPY_text_exec(_context, text, reports, false);
+ ok = BPY_execute_text(_context, text, reports, false);
BKE_text_unlink(&_freestyle_bmain, text);
BKE_libblock_free(&_freestyle_bmain, text);
}
else {
BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn);
- status = 0;
+ ok = false;
}
#endif
- if (status != 1) {
+ if (ok == false) {
cerr << "\nError executing Python script from PythonInterpreter::interpretFile" << endl;
cerr << "File: " << fn << endl;
cerr << "Errors: " << endl;
@@ -113,7 +113,7 @@ public:
BKE_reports_clear(reports);
- if (BPY_string_exec(_context, str.c_str()) != 0) {
+ if (!BPY_execute_string(_context, str.c_str())) {
BPy_errors_to_report(reports);
cerr << "\nError executing Python script from PythonInterpreter::interpretString" << endl;
cerr << "Name: " << name << endl;
@@ -133,7 +133,7 @@ public:
BKE_reports_clear(reports);
- if (!BPY_text_exec(_context, text, reports, false)) {
+ if (!BPY_execute_text(_context, text, reports, false)) {
cerr << "\nError executing Python script from PythonInterpreter::interpretText" << endl;
cerr << "Name: " << name << endl;
cerr << "Errors: " << endl;
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 815beebb159..d3be59921c0 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -72,10 +72,12 @@ void BPY_thread_restore(BPy_ThreadStatePtr tstate);
#define BPy_BEGIN_ALLOW_THREADS { BPy_ThreadStatePtr _bpy_saved_tstate = BPY_thread_save(); (void)0
#define BPy_END_ALLOW_THREADS BPY_thread_restore(_bpy_saved_tstate); } (void)0
+bool BPY_execute_filepath(struct bContext *C, const char *filepath, struct ReportList *reports);
+bool BPY_execute_text(struct bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump);
+bool BPY_execute_string_as_number(struct bContext *C, const char *expr, double *value, const bool verbose);
+bool BPY_execute_string_ex(struct bContext *C, const char *expr, bool use_eval);
+bool BPY_execute_string(struct bContext *C, const char *expr);
-/* 2.5 UI Scripts */
-int BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports);
-int BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump);
void BPY_text_free_code(struct Text *text);
void BPY_modules_update(struct bContext *C); // XXX - annoying, need this for pointers that get out of date
void BPY_modules_load_user(struct bContext *C);
@@ -85,10 +87,6 @@ void BPY_app_handlers_reset(const short do_all);
void BPY_driver_reset(void);
float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime);
-int BPY_button_exec(struct bContext *C, const char *expr, double *value, const bool verbose);
-int BPY_string_exec_ex(struct bContext *C, const char *expr, bool use_eval);
-int BPY_string_exec(struct bContext *C, const char *expr);
-
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr);
int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result);
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 89c3ed2460e..dd32c913f78 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -971,14 +971,14 @@ PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag)
/**
- * \return -1 on error, else 0
+ * \return success
*
* \note it is caller's responsibility to acquire & release GIL!
*/
-int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename)
+bool PyC_RunString_AsNumber(const char *expr, double *value, const char *filename)
{
PyObject *py_dict, *mod, *retval;
- int error_ret = 0;
+ bool ok = true;
PyObject *main_mod = NULL;
PyC_MainModule_Backup(&main_mod);
@@ -998,7 +998,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
if (retval == NULL) {
- error_ret = -1;
+ ok = false;
}
else {
double val;
@@ -1024,7 +1024,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
Py_DECREF(retval);
if (val == -1 && PyErr_Occurred()) {
- error_ret = -1;
+ ok = false;
}
else if (!finite(val)) {
*value = 0.0;
@@ -1036,7 +1036,7 @@ int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename
PyC_MainModule_Restore(main_mod);
- return error_ret;
+ return ok;
}
#endif /* #ifndef MATH_STANDALONE */
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index 0ebc06ce2fa..a06a717ecbc 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -79,7 +79,7 @@ int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int
int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix);
PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag);
-int PyC_RunString_AsNumber(const char *expr, double *value, const char *filename);
+bool PyC_RunString_AsNumber(const char *expr, double *value, const char *filename);
int PyC_ParseBool(PyObject *o, void *p);
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index d10816b809f..0c3048dd9d6 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -424,8 +424,9 @@ typedef struct {
} PyModuleObject;
#endif
-static int python_script_exec(bContext *C, const char *fn, struct Text *text,
- struct ReportList *reports, const bool do_jump)
+static bool python_script_exec(
+ bContext *C, const char *fn, struct Text *text,
+ struct ReportList *reports, const bool do_jump)
{
Main *bmain_old = CTX_data_main(C);
PyObject *main_mod = NULL;
@@ -543,13 +544,13 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
}
/* Can run a file or text block */
-int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports)
+bool BPY_execute_filepath(bContext *C, const char *filepath, struct ReportList *reports)
{
return python_script_exec(C, filepath, NULL, reports, false);
}
-int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
+bool BPY_execute_text(bContext *C, struct Text *text, struct ReportList *reports, const bool do_jump)
{
return python_script_exec(C, NULL, text, reports, do_jump);
}
@@ -572,24 +573,26 @@ void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr)
PyGILState_Release(gilstate);
}
-/* return -1 on error, else 0 */
-int BPY_button_exec(bContext *C, const char *expr, double *value, const bool verbose)
+/**
+ * \return success
+ */
+bool BPY_execute_string_as_number(bContext *C, const char *expr, double *value, const bool verbose)
{
PyGILState_STATE gilstate;
- int error_ret = 0;
+ bool ok = true;
if (!value || !expr) return -1;
if (expr[0] == '\0') {
*value = 0.0;
- return error_ret;
+ return ok;
}
bpy_context_set(C, &gilstate);
- error_ret = PyC_RunString_AsNumber(expr, value, "<blender button>");
+ ok = PyC_RunString_AsNumber(expr, value, "<blender button>");
- if (error_ret) {
+ if (ok == false) {
if (verbose) {
BPy_errors_to_report_ex(CTX_wm_reports(C), false, false);
}
@@ -600,21 +603,21 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const bool ver
bpy_context_clear(C, &gilstate);
- return error_ret;
+ return ok;
}
-int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
+bool BPY_execute_string_ex(bContext *C, const char *expr, bool use_eval)
{
PyGILState_STATE gilstate;
PyObject *main_mod = NULL;
PyObject *py_dict, *retval;
- int error_ret = 0;
+ bool ok = true;
Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */
if (!expr) return -1;
if (expr[0] == '\0') {
- return error_ret;
+ return ok;
}
bpy_context_set(C, &gilstate);
@@ -631,7 +634,7 @@ int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
bpy_import_main_set(bmain_back);
if (retval == NULL) {
- error_ret = -1;
+ ok = false;
BPy_errors_to_report(CTX_wm_reports(C));
}
@@ -643,12 +646,12 @@ int BPY_string_exec_ex(bContext *C, const char *expr, bool use_eval)
bpy_context_clear(C, &gilstate);
- return error_ret;
+ return ok;
}
-int BPY_string_exec(bContext *C, const char *expr)
+bool BPY_execute_string(bContext *C, const char *expr)
{
- return BPY_string_exec_ex(C, expr, true);
+ return BPY_execute_string_ex(C, expr, true);
}
void BPY_modules_load_user(bContext *C)
diff --git a/source/blender/python/intern/bpy_utils_units.c b/source/blender/python/intern/bpy_utils_units.c
index 057df4ccd41..974d7c5549c 100644
--- a/source/blender/python/intern/bpy_utils_units.c
+++ b/source/blender/python/intern/bpy_utils_units.c
@@ -201,7 +201,7 @@ static PyObject *bpyunits_to_value(PyObject *UNUSED(self), PyObject *args, PyObj
bUnit_ReplaceString(str, (int)str_len, uref, scale, usys, ucat);
- if (PyC_RunString_AsNumber(str, &result, "<bpy_units_api>") != 0) {
+ if (!PyC_RunString_AsNumber(str, &result, "<bpy_units_api>")) {
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 86da2ef32ba..4b7d50fce02 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -458,7 +458,7 @@ static void wm_file_read_post(bContext *C, bool is_startup_file)
/* possible python hasn't been initialized */
if (CTX_py_init_get(C)) {
/* sync addons, these may have changed from the defaults */
- BPY_string_exec(C, "__import__('addon_utils').reset_all()");
+ BPY_execute_string(C, "__import__('addon_utils').reset_all()");
BPY_python_reset(C);
addons_loaded = true;