success!!!  sorta....

thanks for the info, chris, you put me on the right track.  i started  
looking into this more thoroughly and i was able to launch an  
interactive ipython terminal from within maya.  there are a few issues  
still to resolve, but the potential is very clearly there.  it has  
popup completion of attributes, tab completion of paths, documentation  
prompting, syntax hilighting, plus all the other goodies of ipython.

here's how i got it working on osx.  should not be too much of a leap  
for other platforms. i installed to my maya python directory, but  
you're welcome to install wherever you like, just make sure everything  
is on your PYTHONPATH.


1) install ez_install :
        download 
http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install
        then run:
        sudo mayapy ez_setup.py

2) install ipython 0.9.1 :      
        sudo mayapy /Applications/Autodesk/maya2008/Maya.app/Contents/ 
Frameworks/Python.framework/Versions/Current/bin/easy_install ipython

3) install wxPython
        download the proper binary (be sure to use unicode): 
http://wxpython.org/download.php#binaries
        run the installer
        on osx it installs to /usr/local/ and places a file called  
wxredirect.pth in your default python site-packages directory
        copy wxredirect.pth from your system python site-packages directory  
to your maya site-packages directory:

        cp /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ 
site-packages/wxredirect.pth /Applications/Autodesk/maya2008/Maya.app/ 
Contents/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site- 
packages/

4) open maya.  on osx i had to do this from a terminal because it  
seems that sys.args was getting polluted when using the dock.
run the following in maya:

import sys
import maya.utils
#sys.stdin.write = lambda self, data:  
maya.utils.executeInMainThreadWithResult(data)
sys.stdin.write = lambda self, data: maya.utils.executeDeferred(data)
sys.stdin.flush = lambda self: None
from IPython.frontend.wx import ipythonx
ipythonx.main()

this should launch an ipython interpreter within maya.  i found that  
executeDeferred was more stable than executeInMainThreadWithResult , i  
guess because it does not need to wait for a result.

if you get an error like:
# Maya: error: no such option: -p
it has something to do with the options used when launching maya  
polluting sys.args, which is being parsed by the wx ipython widget. as  
i mentioned, i got around it for the moment by launching from a  
terminal instead of  from the dock.

there are still some serious issues to resolve:
- in order to safely close the terminal without crashing maya, you  
must first end your session by typing quit() or pressing ctrl-d. after  
which you can close the window
- here's the biggie:  after closing the terminal maya does not seem to  
be get the main thread back?  new windows cannot be opened.
- the pymel tab completers are broken by default, but i've made a lot  
of progress fixing the ipython code that's breaking them.  once i get  
it all sorted out i'll post some bugs to the ipython bug tracker.


so, the main problem now is figuring out how to get maya back to a  
usable state after the terminal is closed....  any thoughts?


-chad



On Sep 16, 2008, at 7:39 PM, Chris G wrote:

> Looking at the IPython code, I think someone would have to re-write  
> substitute IOTerm with something that could read and write to maya,  
> maybe through cmdScrollFieldExecuter/Reporter or using  
> executeInMainThreadWithResult.
>
>
> On Tue, Sep 16, 2008 at 6:43 PM, chadrik <[EMAIL PROTECTED]> wrote:
> jelle,
> i'm looking to get an interactive ipython session running in a GUI  
> Maya.  maya has a customized stdin so that it does not have a write  
> method
>
> import IPython
> # Error: StandardInput instance has no attribute 'write'
> # Traceback (most recent call last):
> #   File "<maya console>", line 1, in <module>
> #   File "/Applications/Autodesk/maya2008/Maya.app/Contents/ 
> Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 
> ipython-0.9.1-py2.5.egg/IPython/__init__.py", line 58, in <module>
> #     __import__(name,glob,loc,[])
> #   File "/Applications/Autodesk/maya2008/Maya.app/Contents/ 
> Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 
> ipython-0.9.1-py2.5.egg/IPython/ipstruct.py", line 22, in <module>
> #     from IPython.genutils import list2dict2
> #   File "/Applications/Autodesk/maya2008/Maya.app/Contents/ 
> Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 
> ipython-0.9.1-py2.5.egg/IPython/genutils.py", line 118, in <module>
> #     Term = IOTerm()
> #   File "/Applications/Autodesk/maya2008/Maya.app/Contents/ 
> Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 
> ipython-0.9.1-py2.5.egg/IPython/genutils.py", line 113, in __init__
> #     self.cin  = IOStream(cin,sys.stdin)
> #   File "/Applications/Autodesk/maya2008/Maya.app/Contents/ 
> Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 
> ipython-0.9.1-py2.5.egg/IPython/genutils.py", line 81, in __init__
> #     self._swrite = stream.write
> # AttributeError: StandardInput instance has no attribute 'write' #
>
> i can run ipythonx from commandline just fine, but i'd really like  
> to get this running inside a maya gui.
>
> the contents of ipythonx are:
>
> import sys
> from pkg_resources import load_entry_point
>
> sys.exit(
>    load_entry_point('ipython==0.9.1', 'console_scripts', 'ipythonx')()
> )
>
>
> if i run the above code in maya i end up with the same error with  
> stdin.
>
> -chad
>
> On Sep 16, 2008, at 2:28 PM, Jelle Feringa wrote:
>
>>
>>> is it technically feasible to connect an
>>> interactive python terminal to the active python session inside of
>>> maya?
>>
>> It is, and if you run "sudo easy_install -U ipython" you'll upgrade  
>> to
>> ipython 0.91 and you'll be able to run ipythonx, ipython in a WX  
>> shell
>>
>>
>
>
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to