diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2009-10-15 07:32:53 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2009-10-15 07:32:53 +0400 |
commit | dc81204c91aac5ffe5c81051a905afca4aca14d4 (patch) | |
tree | 829b5a59a809b47eccb44ecb30f0c23c6008da26 /source/blender/freestyle/intern | |
parent | 986db26d48a1d30ef9ea53f5da70fab03da6aa68 (diff) |
TK's patch to correct the PythonInterpereter
Diffstat (limited to 'source/blender/freestyle/intern')
4 files changed, 34 insertions, 19 deletions
diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index 89c0bde2cf5..6b7f095c6ac 100755 --- a/source/blender/freestyle/intern/application/Controller.cpp +++ b/source/blender/freestyle/intern/application/Controller.cpp @@ -71,7 +71,7 @@ extern "C" { -Controller::Controller() +Controller::Controller(bContext* C) { const string sep(Config::DIR_SEP.c_str()); @@ -108,7 +108,7 @@ Controller::Controller() _Canvas = new AppCanvas; - _inter = new PythonInterpreter; + _inter = new PythonInterpreter(C); _EnableQI = true; _ComputeRidges = true; _ComputeSteerableViewMap = false; diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h index 46d08d0c686..99d85434811 100755 --- a/source/blender/freestyle/intern/application/Controller.h +++ b/source/blender/freestyle/intern/application/Controller.h @@ -66,7 +66,7 @@ extern "C" { class Controller { public: - Controller() ; + Controller(bContext* C) ; ~Controller() ; void setView(AppView *iView); diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp index 6346c05b0d6..48cecd1ab4f 100644 --- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp +++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp @@ -60,7 +60,7 @@ extern "C" { if( !freestyle_is_initialized ) { pathconfig = new Config::Path; - controller = new Controller; + controller = new Controller(C); view = new AppView; controller->setView(view); diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h index 810825e68cf..314b91228ce 100755 --- a/source/blender/freestyle/intern/system/PythonInterpreter.h +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -51,8 +51,9 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter { public: - PythonInterpreter() { + PythonInterpreter(bContext* C) { _language = "Python"; + _context = C; //Py_Initialize(); } @@ -62,15 +63,32 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter int interpretFile(const string& filename) { - bContext* C = CTX_create(); - ReportList* reports = (ReportList*) MEM_mallocN(sizeof(ReportList), "freestyleExecutionReportList"); + initPath(); - initPath(C); - - BKE_reports_init(reports, RPT_ERROR); + ReportList* reports = CTX_wm_reports(_context); + BKE_reports_clear(reports); char *fn = const_cast<char*>(filename.c_str()); - - int status = BPY_run_python_script( C, fn, NULL, reports); +#if 0 + int status = BPY_run_python_script(_context, fn, NULL, reports); +#else + int status; + FILE *fp = fopen(fn, "r"); + if (fp) { + struct Text *text = add_empty_text("tmp_freestyle.txt"); + char buf[256]; + while (fgets(buf, sizeof(buf), fp) != NULL) + txt_insert_buf(text, buf); + fclose(fp); + + status = BPY_run_python_script(_context, NULL, text, reports); + + unlink_text(G.main, text); + free_libblock(&G.main->text, text); + } else { + BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn); + status = 0; + } +#endif if (status != 1) { cout << "\nError executing Python script from PythonInterpreter::interpretFile" << endl; @@ -81,12 +99,7 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter } // cleaning up - CTX_free( C ); BKE_reports_clear(reports); - if ((reports->flag & RPT_FREE) == 0) - { - MEM_freeN(reports); - } return 0; } @@ -110,7 +123,9 @@ class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter private: - static void initPath(bContext* C) { + bContext* _context; + + void initPath() { if (_initialized) return; @@ -129,7 +144,7 @@ private: } } - BPY_run_python_script( C, NULL, text, NULL); + BPY_run_python_script(_context, NULL, text, NULL); // cleaning up unlink_text(G.main, text); |