class library: Reset has been renamed to OnError
[supercollider.git] / bindings / PySCLang / PySCLang_Module_GUIStuff.cpp
blob693629f7f17f30a5f612a745e7d888510c7d0a9a
1 /*
2 * File: PYSCLang_Module_GUIStuff.cpp
3 * Project : Psycollider
5 * by:
6 * Benjamin Golinvaux
7 * benjamin.golinvaux@euresys.com
8 * messenger: bgolinvaux@hotmail.com
10 * currently maintained by:
11 * Christopher Frauenberger
12 * frauenberger@iem.at
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
27 * USA
31 #ifndef SC_WIN32
32 #include "CXX/Objects.hxx"
33 #include "CXX/Extensions.hxx"
34 #else
35 #include "stdafx.h"
36 #endif
38 #include "PyrPrimitive.h"
39 #include "PyrObject.h"
40 #include "PyrKernel.h"
41 #include "VMGlobals.h"
42 #include "SC_RGen.h"
43 #include "GC.h"
44 #include "PySCLang_Module.h"
46 int prOpenWinTextFile(struct VMGlobals *g, int numArgsPushed);
47 int prOpenWinTextFile(struct VMGlobals *g, int numArgsPushed)
50 if (!g->canCallOS)
51 return errCantCallOS;
53 PyrSlot *d = g->sp - 3;
54 PyrSlot *a = g->sp - 2; // path
55 PyrSlot *b = g->sp - 1; // rangeStart
56 PyrSlot *c = g->sp; // rangeSize
58 int rangeStart, rangeSize;
60 // retrieve path
61 if (!(isKindOfSlot(a, class_string)))
62 return errWrongType;
63 PyrString* string = slotRawString(a);
64 if(string->size == 0)
65 return errFailed;
68 // start char in sel range
69 int err = slotIntVal(b, &rangeStart);
70 if (err)
71 return err;
72 // sel range size
73 err = slotIntVal(c, &rangeSize);
74 if (err)
75 return err;
77 if( PySCLang_Module::PyPrOpenWinTextFile_s != NULL) {
78 // TODO : send text in the scLogSink_
79 char* szString = new char[string->size+1];
80 memcpy(szString,string->s,string->size);
81 szString[string->size] = 0;
82 PyObject* pystr = PyString_FromString(szString);
83 delete [] szString;
84 PyObject* pyRangeStart = PyInt_FromLong(rangeStart);
85 PyObject* pyRangeSize = PyInt_FromLong(rangeSize);
86 PyObject* tuple = PyTuple_New(3);
87 PyTuple_SetItem(tuple,0,pystr);
88 PyTuple_SetItem(tuple,1,pyRangeStart);
89 PyTuple_SetItem(tuple,2,pyRangeSize);
91 /* make the Python call thread safe (global interpreter clock) */
92 PyGILState_STATE gstate;
93 gstate = PyGILState_Ensure();
94 PyObject* result = PyObject_Call(PySCLang_Module::PyPrOpenWinTextFile_s,tuple,NULL);
95 PyGILState_Release(gstate);
97 result = PyErr_Occurred( );
98 if (result) {
99 post("logSink call failed, result: %d\n", result);
100 return errFailed;
103 else { // no log sink callable..
104 post("No Python callable bound to PySCLang_Module::PyPrOpenWinTextFile_s with setPyPrOpenWinTextFile\n");
105 return errFailed;
107 //NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
109 // SetInt(a, result---->window->Id);
110 return errNone;
113 void initGUIPrimitives()
115 int base,index;
117 base = nextPrimitiveIndex();
118 index = 0;
120 definePrimitive(base, index++, "_OpenWinTextFile", prOpenWinTextFile, 3, 0);