##// END OF EJS Templates
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ...
This is a manual merge of certain things in the ipython1-dev branch, revision 46, into the main ipython branch. This is not a true merge in the formal sense because all history is not coming over with the files. For a detailed history of the added files, please see the ipython1-dev branch or the svn repository on scipy.org that ipython1-dev came from. More specifically, here is what I have done in this commit: 1) Moved the following by hand ipython1.config -> IPython.config ipython1.kernel -> IPython.kernel ipython1.external -> IPython.external ipython1.core -> IPython.kernel.core ipython1.testutils -> IPython.testing ipython1.tools -> IPython.tools 2) Moved IPython.tools.guid -> IPython1.external.guid 3) Renamed: ipython1 -> IPython IPython.core -> IPython.kernel.core IPython.testutils -> IPython.testing 4) Then did a "bzr add" for all the new stuff. That is all folks!

File last commit:

r680:5a2d2c1b
r1234:52b55407
Show More
ipy_render.py
67 lines | 1.6 KiB | text/x-python | PythonLexer
#!/usr/bin/env python
""" IPython extension: Render templates from variables and paste to clipbard """
import IPython.ipapi
ip = IPython.ipapi.get()
from string import Template
import sys,os
from IPython.Itpl import itplns
def toclip_w32(s):
""" Places contents of s to clipboard
Needs pyvin32 to work:
http://sourceforge.net/projects/pywin32/
"""
import win32clipboard as cl
import win32con
cl.OpenClipboard()
cl.EmptyClipboard()
cl.SetClipboardText( s.replace('\n','\r\n' ))
cl.CloseClipboard()
try:
import win32clipboard
toclip = toclip_w32
except ImportError:
def toclip(s): pass
def render(tmpl):
""" Render a template (Itpl format) from ipython variables
Example:
$ import ipy_render
$ my_name = 'Bob' # %store this for convenience
$ t_submission_form = "Submission report, author: $my_name" # %store also
$ render t_submission_form
=> returns "Submission report, author: Bob" and copies to clipboard on win32
# if template exist as a file, read it. Note: ;f hei vaan => f("hei vaan")
$ ;render c:/templates/greeting.txt
Template examples (Ka-Ping Yee's Itpl library):
Here is a $string.
Here is a $module.member.
Here is an $object.member.
Here is a $functioncall(with, arguments).
Here is an ${arbitrary + expression}.
Here is an $array[3] member.
Here is a $dictionary['member'].
"""
if os.path.isfile(tmpl):
tmpl = open(tmpl).read()
res = itplns(tmpl, ip.user_ns)
toclip(res)
return res
ip.to_user_ns('render')