Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Split the JS functions into logical groupings, fix some more bugs

  • Loading branch information...
commit 990adfc2b50c009f31a6d2fa483eccc89810d068 1 parent 6f1c4f5
@jamesgao authored
View
14 IPython/frontend/html/css/defaults.css
@@ -0,0 +1,14 @@
+body { font-family:sans-serif; font-size:10pt;}
+pre, p { margin:0px; }
+.cblue { color: blue }
+.ccyan { color: teal }
+.cgreen { color: green }
+.cyellow { color: yellow }
+.cred { color: red }
+.cbold { font-weight:bold }
+.hidden { display:none; }
+.clear { clear:both; }
+
+.headers { font-size:60%;}
+.xreq { font-style:italic }
+
View
50 IPython/frontend/html/css/notebook.css
@@ -0,0 +1,50 @@
+#sidebar { float:right; width:20%; }
+#statusbar { margin:5px; }
+#statusbar span { vertical-align:middle; }
+#statusbar .bullet {
+ font-size:150%;
+ margin-left:10px;
+ float:right;
+}
+#messages {
+ width:80%;
+ float:left;
+}
+.active {
+ border-color:#090;
+}
+.message {
+ padding:3px;
+ border:1px solid #CCC;
+ margin:5px;
+}
+.message:hover {
+ border:1px solid red;
+ cursor:pointer;
+}
+.message .input_header {
+ color:blue;
+ float:left;
+ width:10%;
+}
+.message .input {
+ float:left;
+ width:90%;
+}
+.message .output_header {
+ color:red;
+ float:left;
+ width:10%;
+}
+.message .output {
+ float:left;
+ width:90%;
+}
+
+.inlinesvg { width:432pt; height:288pt; }
+
+pre.input input {
+ width:100%;
+ border:none;
+ padding:0px;
+}
View
86 IPython/frontend/html/js/communicate.js
@@ -0,0 +1,86 @@
+function CometGetter() {
+ this.start()
+ this.request()
+}
+CometGetter.prototype.request = function () {
+ var thisObj = this
+ $.ajax({
+ success: function (json, status, request) {
+ thisObj.complete(json, status, request)
+ }
+ })
+}
+CometGetter.prototype.complete = function(json, status, request) {
+ this.request()
+ this.process(json)
+}
+CometGetter.prototype.process = function (json) {
+ var thisObj = this
+ if (json.msg_type == "status") {
+ statusbar.set(json.content.execution_state)
+ } else if (this.pause) {
+ setTimeout(function () { thisObj.process(json) }, 10)
+ } else {
+ var msg = manager.get(
+ json.parent_header.msg_id,
+ json.parent_header.session)
+ if (json.msg_type == "stream") {
+ msg.setOutput(fixConsole(json.content.data))
+ } else if (json.msg_type == "pyin") {
+ if (json.parent_header.session != session)
+ msg.setInput(fixConsole(json.content.code))
+ } else if (json.msg_type == "pyout") {
+ exec_count = json.content.execution_count
+ msg.num = json.content.execution_count
+ msg.setOutput(fixConsole(json.content.data), true)
+ } else if (json.msg_type == "pyerr") {
+ msg.setOutput(fixConsole(json.content.traceback.join("\n")))
+ }
+ }
+}
+CometGetter.prototype.start = function () {
+ this.pause = false
+}
+CometGetter.prototype.stop = function () {
+ this.pause = true
+}
+
+function heartbeat() {
+ $.ajax({
+ type: "POST",
+ data: {client_id:client_id, type:"heartbeat"},
+ success: function() {
+ setTimeout(heartbeat, 60000)
+ }
+ })
+}
+
+function execute(code, postfunc) {
+ $.ajax({
+ type: "POST",
+ data: {type:"execute", code:code},
+ success: function(json, status, request) {
+ if (json != null) {
+ exec_count = json.content.execution_count
+ if (typeof(postfunc) != "undefined")
+ postfunc(json)
+ if (json.content.payload.length > 0 &&
+ json.content.payload[0]['format'] == "svg") {
+ var svg = document.createElement('object')
+ svg.setAttribute('class', "inlinesvg")
+ svg.setAttribute('type', 'image/svg+xml')
+ svg.setAttribute('data', 'data:image/svg+xml,'+
+ json.content.payload[0]['data'])
+ manager.get(json.parent_header.msg_id).setOutput(svg)
+ manager.get(json.parent_header.msg_id).setOutput("<br />")
+ }
+ //Open a new input object
+ manager.get().activate()
+ }
+ }
+ })
+}
+
+function complete() {
+
+}
View
5 IPython/frontend/html/js/jquery-fieldselection.pack.js
@@ -0,0 +1,5 @@
+/*
+ * jQuery plugin: fieldSelection - v0.1.0 - last change: 2006-12-16
+ * (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
+ */
+(function(){var c={getSelection:function(){var e=this.jquery?this[0]:this;return(('selectionStart'in e&&function(){var l=e.selectionEnd-e.selectionStart;return{start:e.selectionStart,end:e.selectionEnd,length:l,text:e.value.substr(e.selectionStart,l)}})||(document.selection&&function(){e.focus();var r=document.selection.createRange();if(r==null){return{start:0,end:e.value.length,length:0}}var a=e.createTextRange();var b=a.duplicate();a.moveToBookmark(r.getBookmark());b.setEndPoint('EndToStart',a);return{start:b.text.length,end:b.text.length+r.text.length,length:r.text.length,text:r.text}})||function(){return{start:0,end:e.value.length,length:0}})()},replaceSelection:function(){var e=this.jquery?this[0]:this;var a=arguments[0]||'';return(('selectionStart'in e&&function(){e.value=e.value.substr(0,e.selectionStart)+a+e.value.substr(e.selectionEnd,e.value.length);return this})||(document.selection&&function(){e.focus();document.selection.createRange().text=a;return this})||function(){e.value+=a;return this})()}};jQuery.each(c,function(i){jQuery.fn[i]=this})})();
View
11 IPython/frontend/html/js/jquery.scrollTo-1.4.2-min.js
@@ -0,0 +1,11 @@
+/**
+ * jQuery.ScrollTo - Easy element scrolling using jQuery.
+ * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 5/25/2009
+ * @author Ariel Flesler
+ * @version 1.4.2
+ *
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
+ */
+;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
View
273 IPython/frontend/html/js/notebook.js
@@ -1,3 +1,25 @@
+$.ajaxSetup({
+ url: client_id,
+ dataType: "json"
+})
+$(document).ready(function() {
+ comet = new CometGetter()
+ heartbeat()
+ manager = new Manager("messages")
+ //Startup POST, set some globals
+ $.ajax({
+ type: "POST",
+ data: {type:"connect"},
+ success: function(json, status, request) {
+ username = json.parent_header.username
+ session = json.header.session
+ exec_count = json.content.execution_count
+ manager.get().activate()
+ }
+ })
+ statusbar = new StatusBar("statusbar")
+})
+
function fixConsole(txt) {
//Fixes escaped console commands, IE colors. Turns them into HTML
//Unfortunately, the "semantics" of html and console are very
@@ -7,12 +29,13 @@ function fixConsole(txt) {
var re = /\033\[([\d;]+?)m/
var opened = false
while (re.test(txt)) {
- var cmds = re.exec(txt)[1].split(";")
- var close = opened?"</span>":""
- opened = cmds[0] == "0"?false:true
+ var cmds = txt.match(re)[1].split(";")
+ opened = cmds[0] != "0"
+ var close = opened?"":"</span>"
var rep = []
for (var i in cmds)
- rep.push(attrib[cmds[i]])
+ if (typeof(attrib[cmds[i]]) != "undefined")
+ rep.push(attrib[cmds[i]])
var open = rep.length > 0?"<span class=\""+rep.join(" ")+"\">":""
txt = txt.replace(re, close + open)
}
@@ -20,84 +43,6 @@ function fixConsole(txt) {
return txt
}
-function CometGetter() {
- this.start()
- this.request()
-}
-CometGetter.prototype.request = function () {
- var thisObj = this
- $.ajax({
- success: function (json, status, request) {
- thisObj.complete(json, status, request)
- }
- })
-}
-CometGetter.prototype.complete = function(json, status, request) {
- this.request()
-//$("#messages").append("<pre class='headers'>"+json.msg_type+": "+inspect(json.header)+inspect(json.parent_header)+"</pre>")
- this.process(json)
-}
-CometGetter.prototype.process = function (json) {
- var thisObj = this
- if (json.msg_type == "status") {
- statusbar.set(json.content.execution_state)
- } else if (this.pause) {
- setTimeout(function () { thisObj.process(json) }, 10)
- } else {
- var msg = manager.get(json.parent_header.msg_id, json.parent_header.session)
- if (json.msg_type == "stream") {
- msg.setOutput(fixConsole(json.content.data))
- } else if (json.msg_type == "pyin") {
- if (json.parent_header.session != session)
- msg.setInput(fixConsole(json.content.code))
- } else if (json.msg_type == "pyout") {
- msg.setOutput(fixConsole(json.content.data), true)
- } else if (json.msg_type == "pyerr") {
- msg.setOutput(fixConsole(json.content.traceback.join("\n")))
- }
- }
-}
-CometGetter.prototype.start = function () {
- this.pause = false
-}
-CometGetter.prototype.stop = function () {
- this.pause = true
-}
-
-function heartbeat() {
- $.ajax({
- type: "POST",
- data: {client_id:client_id, type:"heartbeat"},
- success: function() {
- setTimeout(heartbeat, 10000)
- }
- })
-}
-function execute(code, postfunc) {
- $.ajax({
- type: "POST",
- data: {type:"execute", code:code},
- success: function(json, status, request) {
- if (json != null) {
- exec_count = json.content.execution_count
- if (typeof(postfunc) != "undefined")
- postfunc(json)
- if (json.content.payload.length > 0 &&
- json.content.payload[0]['format'] == "svg") {
- var svg = document.createElement('object')
- svg.setAttribute('class', "inlinesvg")
- svg.setAttribute('type', 'image/svg+xml')
- svg.setAttribute('data', 'data:image/svg+xml,'+
- json.content.payload[0]['data'])
- manager.get(json.parent_header.msg_id).setOutput(svg)
- manager.get(json.parent_header.msg_id).setOutput("<br />")
- }
- //Open a new input object
- manager.get().activate()
- }
- }
- })
-}
function inspect(obj) {
if (obj instanceof Object) {
var str = []
@@ -112,167 +57,3 @@ function inspect(obj) {
return ""
}
}
-
-function StatusBar(obj) {
- $("#"+obj).append("<span class='txt'></span>")
- $("#"+obj).append("<span class='bullet'>&#8226;</span>")
- this.text = $("#"+obj+" .txt")
- this.bullet = $("#"+obj+" .bullet")
-}
-StatusBar.prototype.map = { "idle":"cgreen", "busy":"cyellow", "dead":"cred" }
-StatusBar.prototype.set = function(status) {
- this.bullet.removeClass()
- this.bullet.addClass("bullet "+this.map[status])
- this.text.text(status)
-}
-
-
-function Manager(obj) {
- this.messages = {}
- this.ordering = []
- this.obj = "#"+obj
- this.ondeck = null
- this.cursor = 0
- var thisObj = this
- $(document).click(function() {
- thisObj.deactivate(thisObj.ondeck)
- })
-}
-Manager.prototype.get = function (msg_id, sess) {
- if (typeof(msg_id) == "undefined") {
- if (this.ondeck == null) {
- this.ondeck = new Message(-1, this.obj)
- this.cursor += 1
- }
- return this.ondeck
- } else if (msg_id[0] == "+" || msg_id[0] == "-") {
- var idx = parseInt(msg_id)
- if (this.cursor + idx <= this.ordering.length &&
- this.cursor + idx >= 0)
- this.cursor += idx
- return this.ordering[this.ondeck==null?this.cursor:this.cursor-1]
- } else if (typeof(this.messages[msg_id]) == "undefined") {
- if (sess != session) {
- if (this.ondeck != null)
- this.ondeck.remove()
- else
- this.cursor += 1
- this.messages[msg_id] = new Message(msg_id, this.obj)
- this.ordering.push(this.messages[msg_id])
- this.get().activate()
- }
- }
- return this.messages[msg_id]
-}
-Manager.prototype.set = function (msg_id) {
- if (this.ondeck == null)
- alert("Error, nothing ondeck!")
- else {
- this.messages[msg_id] = this.ondeck
- this.ordering.push(this.ondeck)
- this.ondeck = null
- }
-}
-Manager.prototype.deactivate = function (current) {
- for (var i in this.messages)
- this.messages[i].deactivate()
- if (this.ondeck != null) {
- this.ondeck.deactivate()
- if (this.ondeck != current) {
- this.ondeck.remove()
- this.ondeck = null
- }
- }
-}
-
-function Message(msg_id, obj) {
- this.msg_id = msg_id
- this.num = msg_id == -1?exec_count+1:exec_count
-
- this.outer = $(document.createElement("div"))
- this.outer.addClass("message")
- $(obj).append(this.outer)
- this.obj = $(document.createElement("div"))
- this.obj.addClass("message_inside")
- this.outer.append(this.obj)
- this.active = false
-
- this.in_head = $(document.createElement("div"))
- this.in_head.addClass("input_header")
- this.in_head.html("In [<span class='cbold'>"+this.num+"</span>]:")
- this.obj.append(this.in_head)
-
- this.input = $(document.createElement("pre"))
- this.input.addClass("input")
- this.obj.append(this.input)
- this.obj.append("<div class='clear'></div>")
-
- this.out_head = $(document.createElement("div"))
- this.out_head.addClass("output_header")
- this.obj.append(this.out_head)
-
- this.output = $(document.createElement("pre"))
- this.output.addClass("output")
- this.obj.append(this.output)
- this.obj.append("<div class='clear'></div>")
-
- this.code = ""
- var thisObj = this
- this.obj.click(function(e) {
- thisObj.activate()
- e.stopPropagation()
- })
-}
-Message.prototype.activate = function () {
- this.active = true
- manager.deactivate(this)
- this.outer.addClass("active")
- var input = document.createElement("input")
- input.setAttribute("value", this.input.text().replace("'", "\\'"))
- this.text = $(input)
- this.input.html(this.text)
- this.text.focus()
-
- var thisObj = this
- this.text.keydown(function(e) {
- if (e.which == 13)
- thisObj.submit(e.target.value)
- else if (e.which == 38) {
- manager.get("-1").activate()
- } else if (e.which == 40) {
- manager.get("+1").activate()
- }
- })
-}
-Message.prototype.deactivate = function () {
- this.outer.removeClass("active")
- this.input.html(this.code)
- this.active = false
-}
-Message.prototype.submit = function (code) {
- this.code = code
- this.deactivate()
- comet.stop()
- var thisObj = this
- execute(code, function(json) {
- thisObj.num = exec_count
- thisObj.in_head.html("In [<span class='cbold'>"+exec_count+"</span>]:")
- if (manager.ondeck == thisObj)
- manager.set(json.parent_header.msg_id)
- else
- manager.messages[json.parent_header.msg_id] = thisObj
- comet.start()
- })
-}
-Message.prototype.remove = function () {
- this.outer.remove()
- manager.ondeck = null
-}
-Message.prototype.setInput = function(value) {
- this.input.html(value)
-}
-Message.prototype.setOutput = function(value, header) {
- this.output.html(value)
- if (header)
- this.out_head.html("Out [<span class='cbold'>"+this.num+"</span>]:")
-}
View
191 IPython/frontend/html/js/ui.js
@@ -0,0 +1,191 @@
+/***********************************************************************
+ * Tracks the status bar on the right, will eventually be draggable
+ ***********************************************************************/
+function StatusBar(obj) {
+ $("#"+obj).append("<span class='txt'></span>")
+ $("#"+obj).append("<span class='bullet'>&#8226;</span>")
+ this.text = $("#"+obj+" .txt")
+ this.bullet = $("#"+obj+" .bullet")
+}
+StatusBar.prototype.map = { "idle":"cgreen", "busy":"cyellow", "dead":"cred" }
+StatusBar.prototype.set = function(status) {
+ this.bullet.removeClass()
+ this.bullet.addClass("bullet "+this.map[status])
+ this.text.text(status)
+}
+
+/***********************************************************************
+ * Manages the messages and their ordering
+ ***********************************************************************/
+function Manager(obj) {
+ this.messages = {}
+ this.ordering = []
+ this.obj = "#"+obj
+ this.ondeck = null
+ this.cursor = 0
+ var thisObj = this
+ $(document).click(function() {
+ thisObj.deactivate(thisObj.ondeck)
+ })
+}
+Manager.prototype.get = function (msg_id, sess) {
+ if (typeof(msg_id) == "undefined") {
+ //Handle manager.get(), to return a new message on deck
+ if (this.ondeck == null) {
+ this.ondeck = new Message(-1, this.obj)
+ this.cursor = this.ordering.length
+ }
+ return this.ondeck
+ } else if (msg_id[0] == "+" || msg_id[0] == "-") {
+ //Handle the manager.get("+1") case, to advance the cursor
+ var idx = parseInt(msg_id)
+ if (this.cursor + idx <= this.ordering.length &&
+ this.cursor + idx >= 0)
+ this.cursor += idx
+ if (this.cursor >= this.ordering.length ||
+ this.ordering.length == 0) {
+ return this.get()
+ }
+ return this.ordering[this.cursor]
+ } else if (typeof(this.messages[msg_id]) == "undefined") {
+ if (sess != session) {
+ if (this.ondeck != null)
+ this.ondeck.remove()
+ this.messages[msg_id] = new Message(msg_id, this.obj)
+ this.ordering.push(this.messages[msg_id])
+ this.get().activate()
+ }
+ }
+ return this.messages[msg_id]
+}
+Manager.prototype.set = function (msg_id) {
+ if (this.ondeck == null)
+ alert("Error, nothing ondeck!")
+ else {
+ this.messages[msg_id] = this.ondeck
+ this.ordering.push(this.ondeck)
+ this.ondeck = null
+ }
+}
+Manager.prototype.deactivate = function (current) {
+ for (var i in this.messages)
+ this.messages[i].deactivate()
+ if (this.ondeck != null) {
+ this.ondeck.deactivate()
+ if (this.ondeck != current) {
+ this.ondeck.remove()
+ this.ondeck = null
+ }
+ }
+}
+
+/***********************************************************************
+ * Each message is a paired input/output object
+ ***********************************************************************/
+function Message(msg_id, obj) {
+ this.msg_id = msg_id
+ this.num = msg_id == -1?exec_count+1:exec_count
+
+ this.outer = $(document.createElement("div"))
+ this.outer.addClass("message")
+ $(obj).append(this.outer)
+ this.obj = $(document.createElement("div"))
+ this.obj.addClass("message_inside")
+ this.outer.append(this.obj)
+ this.active = false
+
+ this.in_head = $(document.createElement("div"))
+ this.in_head.addClass("input_header")
+ this.in_head.html("In [<span class='cbold'>"+this.num+"</span>]:")
+ this.obj.append(this.in_head)
+
+ this.input = $(document.createElement("pre"))
+ this.input.addClass("input")
+ this.obj.append(this.input)
+ this.obj.append("<div class='clear'></div>")
+
+ this.out_head = $(document.createElement("div"))
+ this.out_head.addClass("output_header")
+ this.obj.append(this.out_head)
+
+ this.output = $(document.createElement("pre"))
+ this.output.addClass("output")
+ this.obj.append(this.output)
+ this.obj.append("<div class='clear'></div>")
+
+ this.code = ""
+ var thisObj = this
+ this.obj.click(function(e) {
+ thisObj.activate()
+ e.stopPropagation()
+ })
+}
+Message.prototype.activate = function () {
+ this.active = true
+ manager.deactivate(this)
+ this.outer.addClass("active")
+ this.text = new InputArea(this)
+}
+Message.prototype.deactivate = function () {
+ this.outer.removeClass("active")
+ this.input.html(this.code)
+ this.active = false
+}
+Message.prototype.remove = function () {
+ this.outer.remove()
+ manager.ondeck = null
+}
+Message.prototype.setInput = function(value) {
+ this.code = value
+ this.input.html(value)
+}
+Message.prototype.setOutput = function(value, header) {
+ this.in_head.html("In [<span class='cbold'>"+this.num+"</span>]:")
+ this.output.html(value)
+ if (header)
+ this.out_head.html("Out [<span class='cbold'>"+this.num+"</span>]:")
+}
+
+/***********************************************************************
+ * Handles python input, including autocompletion, submission, etc
+ ***********************************************************************/
+function InputArea(msg) {
+ this.msg = msg
+ this.activate()
+}
+InputArea.prototype.activate = function () {
+ var input = document.createElement("input")
+ input.setAttribute("value", this.msg.code)
+ this.text = $(input)
+ this.msg.input.html(this.text)
+ this.text.focus()
+
+ var thisObj = this
+ this.text.keydown(function(e) {
+ if (e.which == 13)
+ thisObj.submit(e.target.value)
+ else if (e.which == 38) {
+ manager.get("-1").activate()
+ } else if (e.which == 40) {
+ manager.get("+1").activate()
+ } else if (e.which == 9) {
+ e.preventDefault()
+
+ tabcomplete()
+ }
+ })
+ $.scrollTo(this.text)
+}
+InputArea.prototype.submit = function (code) {
+ this.msg.code = code
+ comet.stop()
+ var thisObj = this
+ execute(code, function(json) {
+ thisObj.msg.num = exec_count
+ if (manager.ondeck == thisObj.msg)
+ manager.set(json.parent_header.msg_id)
+ else
+ manager.messages[json.parent_header.msg_id] = thisObj.msg
+ comet.start()
+ })
+}
View
24 IPython/frontend/html/kernelmanager.py
@@ -13,7 +13,9 @@
from SocketServer import ThreadingMixIn
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
-client_death = 30 # seconds without heartbeat that client considered dead
+client_death = 300 # seconds without heartbeat that client considered dead
+#Base path to serve js and css files from
+basepath = os.path.split(__main__.__file__)[0]+"/"
class CometManager(object):
"""Tracks msg_id, client get requests for the Comet design pattern"""
@@ -55,8 +57,6 @@ def addreq(self, msg):
manager = CometManager()
-basepath = os.path.split(__main__.__file__)[0]+"/"
-
class IPyHttpHandler(BaseHTTPRequestHandler):
def do_GET(self):
#Path is either a real path, or the client_id
@@ -117,17 +117,12 @@ def do_POST(self):
class IPyHttpServer(ThreadingMixIn, HTTPServer):
pass
-
# IPython imports.
from IPython.utils.traitlets import Type
from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \
XReqSocketChannel, RepSocketChannel, HBSocketChannel
class HttpXReqSocketChannel(XReqSocketChannel):
- # Used by the first_reply signal logic to determine if a reply is the
- # first.
- _handlers_called = False
-
#---------------------------------------------------------------------------
# 'XReqSocketChannel' interface
#---------------------------------------------------------------------------
@@ -135,20 +130,8 @@ class HttpXReqSocketChannel(XReqSocketChannel):
def call_handlers(self, msg):
""" Reimplemented to emit signals instead of making callbacks.
"""
- if not self._handlers_called:
- self._handlers_called = True
manager.addreq(msg)
- #---------------------------------------------------------------------------
- # 'HttpXReqSocketChannel' interface
- #---------------------------------------------------------------------------
-
- def reset_first_reply(self):
- """ Reset the first_reply signal to fire again on the next reply.
- """
- self._handlers_called = False
-
-
class HttpSubSocketChannel(SubSocketChannel):
#---------------------------------------------------------------------------
# 'SubSocketChannel' interface
@@ -169,7 +152,6 @@ def call_handlers(self, msg):
"""
pass
-
class HttpHBSocketChannel(HBSocketChannel):
#---------------------------------------------------------------------------
# 'HBSocketChannel' interface
View
100 IPython/frontend/html/notebook.html
@@ -4,99 +4,15 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>AJAX test</title>
- <style type="text/css">
- body { font-family:sans-serif; font-size:10pt;}
- pre, p { margin:0px; }
- .cblue { color: blue }
- .ccyan { color: teal }
- .cgreen { color: green }
- .cyellow { color: yellow }
- .cred { color: red }
- .cbold { font-weight:bold }
- .hidden { display:none; }
- .clear { clear:both; }
-
- .headers { font-size:60%;}
- .xreq { font-style:italic }
-
- #sidebar { float:right; width:20%; }
- #statusbar { margin:5px; }
- #statusbar span { vertical-align:middle; }
- #statusbar .bullet {
- font-size:150%;
- margin-left:10px;
- float:right;
- }
- #messages {
- width:80%;
- float:left;
- }
- .active {
- border-color:#090;
- }
- .message {
- padding:3px;
- border:1px solid #CCC;
- margin:2px;
- }
- .message:hover {
- border:1px solid red;
- cursor:pointer;
- }
- .message .input_header {
- color:blue;
- float:left;
- width:10%;
- }
- .message .input {
- float:left;
- width:90%;
- }
- .message .output_header {
- color:red;
- float:left;
- width:10%;
- margin:1px;
- }
- .message .output {
- float:left;
- width:90%;
- }
-
- .inlinesvg { width:432pt; height:288pt; }
-
- pre.input input {
- width:100%;
- border:none;
- padding:0px;
- }
- </style>
- <script type="text/javascript" src="js/jquery.min.js"></script>
+ <link rel="stylesheet" type="text/css" href="css/defaults.css" />
+ <link rel="stylesheet" type="text/css" href="css/notebook.css" />
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
+ <script type="text/javascript" src="js/jquery.scrollTo-1.4.2-min.js"></script>
+ <script type="text/javascript" src="js/jquery-fieldselection.pack.js"></script>
+ <script type="text/javascript">client_id = "/$client_id";</script>
<script type="text/javascript" src="js/notebook.js"></script>
- <script type="text/javascript">
- client_id = "/$client_id";
- $.ajaxSetup({
- url: client_id,
- dataType: "json"
- })
- $(document).ready(function() {
- comet = new CometGetter()
- heartbeat()
- manager = new Manager("messages")
- //Startup POST, set some globals
- $.ajax({
- type: "POST",
- data: {type:"connect"},
- success: function(json, status, request) {
- username = json.parent_header.username
- session = json.parent_header.session
- exec_count = json.content.execution_count
- manager.get().activate()
- }
- })
- statusbar = new StatusBar("statusbar")
- })
- </script>
+ <script type="text/javascript" src="js/communicate.js"></script>
+ <script type="text/javascript" src="js/ui.js"></script>
</head>
<body>
<div id="messages"></div>
Please sign in to comment.
Something went wrong with that request. Please try again.