×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    2

    Running Python-scripts from Symbian C++ code

    I have trouble running a Python script from Symbian C++ code. Could someone give me an example of this?

    I have tried:

    -using CSPyInterpreter, but the code does not compile/link correctly. I have added some headers to Symbian SDK's include from "C:\Symbian\7.0s\Series60_v20\python-port-s60\symbian_python\Include", but it doesn't seem to work. This lead to missing io.h, which doesn't seem to exist. I'm using MS VC++.

    -using RApaLsSession::StartApp(const CApaCommandLine& aCommandLine), but I don't know what to use in CApaCommandLine::SetDocumentNameL(const TDesC& aDocName). This almost opens the Pyhton script; the title can be seen, but the application does not run. Maybe something to do with ViewUID's, but I haven't found that concept from the documentation.

    If someone has done this, I'll appreciate the help.

    --Marko

  2. #2
    Regular Contributor
    Join Date
    Sep 2003
    Location
    Finland
    Posts
    209

    Re: Running Python-scripts from Symbian C++ code

    Originally posted by markol


    -using CSPyInterpreter, but the code does not compile/link correctly. I have added some headers to Symbian SDK's include from "C:\Symbian\7.0s\Series60_v20\python-port-s60\symbian_python\Include", but it doesn't seem to work. This lead to missing io.h, which doesn't seem to exist. I'm using MS VC++.

    This answer only considers the "CSPyInterpreter"-option:

    1) In ".mmp"-file you have to have line:

    LIBRARY python222.lib

    2) Include:

    #include "CSPyInterpreter.h"

    3) Running a script (you might want to consider wrapping this e.g. with "CAsyncCallBack"):

    CSPyInterpreter* iInterpreter;

    iInterpreter = CSPyInterpreter::NewInterpreterL();

    TBuf8<KMaxFileName> outputBuffer;

    ... outputBuffer is filled with a proper script name, e.g. "default.py" ...

    char *argv[1];
    int argc;
    argv[0] = (char*)outputBuffer.PtrZ();
    argc = 1;

    iInterpreter->RunScript(argc, argv);

    delete iInterpreter;
    iInterpreter = NULL;

    4) If your target is ".exe" you might have to increase the stacksize, for example in ".mmp"-file:

    EPOCSTACKSIZE 65536

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    2
    Thanks, I think this will do the trick.

    It seems, that the CSPyInterpreter is not included in every version of Python for Series60 SDK. My problem is, that I have to use the Symbian 7.0 SDK (and therefore the Python SDK for that). The CSPyInterpreter seems to be included in the Python SDK for Symbian 8.0 (which is Python_1_0_for_Series60_SDK_2nd_ed_FP2).

    My next question is, has anyone lauched Python code using Symbian 7.0 SDK? Adding just the CSPyInterpreter.h to the older environment does not work.

    --Marko

  4. #4
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: Running Python-scripts from Symbian C++ code

    Here is how you can use other Python C API. This works with latest 1.1.6 alpha.

    <code>
    CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
    CleanupStack::PushL(it);
    PyEval_RestoreThread(PYTHON_TLS->thread_state);

    PyRun_SimpleString("open(r'c:\\foo.txt', 'w').write('hello')\n");

    PyEval_SaveThread();
    CleanupStack::PopAndDestroy(it);
    </code>

    One thing that does not seem to work is calls to appuifw module.

  5. #5
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: Running Python-scripts from Symbian C++ code

    Here is how you can print out error messages from Python C API:

    First, define following function:
    int PythonOutput(const char *buf, int n)
    {
    HBufC* buf16 = HBufC::NewLC(n);
    buf16->Des().Copy(TPtrC8((unsigned char*)buf, n));
    RDebug::Print(_L("[PYTHON ERROR]: %S"), buf16);
    CleanupStack::PopAndDestroy();
    return n;
    }


    Then, after interpreter is started, do following:
    CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
    CleanupStack::PushL(it);
    it->iStdO = &PythonOutput;


    Now you can use if (PyErr_Occurred()) { PyErr_Print(); } to find out about errors.
    Last edited by simo.salminen; 2006-08-23 at 15:26.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    6

    Re: Running Python-scripts from Symbian C++ code

    hii,
    I'm new to symbian environment....
    I've a small problem here...

    I'm writing an application which calls for some python functions...

    My Symbian-Python directory is in C:\Symbian\8.0a\S60_2nd_FP2\python-port-s60

    While my app is in
    C:\Symbian\8.0a\S60_2nd_FP2\Series60Ex

    So whn i include Symbian-Python as user include in da mmp file of my application, its taking da address as
    ..\MyApp\group\C:\Symbian\8.0a\S60_2nd_FP2\Series60Ex

    I need some help in this regard...its really urgent...so plz reply if some1 can help me in dis regard....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •