ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pyxpcom
pyxpcom
Re: [pyxpcom] Python Scripting Component/PyXPCOM InterprocessCommunication
by Ryan Sturmer other posts by this author
Jul 10 2007 4:14PM messages near this date
view in the new Beta List Site
Re: [pyxpcom] Python Scripting Component/PyXPCOM InterprocessCommunication | Re: [pyxpcom] Python Scripting Component/PyXPCOMInterprocessCommunication
Interprocess communication was probably a poor choice of words.  I'll
illustrate with a more specific example, without trying to use

* I have a XUL application, that has a user interface, say, a text box, a
button, and an image.
* At startup, I invoke my specially written pyshell XPCOM object, to which I
may pass user code to be executed in a persistent python environment (ie, I
may pass it code more than once, confident that variables that I set
continue to exist across function calls)  I do this in the usual way, by
consulting the xpcom registry, creating an object in javascript, querying
its interface, etc... getting a few methods (with methods such as
executePythonCode() and attributes such as stdIn, stdOut, stdErr, etc...)  I
hook it up such that you can enter text in the textbox, mash the button, and
the python code gets passed to my pyshell and executed, with the results
returned in the standard io stream attributes.
* Now, in my XUL code, I can access and modify the image in my user
interface (say by pulling one off the web, or on disk, and swapping them
out, etc...) say I even create functions to modify the image.  Let's call
the image an indicator, and I have several javascript functions I can use to
interact with it (say, setIndicatorColor(), setIndicatorBlinkRate(),
etc...)
* This is all pretty straightforward, and I've got it all coded up and it
looks great (Which is quite a feat for me!)

!!! Now, the trick of it is, I want to be able to execute user code, in the
usual way, by allowing the user to enter some python code and mash the
button, only what I'd *really* like to do is have some objects and functions
within the namespace of my little python world, that allow the user (in his
user code) to interact with the user interface that invoked the shell.

Picture having an object within the pyshell environment called
parentUserInterface which has methods such as setIndicatorColor(),
setIndicatorBlinkRate(), etc... allowing my user (equipped with appropriate
documentation regarding what parts of the user interface are scriptable to
write code like this

def alert():
   parentUI.setIndicatorColor(255,0,0)
   parentUI.setIndicatorBlinkRate(10)
   return

and call alert() from within his code, confident that it will in fact effect
the user interface in the way she specifies.

Does this make sense at all?   I'm either horribly misusing the programming
model, or am missing something pretty basic. After playing a bit with XUL,
and finding it could be connected with python, this is the first thing that
I thought of.  We've got an enterprise application we're writing where the
mozilla suite of technologies fits like a glove, but python scriptability is
an absolute must for a variety of reasons.

Thank you for your prompt responses and thorough answers... when I ran
across this mailing list, I thought it was dead, but apparently you guys are
just hiding in the bushes with some of those pits dug with the sharpened
sticks and stuff....

Cheers!

-R
On 7/10/07, Mark Hammond <mhammond@[...].au>  wrote:
> 
>   If you are looking for inter-process communication, then xpcom isn't
>  going to help much.  However, nothing you have said seems to require that -
>  why can't the user scripts execute in the same process, thereby allowing you
>  to just use xpcom the way it was designed for this task?
> 
>  Cheers,
> 
>  Mark
> 
>  -----Original Message-----
>  *From:* pyxpcom-bounces@[...].com [mailto:
>  pyxpcom-bounces@[...].com]*On Behalf Of *Ryan Sturmer
>  *Sent:* Wednesday, 11 July 2007 6:10 AM
>  *To:* pyxpcom@[...].com
>  *Subject:* [pyxpcom] Python Scripting Component/PyXPCOM
>  InterprocessCommunication
> 
>  I'm developing a XULRunner application that's got a python backbone, and
>  part of that backbone is ideally using python itself to expose scriptability
>  to the users.  I have a number of features on the "python side" of the world
>  that need to be scripted, but would also like access to my user interface
>  from the scripting language.
> 
>  Imagine an MVC sort of design where I would like my view (all done in XUL
>  and web technologies) to be updated by my model and controller (python
>  backbone)  Essentially, I'd like to expose some of my user interface
>  functions (displayThis(), changeTheColorOfThat()) as methods of a "user
>  interface object" that's in the local namespace of the users scripting
>  environment.  I've written an nsIPyShell component that lets the user pass
>  commands and code blocks to a persistent python environment, but haven't
>  figured how to expose functions of the calling environment to that
>  namespace. (presumably via an XPCOM object of some variety)  I guess the
>  concept I'm shooting for is a "bidirectional" relationship, where an XPCOM
>  object can exist as a client and server at the same time (both the python
>  code and javascript code can share the same object)
> 
>  I know this is a broad question... I'm not looking for a design solution,
>  but a point in the right direciton or a nod that this is even feasible... it
>  seems like an interprocess communication nightmare, and I wouldn't be
>  surprised by a response to the effect of "XPCOM/PyXPCOM doesn't do that."
> 
>  Thoughts?
> 
>  -R
> 
>  --
>  "The preceding program contained violent scenes of a graphic nature.  Time
>  travelers with nervous dispositions may wish to listen to something else for
>  the past half hour."
>  -John Marsh
>  "The Hitchhikers Guide to the Galaxy"
> 
> 


-- 
"The preceding program contained violent scenes of a graphic nature.  Time
travelers with nervous dispositions may wish to listen to something else for
the past half hour."
-John Marsh
"The Hitchhikers Guide to the Galaxy"


Ryan Sturmer
ryansturmer@[...].com
http://www.gogglemarks.net/
Thread:
Ryan Sturmer
Mark Hammond
Ryan Sturmer
Mark Hammond
Ryan Sturmer
Mark Hammond
Ryan Sturmer
Mark Hammond
Ryan Sturmer

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved