Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Exposing object model in Python?

Reply
Thread Tools

Re: Exposing object model in Python?

 
 
MK
Guest
Posts: n/a
 
      06-27-2003
"MK" <(E-Mail Removed)> wrote

[...]

Thanks for your input. Apologies for not being clear enough.

I'm writing a classical desktop application, using wxPython
and some other libraries. I'm interested to expose its
object model a la Microsoft's VBA. That is, I want to allow
my users to tinker with the app, i.e. write their own macros
in Python in a miniature IDE, within the app. I'd also like to ship
the program as a standalone app, using py2exe.




 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      06-27-2003
"MK" <(E-Mail Removed)> wrote in message
news:bdgvk5$sid7t$(E-Mail Removed)...> > [...]
>
> Thanks for your input. Apologies for not being clear enough.
>
> I'm writing a classical desktop application, using wxPython
> and some other libraries. I'm interested to expose its
> object model a la Microsoft's VBA. That is, I want to allow
> my users to tinker with the app, i.e. write their own macros
> in Python in a miniature IDE, within the app. I'd also like to ship
> the program as a standalone app, using py2exe.
>


If you can get a look at "Python Programming on Win32" by Mark Hammond and
Andy Robinson that will show you a number of ways to do this, including
writing a COM server in Python and providing Python scripting facilities to
your users.

Unfortunately the techniques used are a little too complicated to describe
in a newsgroup posting.

with-apologies-to-pierre-de-fermat-ly y'rs - steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/



 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-27-2003
Steve Holden wrote:

> > I'm writing a classical desktop application, using wxPython
> > and some other libraries. I'm interested to expose its
> > object model a la Microsoft's VBA. That is, I want to allow
> > my users to tinker with the app, i.e. write their own macros
> > in Python in a miniature IDE, within the app. I'd also like to ship
> > the program as a standalone app, using py2exe.


> Unfortunately the techniques used are a little too complicated to describe
> in a newsgroup posting.
>
> with-apologies-to-pierre-de-fermat-ly y'rs - steve


macrosource = getmacro(macroname)
code = compile(macrosource, macroname, "exec")
context = {}
# populate context with fun things
context["app"] = object_representing_my_app
exec code in context

(add exception handling as necessary)

</F>




 
Reply With Quote
 
MK
Guest
Posts: n/a
 
      06-27-2003
"Steve Holden" <(E-Mail Removed)> wrote

> If you can get a look at "Python Programming on Win32" by Mark Hammond and
> Andy Robinson that will show you a number of ways to do this, including
> writing a COM server in Python and providing Python scripting facilities

to
> your users.



Is COM platform-specific? I believe it is, but I may be wrong.
(Anyway I'm sure it's platform specific, no matter what MS says.)
If it is platform-specific, then that's not what I need.
I'd like to expose my object model on every Python-enabled
platform.


 
Reply With Quote
 
Brian Kelley
Guest
Posts: n/a
 
      06-27-2003
MK wrote:
> "MK" <(E-Mail Removed)> wrote
>
> [...]
>
> Thanks for your input. Apologies for not being clear enough.
>
> I'm writing a classical desktop application, using wxPython
> and some other libraries. I'm interested to expose its
> object model a la Microsoft's VBA. That is, I want to allow
> my users to tinker with the app, i.e. write their own macros
> in Python in a miniature IDE, within the app. I'd also like to ship
> the program as a standalone app, using py2exe.


First thing, if you don't have Python Programming on Win32 you need to
purchase it post haste.

Second thing - the problem you are going to find is having COM talk to
the wxPython application. wxPython when run, expects to be the main
thread of execution which means that it is slightly difficult for COM to
start and talk to wxPython. I have "solved" this problem using the
following methodology.

I

COM Server
py2exe wrapped
using windows registry
to keep track of where
GUI executable is
stored.

^
|
| Com Server Starts
| GUI and connects
| through sockets
|
V
II

