[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23852] branches/soc-2008-mxcurioni/source /blender/freestyle/intern: TK's patch to correct the PythonInterpereter
Maxime Curioni
maxime.curioni at gmail.com
Thu Oct 15 05:32:54 CEST 2009
Revision: 23852
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23852
Author: mxcurioni
Date: 2009-10-15 05:32:53 +0200 (Thu, 15 Oct 2009)
Log Message:
-----------
TK's patch to correct the PythonInterpereter
Modified Paths:
--------------
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp 2009-10-15 01:34:29 UTC (rev 23851)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.cpp 2009-10-15 03:32:53 UTC (rev 23852)
@@ -71,7 +71,7 @@
-Controller::Controller()
+Controller::Controller(bContext* C)
{
const string sep(Config::DIR_SEP.c_str());
@@ -108,7 +108,7 @@
_Canvas = new AppCanvas;
- _inter = new PythonInterpreter;
+ _inter = new PythonInterpreter(C);
_EnableQI = true;
_ComputeRidges = true;
_ComputeSteerableViewMap = false;
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h 2009-10-15 01:34:29 UTC (rev 23851)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/application/Controller.h 2009-10-15 03:32:53 UTC (rev 23852)
@@ -66,7 +66,7 @@
class Controller
{
public:
- Controller() ;
+ Controller(bContext* C) ;
~Controller() ;
void setView(AppView *iView);
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp 2009-10-15 01:34:29 UTC (rev 23851)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp 2009-10-15 03:32:53 UTC (rev 23852)
@@ -60,7 +60,7 @@
if( !freestyle_is_initialized ) {
pathconfig = new Config::Path;
- controller = new Controller;
+ controller = new Controller(C);
view = new AppView;
controller->setView(view);
Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h 2009-10-15 01:34:29 UTC (rev 23851)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h 2009-10-15 03:32:53 UTC (rev 23852)
@@ -51,8 +51,9 @@
{
public:
- PythonInterpreter() {
+ PythonInterpreter(bContext* C) {
_language = "Python";
+ _context = C;
//Py_Initialize();
}
@@ -62,16 +63,33 @@
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());
+#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);
- int status = BPY_run_python_script( C, fn, NULL, reports);
+ 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;
cout << "File: " << fn << endl;
@@ -81,12 +99,7 @@
}
// cleaning up
- CTX_free( C );
BKE_reports_clear(reports);
- if ((reports->flag & RPT_FREE) == 0)
- {
- MEM_freeN(reports);
- }
return 0;
}
@@ -110,7 +123,9 @@
private:
- static void initPath(bContext* C) {
+ bContext* _context;
+
+ void initPath() {
if (_initialized)
return;
@@ -129,7 +144,7 @@
}
}
- BPY_run_python_script( C, NULL, text, NULL);
+ BPY_run_python_script(_context, NULL, text, NULL);
// cleaning up
unlink_text(G.main, text);
More information about the Bf-blender-cvs
mailing list