State of IPython under PTVS

Aug 6, 2014 at 11:25 AM
Hello PTVS team,

I've been poking around a bit, but couldn't find anything other than copy/paste (albeit using Control-E-E when from clipboard to ipython) for sharing code between ipython and the VS editor tabs. Am I missing something perhaps? For example, is IPython's %edit feature somehow able to open code inside a Visual Studio editor tab? (It's not working for me, but I'm using python 2.6 and a correspondingly old ipython version too but will look at 2.7 and latest ipython soon - if it's working for anyone that'd be great to know).

If there's currently no specific support for %edit, might it be easiest to invoke devenv.exe with arguments that load a file - something like explorer - or would you recommend I try coding something within the ipython repl script? - any hints/thoughts welcome.

Thanks and regards,
Aug 18, 2014 at 5:17 PM
Apologies for the slow reply, we've been heads-down getting the release ready.

We don't make any changes to IPython itself, which is what would be required to handle the %edit command. However, you can edit your file (should be in C:\Users\<username>\.ipython\profile_default) and either set it to devenv.exe or create a script (Python+pywin32) that can use DDE to open the file.

If you look in the registry at HKEY_CLASSES_ROOT\\shell\Open\ddeexec you'll see the application (service), topic and command you need for the PyDDEConv object (from pywin32). I haven't actually tried this myself, so I'll be interested if you have success. I'd try launching devenv directly first - it's possible that it will automatically handle opening in the active window by itself.

Hope that helps. We'll be looking into how we can provide tighter integration with IPython for our next release, so I'll copy this into our issue tracker as a suggestion.
Aug 18, 2014 at 5:17 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 9, 2014 at 5:50 PM
Edited Nov 9, 2014 at 5:54 PM
Similarly, if I wanted interaction between the interactive window in IPython mode and the system clipboard would it be best to go snooping around inside of IPython? At what level are special $ commands handled inside the interactive window? Any thought to having a pytools module that automatically gets imported and can be used by $ commands? Then you could implement send-to-edit-window with $edit instead of %edit, and send-arbitrary-junk-to-clipboard with $clipboard, so I could get what I wanted with $clipboard <matplotlib figure> -> calls pytools.to_clipboard routine that knows how to take a Figure and put its pixel buffer on the clipboard in png data format, and similarly you could implement $edit with an appropriate call to pytools.to_editor. Bonus: opens a possibility for user-scripts inside the REPL implemented through $ commands. The pytools module could just provide basic data back-and-forth routines.
Nov 9, 2014 at 5:55 PM
You know, if I weren't swamped by work and this side-project which has me back inside of pytools at home, that's a feature I could probably do myself.

Well, not really, because I only have VS Pro, so the build chain is probably awful.
Nov 9, 2014 at 6:17 PM
Build chain should be fine with Pro, except I think you have to leave out profiling, but we've made a whole lot of features like that optional since you last worked on the code.

%commands are passed through to IPython unmodified, while $commands are intercepted by the repl window. Interacting with the clipboard is probably easier with an IPython %command and PyWin32, though a $command will be more reliable long term as we separate the IPython backend from the local machine. Either way, it should be possible to add the command without building PTVS again - we pick up repl commands using MEF. I can give you the exact details when I'm back at my desk if you need them.