embedded python in dll with C

2007-07-15 Thread Mick Duprez
Hi All,
I can't quite get my head around embedding Python in a C app and I
have a few questions if I may, here is the background.
I want to create a dll plugin that has the Python interpreter embedded
in it for use in scripting an established application. So far I have
created the interface dll and py module using swig. So far so good,
now some questions -

1) Would it be best to combine my swig generated .c file into the same
dll as my plugin dll or leave it seperate, in other words should I
just embed the interpreter into the C 'plugin' dll and create the
interface module and dll seperately to import into python scripts?

2) Once I have done this would it be appropriate just to use something
like this in my C code -

PyRun_SimpleString("import my_plugin_script");
PyRun_SimpleString("init_func_from_script()");

where 'init_func_from_script' establishes callbacks for C to use from
the script using the new interface module/dll? The C application has
it's own functions for registering callbacks by passing in a list of
the functions, I'm hoping this will work.

I'll give it a go in the mean time, just looking for the right/better
way to do this, thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Python command line error

2007-05-28 Thread Mick Duprez
Hi All,

I've installed Python 2.5 on a number of machines but on one I'm
having problems with the CLI.
If I fire up the 'cmd' dos box and type 'python' I get a line of
gibberish and it locks up the cli, if I run the 'command' dos box I
get a few lines of garbage and it crashes/closes the dos box.

I've tried a re-install, checked my system paths etc but I can't get
it to work, it works ok for running scripts from a dbl click in
explorer for instance and from Idle, I just can't run scripts from the
command line.

I have installed -
xp pro sp2
Python25
wxPython2.8 unicode
PIL
numpy

any clues to what's causing this behavior?
tia,
Mick.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python command line error

2007-05-28 Thread Mick Duprez
On May 29, 11:33 am, Max Erickson <[EMAIL PROTECTED]> wrote:
> Mick Duprez <[EMAIL PROTECTED]> wrote:
> > Hi All,
>
> > I've installed Python 2.5 on a number of machines but on one I'm
> > having problems with the CLI.
> > If I fire up the 'cmd' dos box and type 'python' I get a line of
> > gibberish and it locks up the cli, if I run the 'command' dos box
> > I get a few lines of garbage and it crashes/closes the dos box.
>
> > I've tried a re-install, checked my system paths etc but I can't
> > get it to work, it works ok for running scripts from a dbl click
> > in explorer for instance and from Idle, I just can't run scripts
> > from the command line.
>
> > I have installed -
> > xp pro sp2
> > Python25
> > wxPython2.8 unicode
> > PIL
> > numpy
>
> > any clues to what's causing this behavior?
> > tia,
> > Mick.
>
> What kind of gibberish? Actual garbage characters and the like?
>
> Anyway, maybe try running which; this one should be easy to get
> going:
>
> http://gnuwin32.sourceforge.net/packages/which.htm
>
> But I have never used it, I use the one in this package:
>
> http://unxutils.sourceforge.net/
>
> It expects 'python.exe' or whatever, not just 'python', I would
> expect the gnuwin32 version to behave similarly.
>
> max

Thanks Max, I just worked it out just before I read your post...doh!
I have cygwin on this machine also and the cygwin/bin path was before
the Python25 path so it was playing up, I put the Python25 path before
the cygwin stuff and it's fixed.
It's always something simple!
Cheers,
Mick.

-- 
http://mail.python.org/mailman/listinfo/python-list


Error with Simplemapi.py

2007-08-24 Thread Mick Duprez
On Dec 24 2004, 4:56 pm, [EMAIL PROTECTED] wrote:
> I wish I new why google doesn't show nicely aligned python code when
> you paste the script.
> Anyways, in case this helps someone else you can download the script
> fromhttp://www.kirbyfooty.com/simplemapi.py
>
> Ian

First of all, thanks to all involved, this looks like what I need
without re-inventing the wheel.
Sorry to Ian if he just recieved 2 emails, my bad, I need to learn how
to use this board better!

