aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/py
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/py')
-rw-r--r--externals/grill/py/readme.txt1
-rw-r--r--externals/grill/py/source/py.cpp4
-rw-r--r--externals/grill/py/source/pyargs.cpp1
-rw-r--r--externals/grill/py/source/pybase.cpp63
-rw-r--r--externals/grill/py/source/pybase.h2
-rw-r--r--externals/grill/py/source/pyext.cpp4
-rw-r--r--externals/grill/py/source/pyext.h2
-rw-r--r--externals/grill/py/source/pymeth.cpp3
-rw-r--r--externals/grill/py/source/pyprefix.h4
9 files changed, 77 insertions, 7 deletions
diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt
index 0c4bc0f4..da012af9 100644
--- a/externals/grill/py/readme.txt
+++ b/externals/grill/py/readme.txt
@@ -99,6 +99,7 @@ Version history:
- FIX: better exception handling (no longer leaves reference to function object) and cleared misleading error message
- FIX: better definition of output values for atoms, lists and anythings
- FIX: much better detached method handling (one thread for all object instances!)
+- ADD: open module file in editor on "edit" message (or alt-click (PD) or double click (Max))
0.2.0:
- ADD: handling of Python threads
diff --git a/externals/grill/py/source/py.cpp b/externals/grill/py/source/py.cpp
index 4e1057e2..c7111faa 100644
--- a/externals/grill/py/source/py.cpp
+++ b/externals/grill/py/source/py.cpp
@@ -74,6 +74,8 @@ private:
FLEXT_CALLGET_V(mg_dir)
FLEXT_CALLBACK(m_doc)
+ FLEXT_CALLBACK(CbClick)
+
#ifdef FLEXT_THREADS
FLEXT_CALLBACK_T(tick)
#endif
@@ -99,6 +101,8 @@ void pyobj::Setup(t_classid c)
FLEXT_CADDMETHOD_(c,0,"set",m_set);
+ FLEXT_CADDMETHOD_(c,0,"edit",CbClick);
+
FLEXT_CADDATTR_VAR1(c,"py",pymsg);
FLEXT_CADDATTR_VAR1(c,"respond",respond);
}
diff --git a/externals/grill/py/source/pyargs.cpp b/externals/grill/py/source/pyargs.cpp
index 511baf2f..d9a91e10 100644
--- a/externals/grill/py/source/pyargs.cpp
+++ b/externals/grill/py/source/pyargs.cpp
@@ -175,7 +175,6 @@ const t_symbol *pybase::GetPyArgs(AtomList &lst,PyObject *pValue,int offs)
if(pValue == Py_None) return sym_bang;
// analyze return value or tuple
- int rargc = 0;
const t_symbol *sym = NULL;
if(isseq(pValue)) {
diff --git a/externals/grill/py/source/pybase.cpp b/externals/grill/py/source/pybase.cpp
index 2457974f..69bead28 100644
--- a/externals/grill/py/source/pybase.cpp
+++ b/externals/grill/py/source/pybase.cpp
@@ -11,6 +11,12 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "pybase.h"
#include <map>
+#if FLEXT_OS == FLEXT_OS_WIN
+#include <windows.h>
+#elif FLEXT_OS == FLEXT_OS_MAC
+#include <ApplicationServices/ApplicationServices.h>
+#endif
+
static PyMethodDef StdOut_Methods[] =
{
{ "write", pybase::StdOut_Write, 1 },
@@ -295,7 +301,62 @@ void pybase::m__doc(PyObject *obj)
void pybase::OpenEditor()
{
- // this should once open the editor....
+ if(!module) return;
+ const char *mname = PyModule_GetFilename(module);
+ if(!mname) {
+ PyErr_Clear();
+ return;
+ }
+
+ char fname[1024];
+ strcpy(fname,mname);
+
+ // replacing .pyc or .pyo for source file name
+ char *dt = strrchr(fname,'.');
+ if(dt && !strncmp(dt,".py",2)) strcpy(dt,".py");
+
+ // this should open the editor....
+#if FLEXT_OS == FLEXT_OS_WIN
+ int err = (int)ShellExecute(NULL,"edit",fname,NULL,NULL,SW_SHOW);
+ if(err == SE_ERR_NOASSOC) {
+ // no association found - try notepad
+ err = (int)ShellExecute(NULL,NULL,"notepad.exe",fname,NULL,SW_SHOW);
+ }
+ else if(err == ERROR_FILE_NOT_FOUND || err == SE_ERR_FNF)
+ post("py/pyext - File not %s found",fname);
+ else if(err <= 32)
+ post("py/pyext - Unknown error opening %s",fname);
+
+#elif FLEXT_OS == FLEXT_OS_MAC
+ FSRef ref;
+ OSStatus err = FSPathMakeRef(fname,&ref,NULL);
+ if(err)
+ post("py/pyext - Error interpreting path %s",fname);
+ else {
+ FSRef editor;
+ err = LSGetApplicationForItem(&ref,kLSRolesEditor,&editor,NULL);
+ if(err) {
+ // Can't find associated application... try Textedit
+ err = FSPathMakeRef("/Applications/TextEdit.app",&editor,NULL);
+ if(err)
+ post("py/pyext - Can't find Textedit application");
+ }
+
+ if(!err) {
+ LSLaunchFSRefSpec lspec;
+ lspec.appRef = &editor;
+ lspec.numDocs = 1;
+ lspec.itemRefs = &ref;
+ lspec.passThruParams = NULL;
+ lspec.launchFlags = kLSLaunchDefaults;
+ lspec.asyncRefCon = NULL;
+ err = LSOpenFromRefSpec(&lspec,NULL);
+ if(err)
+ post("py/pyext - Couldn't launch editor");
+ }
+ }
+#elif FLEXT_OS == FLEXT_OS_LINUX
+#endif
}
void pybase::SetArgs()
diff --git a/externals/grill/py/source/pybase.h b/externals/grill/py/source/pybase.h
index 0da6d8fa..f0ec5640 100644
--- a/externals/grill/py/source/pybase.h
+++ b/externals/grill/py/source/pybase.h
@@ -124,8 +124,8 @@ protected:
bool respond;
#ifdef FLEXT_THREADS
- bool shouldexit;
int thrcount;
+ bool shouldexit;
int stoptick;
Timer stoptmr;
diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp
index 00ff0cc4..dd4b5a67 100644
--- a/externals/grill/py/source/pyext.cpp
+++ b/externals/grill/py/source/pyext.cpp
@@ -41,6 +41,8 @@ void pyext::Setup(t_classid c)
FLEXT_CADDMETHOD_(c,0,"get",m_get);
FLEXT_CADDMETHOD_(c,0,"set",m_set);
+ FLEXT_CADDMETHOD_(c,0,"edit",CbClick);
+
FLEXT_CADDATTR_VAR1(c,"py",pymsg);
FLEXT_CADDATTR_VAR1(c,"respond",respond);
@@ -99,7 +101,7 @@ void pyext::SetThis()
{
// remember the this pointer
PyObject *th = PyLong_FromVoidPtr(this);
- /*int ret =*/ PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
+ PyObject_SetAttrString(pyobj,"_this",th); // ref is taken
}
void pyext::ClearThis()
diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h
index 3aaf62bf..4a4e79f1 100644
--- a/externals/grill/py/source/pyext.h
+++ b/externals/grill/py/source/pyext.h
@@ -145,6 +145,8 @@ private:
FLEXT_CALLGET_V(mg_dir)
FLEXT_CALLBACK(m_doc)
+ FLEXT_CALLBACK(CbClick)
+
#ifdef FLEXT_THREADS
FLEXT_CALLBACK_T(tick)
#endif
diff --git a/externals/grill/py/source/pymeth.cpp b/externals/grill/py/source/pymeth.cpp
index 177802b7..91ca2146 100644
--- a/externals/grill/py/source/pymeth.cpp
+++ b/externals/grill/py/source/pymeth.cpp
@@ -102,7 +102,6 @@ protected:
virtual void Exit();
virtual bool CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv);
- virtual void CbClick();
void m_help();
@@ -423,8 +422,6 @@ bool pymeth::CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv)
return ret;
}
-void pymeth::CbClick() { pybase::OpenEditor(); }
-
void pymeth::DumpOut(const t_symbol *sym,int argc,const t_atom *argv)
{
ToOutAnything(GetOutAttr(),sym?sym:thisTag(),argc,argv);
diff --git a/externals/grill/py/source/pyprefix.h b/externals/grill/py/source/pyprefix.h
index ac97cbde..de74ca42 100644
--- a/externals/grill/py/source/pyprefix.h
+++ b/externals/grill/py/source/pyprefix.h
@@ -14,6 +14,10 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#define FLEXT_ATTRIBUTES 1
#include <flext.h>
+// hack: must include math.h before Python.h (at least on OSX)
+// otherwise some functions don't get defined
+#include <math.h>
+
#if FLEXT_OS == FLEXT_OS_MAC
#include <Python/Python.h>
#else