File: PySCLang_Module_GUIStuff.cpp

package info (click to toggle)
supercollider 1%3A3.4.5-1wheezy1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 26,972 kB
  • sloc: cpp: 116,645; lisp: 64,914; ansic: 10,725; python: 3,548; perl: 766; ruby: 487; sh: 152; makefile: 117; xml: 13
file content (124 lines) | stat: -rwxr-xr-x 3,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * File: PYSCLang_Module_GUIStuff.cpp
 * Project : Psycollider
 *
 * by:
 * Benjamin Golinvaux
 * benjamin.golinvaux@euresys.com
 * messenger: bgolinvaux@hotmail.com
 *
 * currently maintained by:
 * Christopher Frauenberger
 * frauenberger@iem.at
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 *  USA
 *
 */

#ifndef SC_WIN32
#include "pycxx/CXX/Objects.hxx"
#include "pycxx/CXX/Extensions.hxx"
#else
#include "stdafx.h"
#endif

#include "PyrPrimitive.h"
#include "PyrObject.h"
#include "PyrKernel.h"
#include "VMGlobals.h"
#include "SC_RGen.h"
#include "GC.h"
#include "PySCLang_Module.h"

int prOpenWinTextFile(struct VMGlobals *g, int numArgsPushed);
int prOpenWinTextFile(struct VMGlobals *g, int numArgsPushed)
{

  if (!g->canCallOS)
    return errCantCallOS;

  PyrSlot *d = g->sp - 3;
	PyrSlot *a = g->sp - 2; // path
	PyrSlot *b = g->sp - 1; // rangeStart
	PyrSlot *c = g->sp;     // rangeSize

  int rangeStart, rangeSize;

  // retrieve path
  if (!(isKindOfSlot(a, class_string)))
    return errWrongType;
  PyrString* string = slotRawString(a);
  if(string->size == 0)
    return errFailed;


  // start char in sel range
  int err = slotIntVal(b, &rangeStart);
  if (err)
    return err;
  // sel range size
  err = slotIntVal(c, &rangeSize);
  if (err)
    return err;

  if( PySCLang_Module::PyPrOpenWinTextFile_s != NULL) {
    // TODO : send text in the scLogSink_
    char* szString = new char[string->size+1];
    memcpy(szString,string->s,string->size);
    szString[string->size] = 0;
   PyObject* pystr = PyString_FromString(szString);
    delete [] szString;
    PyObject* pyRangeStart = PyInt_FromLong(rangeStart);
    PyObject* pyRangeSize = PyInt_FromLong(rangeSize);
    PyObject* tuple = PyTuple_New(3);
    PyTuple_SetItem(tuple,0,pystr);
    PyTuple_SetItem(tuple,1,pyRangeStart);
    PyTuple_SetItem(tuple,2,pyRangeSize);

   /* make the Python call thread safe (global interpreter clock) */
	PyGILState_STATE gstate;
	gstate = PyGILState_Ensure();
	PyObject* result = PyObject_Call(PySCLang_Module::PyPrOpenWinTextFile_s,tuple,NULL);
	PyGILState_Release(gstate);

	result = PyErr_Occurred( );
	if (result) {
		post("logSink call failed, result: %d\n", result);
		return errFailed;
	}
  }
  else { // no log sink callable..
    post("No Python callable bound to PySCLang_Module::PyPrOpenWinTextFile_s with setPyPrOpenWinTextFile\n");
    return errFailed;
  }
  //NSString *nsstring = [NSString stringWithCString: string->s length: string->size];

	//  SetInt(a, result---->window->Id);
	return errNone;
}

void initGUIPrimitives()
{
  int base,index;

	base = nextPrimitiveIndex();
	index = 0;

	definePrimitive(base, index++, "_OpenWinTextFile", prOpenWinTextFile, 3, 0);
}