About Embedding PyWin or wxPython

M

Mr. Roboto

Folks: I want to embark on a project to add Python (actually, wxPython
or PythonWin) to a new Windows app I want to start writing soon.
Essentially, I want to take VB6 (or pos Delphi) and construct the app
framework/core functionality using one of those languages, then extend
the app w/ Python, the same way one can extend the MS Office apps
using VBA. The core Python docs provide the fundamental info one
needs to get started. But, I've been looking for some pointers to
articles/web pages that will bootstrap the effort, so I won't have to
completely reinvent the wheel. So far, the c.l.p ngroup traffic (and
the web in general) that speaks to this subject is apparently pretty
sparse. Since I'm a one-man show, it would be helpful if anyone could
offer pointers to sites/pages/books that address some of these issues:

1) To COM or not ? From an implementation standpoint, it seems
worthwhile to build the host app as a series of COM objects, which
could then be ref'd/manipulated via external Python code. Not sure if
this makes sense from a performance-perspective, but I doubt the apps
I'm thinking about (mostly desk accessory utils kinda, sorta) are
going to be compute-intensive at all.

2) SWIG or not ? Have never used it, but know that SWIG has been
ref'd many times in the ngroup as an tool for facilitating the use of
Python as an embedded language. Is SWIG worth the effort for a
relatively small (<10 KLOC) app ?

3) Handling exceptions. I want to start from Day One with a sensible
approach to debugging and testing both host objects and external
scripts.

4) Deployment. Size (30 - 50MB for wxPython or PyWin alone) and a
silent install of either pkg prior to installing the host app.

Regardless of the conversation in this group, I plan to get started in
the next few days. This is how I'm currently looking at the above
issues:

1) COM: Yes, since COM seems like an easy fit w/o writing lotsa
glue code because of built-in support via PyWin

2) SWIG: Not for a 1st cut, at least not to get one's feet wet, so
to speak

3) Exceptions: No clue. Need to closely read Extending/Embedding
Python for more guidance

4) Deployment: Bite the disk space bullet and use PyWin or wxPython as
is

Anyway, that's the beginning of the conversation. If you have any
observations or suggestions, please feel free. Later...MR
 
S

Steve Holden

Mr. Roboto said:
Folks: I want to embark on a project to add Python (actually, wxPython
or PythonWin) to a new Windows app I want to start writing soon.
Essentially, I want to take VB6 (or pos Delphi) and construct the app
framework/core functionality using one of those languages, then extend
the app w/ Python, the same way one can extend the MS Office apps
using VBA. The core Python docs provide the fundamental info one
needs to get started. But, I've been looking for some pointers to
articles/web pages that will bootstrap the effort, so I won't have to
completely reinvent the wheel. So far, the c.l.p ngroup traffic (and
the web in general) that speaks to this subject is apparently pretty
sparse. Since I'm a one-man show, it would be helpful if anyone could
offer pointers to sites/pages/books that address some of these issues:
You almost certainly would regard a copy of Hammind and Robinson's
"Python Programming on Win32" as remarkable value for money. It's an
axcellent book, and even has examples fo how you can make a VBA
application scriptable in Python.

If you are more interested in developing functionality that
experimenting, buying that book would save to a huge amount of time.

regards
Steve
 
S

Simon Hibbs

Have you considered IronPython?

This is of course only an option if you're prepared to code in VB.NET
or C# instead of VB6 or Delphi, but it would provide seamless
integratioon between your Python code and the rest of your app and
would not require an external graphics library - although you would
need to distribute the .NET and IronPython runtimes.

Multiple-language and library integration is after all what .NET is all
about.


Simon Hibbs
 
M

Mr. Roboto

Steve: Thanx for reminding me. I have that book around here
*someplace*. Never finished it, but will dig it out pronto. As you
so aptly point out, I want to develop more than experiment and who
better to learn from than the author of PyWin itself....
 
M

Mr. Roboto

Simon: Good idea, but I'm not yet .NET-compatible and can't handle
that learning curve in addition to everything else. IronPython is an
option I hadn't considered, but yours is a good idea for the next
project....
 
P

Philippe Martin