GUI is Threaded and
periodically checks
for commands on the
socket.

Note that the COM Server blocks when sending commands. This is mainly
since I don't really understand COM threading. This shouldn't be too
much of a problem though.

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      06-27-2003
"Fredrik Lundh" <(E-Mail Removed)> wrote ...
> Steve Holden wrote:
>
> > > I'm writing a classical desktop application, using wxPython
> > > and some other libraries. I'm interested to expose its
> > > object model a la Microsoft's VBA. That is, I want to allow
> > > my users to tinker with the app, i.e. write their own macros
> > > in Python in a miniature IDE, within the app. I'd also like to ship
> > > the program as a standalone app, using py2exe.

>
> > Unfortunately the techniques used are a little too complicated to

describe
> > in a newsgroup posting.
> >
> > with-apologies-to-pierre-de-fermat-ly y'rs - steve

>
> macrosource = getmacro(macroname)
> code = compile(macrosource, macroname, "exec")
> context = {}
> # populate context with fun things
> context["app"] = object_representing_my_app
> exec code in context
>
> (add exception handling as necessary)
>


You just *love* proving me wrong, don't you? Lucky for you I'm wrong so
often.

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/



 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-27-2003
Steve Holden wrote:

> > > Unfortunately the techniques used are a little too complicated to
> > > describe in a newsgroup posting.
> > >
> > > with-apologies-to-pierre-de-fermat-ly y'rs - steve

> >
> > macrosource = getmacro(macroname)
> > code = compile(macrosource, macroname, "exec")
> > context = {}
> > # populate context with fun things
> > context["app"] = object_representing_my_app
> > exec code in context
> >
> > (add exception handling as necessary)

>
> You just *love* proving me wrong, don't you?


Oh, it's just that my news reader has wider margins.

</F>




 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      06-27-2003
In article <bdgvk5$sid7t$(E-Mail Removed)>,
"MK" <(E-Mail Removed)> writes:
> "MK" <(E-Mail Removed)> wrote
>
> [...]
>
> Thanks for your input. Apologies for not being clear enough.
>
> I'm writing a classical desktop application, using wxPython
> and some other libraries. I'm interested to expose its
> object model a la Microsoft's VBA. That is, I want to allow
> my users to tinker with the app, i.e. write their own macros
> in Python in a miniature IDE, within the app. I'd also like to ship
> the program as a standalone app, using py2exe.


Boudewijn Rempt's book _GUI Programming with Python: QT Edition_ has a chapter
(Chapter 20 to be exact) on this. The concepts should transfer over to wxPython
easily.

http://www.opendocs.org/pyqt/

--
Robert Kern
http://www.velocityreviews.com/forums/(E-Mail Removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
Reply With Quote
 
Jason Whitlark
Guest
Posts: n/a
 
      07-01-2003
"Fredrik Lundh" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> macrosource = getmacro(macroname)
> code = compile(macrosource, macroname, "exec")
> context = {}
> # populate context with fun things
> context["app"] = object_representing_my_app
> exec code in context
>
> (add exception handling as necessary)
>
> </F>


Excellent, I was interested in that too.

Ok, here's something similar I've struggled with... How do you
provide a macro recorder? I have some idea how to just play back a
sequence of actions, (just store signals in a list, then fire them in
order), but how do you turn that back into python code, like in Word
VB?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exposing a reduced interface from object returned in dereferencediterator Stone Free C++ 0 08-20-2009 06:51 PM
Storing and Exposing a Complex Object Property In Viewstate daokfella ASP .Net 1 08-08-2008 08:26 PM
Return object without exposing it to delete Michael Pradel C++ 22 01-31-2007 08:27 PM
Convert Java Model to Java Model without XML erinbot@gmail.com Java 1 10-06-2006 09:00 PM
Re: Exposing object model in Python? Graham Fawcett Python 0 06-27-2003 04:13 AM



Advertisments