I have a small problem. I get an error I don't know how to resolve,
any help would be much appreciated.
I'm using Python25 on winXP pro and the script from the link above.
Here's the error -

>>> mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:\dbs.txt')

Traceback (most recent call last):
  File "", line 1, in 
mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:
\dbs.txt')
  File "C:\Python25\mailtest.py", line 135, in SendMail
cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
  File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
return _cast(obj, obj, typ)
ArgumentError: argument 1: : wrong type
>>>

I have had a brief look at the C api for these structs and functions
but I can't resolve it, it is probably something simple.
The piece of code I don't understand though is this -

MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??
rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??

There's some new stuff going on here I don't understand.

thanks for your help,
Mick.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error with Simplemapi.py

2007-08-26 Thread Mick Duprez
On Aug 27, 2:00 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Fri, 24 Aug 2007 04:03:05 -0300, Mick Duprez <[EMAIL PROTECTED]>
> escribi?:
>
> > I have a small problem. I get an error I don't know how to resolve,
> > any help would be much appreciated.
> > I'm using Python25 on winXP pro and the script from the link above.
> > Here's the error -
>
> >>>> mailtest.SendMail('[EMAIL PROTECTED]','test','test
> >>>> string','c:\dbs.txt')
>
> That should be 'c:\\dbs.txt' or r'c:\dbs.txt'
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > mailtest.SendMail('[EMAIL PROTECTED]','test','test string','c:
> > \dbs.txt')
> >   File "C:\Python25\mailtest.py", line 135, in SendMail
> > cast(NULL, lpMapiRecipDesc), RecipCnt, recip,
> >   File "C:\Python25\lib\ctypes\__init__.py", line 478, in cast
> > return _cast(obj, obj, typ)
> > ArgumentError: argument 1: : wrong type
>
> I'm unsure what those cast(NULL, ...) are supposed to do, but they look
> all wrong. NULL, as defined on that script, is *not* a C NULL pointer (use
> None for that).
> (In fact the whole script doesn't look well at all - do you *have* to use
> MAPI? can't use SMTP instead? Even if you must use MAPI, try the pywin32
> package from Mark Hammond, it has MAPI support and a demo script for
> sending mail)
>
> > I have had a brief look at the C api for these structs and functions
> > but I can't resolve it, it is probably something simple.
> > The piece of code I don't understand though is this -
>
> > MapiRecipDesc_A = MapiRecipDesc * len(RecipWork) #size of struct??
>
> This declares a new type, an array of len(RecipWork) items, each of type
> MapiRecipDesc
>
> > rda = MapiRecipDesc_A() # isn't it MapiRecipDesc as declared??
>
> This creates an instance of the above array.
>
> --
> Gabriel Genellina

Thank you very much Gabriel, changing the NULL to None did the trick
(it also helps if I reload the changed module after editing!:( ). Yes
that is an old script and I will look into your suggestions. Basically
I'd just like to use the default mail client (windows or Unix/Linux)
to send simple mail with attachments, this way I can log the
attachments I send to a db for example for document transmittal/
register reports etc.
Thanks also for the code explanations,
Cheers,
Mick.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Error with Simplemapi.py

2007-08-27 Thread Mick Duprez
On Aug 27, 4:46 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 27 Aug 2007 03:05:30 -0300, Mick Duprez <[EMAIL PROTECTED]>
> escribi?:
>
> > Thank you very much Gabriel, changing the NULL to None did the trick
> > (it also helps if I reload the changed module after editing!:( ).
>
> Glad to see it worked.
>
> > Yes
> > that is an old script and I will look into your suggestions. Basically
> > I'd just like to use the default mail client (windows or Unix/Linux)
> > to send simple mail with attachments, this way I can log the
> > attachments I send to a db for example for document transmittal/
> > register reports etc.
>
> Hmmm... altough you may find some MAPI implementation for Linux, it's very
> uncommon; consider using sendmail instead, or ask for an outbound SMTP
> server and use the smtplib module.
>
> --
> Gabriel Genellina

Will do, thanks for your time,
Mick.

-- 
http://mail.python.org/mailman/listinfo/python-list