Mr. Roboto said:
Folks: I want to embark on a project to add Python (actually, wxPython
or PythonWin) to a new Windows app I want to start writing soon.
Essentially, I want to take VB6 (or pos Delphi) and construct the app
framework/core functionality using one of those languages, then extend
the app w/ Python, the same way one can extend the MS Office apps
using VBA. The core Python docs provide the fundamental info one
needs to get started. But, I've been looking for some pointers to
articles/web pages that will bootstrap the effort, so I won't have to
completely reinvent the wheel. So far, the c.l.p ngroup traffic (and
the web in general) that speaks to this subject is apparently pretty
sparse. Since I'm a one-man show, it would be helpful if anyone could
offer pointers to sites/pages/books that address some of these issues:

1) To COM or not ? From an implementation standpoint, it seems
worthwhile to build the host app as a series of COM objects, which
could then be ref'd/manipulated via external Python code. Not sure if
this makes sense from a performance-perspective, but I doubt the apps
I'm thinking about (mostly desk accessory utils kinda, sorta) are
going to be compute-intensive at all.

2) SWIG or not ? Have never used it, but know that SWIG has been
ref'd many times in the ngroup as an tool for facilitating the use of
Python as an embedded language. Is SWIG worth the effort for a
relatively small (<10 KLOC) app ?

3) Handling exceptions. I want to start from Day One with a sensible
approach to debugging and testing both host objects and external
scripts.

4) Deployment. Size (30 - 50MB for wxPython or PyWin alone) and a
silent install of either pkg prior to installing the host app.

Regardless of the conversation in this group, I plan to get started in
the next few days. This is how I'm currently looking at the above
issues:

1) COM: Yes, since COM seems like an easy fit w/o writing lotsa
glue code because of built-in support via PyWin

2) SWIG: Not for a 1st cut, at least not to get one's feet wet, so
to speak

3) Exceptions: No clue. Need to closely read Extending/Embedding
Python for more guidance

4) Deployment: Bite the disk space bullet and use PyWin or wxPython as
is

Anyway, that's the beginning of the conversation. If you have any
observations or suggestions, please feel free. Later...MR


Do you have major performances issues ? why not write everything in
Python/WxPython ?


I used to write my applications in VB6 with python com objects ... and
decided there was no gain there.

Regards,

Philippe
 
M

Mr. Roboto

Phillipe: Actually, it's not performance of the core app that concerns
me. I'm thinking more about UI/form *design* productivity. I've done
a lot of Access work over the years and while the stand-alone VB form
designer isn't quite as thorough, it's still one of the slickest out
there. Unfortunately, there's no designer for PyWin and wxPython's
XRC is nice but not in the same league as what can be done w/ Delphi
or VB. Yes, I'm aware that wxWidgets has a real form designer, but
that's yet another story, for another day.

Making XRC into a more fully-featured tool (more on par w/ the
aforementioned) is a way nice project unto itself, but not right now.
However, the desk accessory I've mentioned is an excellent 1st step
towards *possibly* doing something much bigger....
 
P

Philippe Martin

Mr. Roboto said:
Phillipe: Actually, it's not performance of the core app that concerns
me. I'm thinking more about UI/form *design* productivity. I've done
a lot of Access work over the years and while the stand-alone VB form
designer isn't quite as thorough, it's still one of the slickest out
there. Unfortunately, there's no designer for PyWin and wxPython's
XRC is nice but not in the same league as what can be done w/ Delphi
or VB. Yes, I'm aware that wxWidgets has a real form designer, but
that's yet another story, for another day.

Making XRC into a more fully-featured tool (more on par w/ the
aforementioned) is a way nice project unto itself, but not right now.
However, the desk accessory I've mentioned is an excellent 1st step
towards *possibly* doing something much bigger....

I personally _really_ like wxDesigner (http://www.roebling.de/) and as
under VB6, I always avoided having the tables filled for me (bound forms if
I recall) I have not found my productivity go down ... but then again, I
never was a VB expert.

1)
As others have said, it is very easy to make a Python com object (thank you
Mark!) - and as long as Windows keeps supporting COM ....

2)
I chose the COM option

3)
If your script does not handle exceptions, you'll have a fairly cryptic VB
dialog box telling you about your python com object unhapiness - I find it
more easy to handle the expections in the script

4)
Yes it takes space - I have an application that uses Python, wxPython,
Gadfly, pyserial, HTMLGen ..... and the whole thing takes 120M

I used visual studio to buld a single install for everything- works well.


The one open issue I have about wxPython in a com object is how the main
event loop (in your core application) will react if a com object with GUI
pops-up ... never tried it.

Regards,

Philippe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,049
Members
48,769
Latest member
Clifft

Latest Threads

Top