Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Block image now displays image 'title' when collapsed

  • Loading branch information...
commit ac02912ecea6d7f66f3e205d86a05dd8f6449c90 1 parent 9ea3762
R. Saravanan authored
Showing with 7 additions and 6 deletions.
  1. +4 −4 graphterm/bin/gmatplot.py
  2. +3 −2 graphterm/bin/gtermapi.py
View
8 graphterm/bin/gmatplot.py
@@ -11,7 +11,7 @@ def gplot_setup():
import matplotlib
matplotlib.use("Agg")
-def gplot_savefig(format="png", overwrite=False):
+def gplot_savefig(format="png", overwrite=False, title=""):
"""Save figure as a blob and display as block image
"""
import matplotlib.pyplot as plt
@@ -20,7 +20,7 @@ def gplot_savefig(format="png", overwrite=False):
outbuf = gtermapi.BlobStringIO(content_type)
plt.savefig(outbuf, format=format)
blob_url = outbuf.close()
- gtermapi.display_blockimg(blob_url, overwrite=overwrite)
+ gtermapi.display_blockimg(blob_url, overwrite=overwrite, alt=title)
def demo():
"""gterm-aware matplotlib demo"""
@@ -31,12 +31,12 @@ def demo():
fmt = "png" # or "pdf"
plt.plot([1,2,3,2,3,0])
- gplot_savefig(format=fmt)
+ gplot_savefig(format=fmt, title="Simple plot")
time.sleep(2)
plt.plot([1,2,3,2,3,1])
- gplot_savefig(format=fmt)
+ gplot_savefig(format=fmt, title="Simple animation")
n = 20
dx = 5.0/n
View
5 graphterm/bin/gtermapi.py
@@ -97,12 +97,13 @@ def write_blank(display="fullpage"):
"""Write blank pagelet to stdout"""
write_html("", display=display)
-def display_blockimg(url, overwrite=False):
+def display_blockimg(url, overwrite=False, alt=""):
"""Display block image in a sequence.
New image display causes previous images to be hidden.
Display of hidden images can be toggled by clicking.
"""
- IMGFORMAT = '<span class="gterm-blockseqlink"><em>&lt;image&gt;</em></span><img class="gterm-blockimg gterm-blockseqlink" src="%s"></img><br>'
+ alt_attr = ' alt="'+alt+'"' if alt else ''
+ IMGFORMAT = '<span class="gterm-blockseqlink"><em>&lt;'+(alt or 'image')+'&gt;</em></span><img class="gterm-blockimg gterm-blockseqlink" src="%s"'+alt_attr+'><br>'
add_headers={"classes": "gterm-blockseq"}
if overwrite:
add_headers["block"] = "overwrite"
Please sign in to comment.
Something went wrong with that request. Please try again.