Re: Exposing object model in Python?

Discussion in 'Python' started by MK, Jun 27, 2003.

  1. MK

    MK Guest

    "MK" <> 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.
     
    MK, Jun 27, 2003
    #1
    1. Advertising

  2. MK

    Steve Holden Guest

    "MK" <> wrote in message
    news:bdgvk5$sid7t$...> > [...]
    >
    > 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/
     
    Steve Holden, Jun 27, 2003
    #2
    1. Advertising

  3. 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>
     
    Fredrik Lundh, Jun 27, 2003
    #3
  4. MK

    MK Guest

    "Steve Holden" <> 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.
     
    MK, Jun 27, 2003
    #4
  5. MK

    Brian Kelley Guest

    MK wrote:
    > "MK" <> 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.
     
    Brian Kelley, Jun 27, 2003
    #5
  6. MK

    Steve Holden Guest

    "Fredrik Lundh" <> 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/
     
    Steve Holden, Jun 27, 2003
    #6
  7. 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>
     
    Fredrik Lundh, Jun 27, 2003
    #7
  8. MK

    Robert Kern Guest

    In article <bdgvk5$sid7t$>,
    "MK" <> writes:
    > "MK" <> 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


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
     
    Robert Kern, Jun 27, 2003
    #8
  9. "Fredrik Lundh" <> wrote in message news:<>...
    > 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?
     
    Jason Whitlark, Jul 1, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Graham Fawcett

    Re: Exposing object model in Python?

    Graham Fawcett, Jun 27, 2003, in forum: Python
    Replies:
    0
    Views:
    729
    Graham Fawcett
    Jun 27, 2003
  2. Pedro
    Replies:
    0
    Views:
    813
    Pedro
    Mar 29, 2006
  3. Michael Pradel
    Replies:
    22
    Views:
    962
  4. daokfella
    Replies:
    1
    Views:
    350
    bruce barker
    Aug 8, 2008
  5. Stone Free
    Replies:
    0
    Views:
    345
    Stone Free
    Aug 20, 2009
Loading...

Share This Page