2 * File: PYSCLang_Module_GUIStuff.cpp
3 * Project : Psycollider
7 * benjamin.golinvaux@euresys.com
8 * messenger: bgolinvaux@hotmail.com
10 * currently maintained by:
11 * Christopher Frauenberger
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
32 #include "CXX/Objects.hxx"
33 #include "CXX/Extensions.hxx"
38 #include "PyrPrimitive.h"
39 #include "PyrObject.h"
40 #include "PyrKernel.h"
41 #include "VMGlobals.h"
44 #include "PySCLang_Module.h"
46 int prOpenWinTextFile(struct VMGlobals
*g
, int numArgsPushed
);
47 int prOpenWinTextFile(struct VMGlobals
*g
, int numArgsPushed
)
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
;
61 if (!(isKindOfSlot(a
, class_string
)))
63 PyrString
* string
= slotRawString(a
);
68 // start char in sel range
69 int err
= slotIntVal(b
, &rangeStart
);
73 err
= slotIntVal(c
, &rangeSize
);
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
);
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( );
99 post("logSink call failed, result: %d\n", result
);
103 else { // no log sink callable..
104 post("No Python callable bound to PySCLang_Module::PyPrOpenWinTextFile_s with setPyPrOpenWinTextFile\n");
107 //NSString *nsstring = [NSString stringWithCString: string->s length: string->size];
109 // SetInt(a, result---->window->Id);
113 void initGUIPrimitives()
117 base
= nextPrimitiveIndex();
120 definePrimitive(base
, index
++, "_OpenWinTextFile", prOpenWinTextFile
, 3, 0);