Hi Sage Devel,
Have you ever wanted to make it so a particular Sage notebook cell
would automatically get re-evaluated every few seconds? For example,
maybe you want to monitor some file somewhere, make a counter, watch a
stock price, etc. Here's a little function that illustrates how to do
this to make a clock:
def clock(delay=1):
import time; print time.asctime()
sleep(delay)
id = sage.server.notebook.interact.SAGE_CELL_ID
html("<script>evaluate_cell(%s,0)</script>"%id)
The magic is in the last two lines. The id line figures out the id of
the current cell. The line after that calls a javascript function
that is the same javascript function called when you press shift-enter
or click eval on a cell.
You could even do
clock(5)
in one cell and clock(3) in another to get multiple clocks at the same time.
NOTE: the cursor will jump around a bit -- I haven't sorted that out,
and maybe will need to add something to the notebook javascript to fix
that. The above requires no change to Sage.
Oh, here is a stock example, which is boring on the weekend:
def stock(symbol, delay=1):
print finance.Stock(symbol)
sleep(delay)
id = sage.server.notebook.interact.SAGE_CELL_ID
html("<script>evaluate_cell(%s,0)</script>"%id)
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---