Permalink
Browse files

Still trying to fix message tracking bugs. SVG works again...

  • Loading branch information...
1 parent 990adfc commit 97c2417d789889c3e0783a38c7c22e29f9b329af @jamesgao committed with Oct 18, 2010
@@ -6,7 +6,11 @@ CometGetter.prototype.request = function () {
var thisObj = this
$.ajax({
success: function (json, status, request) {
- thisObj.complete(json, status, request)
+ if (json != null)
+ thisObj.complete(json, status, request)
+ },
+ error: function (request, status, error) {
+ statusbar.set("dead")
}
})
}
@@ -19,22 +23,22 @@ CometGetter.prototype.process = function (json) {
if (json.msg_type == "status") {
statusbar.set(json.content.execution_state)
} else if (this.pause) {
- setTimeout(function () { thisObj.process(json) }, 10)
+ setTimeout(function () { thisObj.process(json) }, 1)
} else {
- var msg = manager.get(
- json.parent_header.msg_id,
- json.parent_header.session)
+//$("#messages").append("<div class='headers'>"+json.msg_type+": "+json.parent_header.msg_id+"</div>")
+ var id = json.parent_header.msg_id
+ var msg = manager.get( id, json.parent_header.session)
if (json.msg_type == "stream") {
- msg.setOutput(fixConsole(json.content.data))
+ msg.setOutput(id, fixConsole(json.content.data))
} else if (json.msg_type == "pyin") {
if (json.parent_header.session != session)
- msg.setInput(fixConsole(json.content.code))
+ msg.setInput(id, 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)
+ msg.setOutput(id, fixConsole(json.content.data), true)
} else if (json.msg_type == "pyerr") {
- msg.setOutput(fixConsole(json.content.traceback.join("\n")))
+ msg.setOutput(id, fixConsole(json.content.traceback.join("\n")))
}
}
}
@@ -56,23 +60,22 @@ function heartbeat() {
}
function execute(code, postfunc) {
+ comet.stop()
$.ajax({
type: "POST",
data: {type:"execute", code:code},
success: function(json, status, request) {
+ comet.start()
if (json != null) {
+ var id = json.parent_header.msg_id
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 />")
+ var svg = $(document.createElement('div'))
+ svg.html(json.content.payload[0]['data'])
+ manager.get(id).setOutput(id, svg)
}
//Open a new input object
manager.get().activate()
@@ -81,6 +84,12 @@ function execute(code, postfunc) {
})
}
-function complete() {
-
+function tabcomplete(code, pos, func) {
+ $.ajax({
+ type:"POST",
+ data: {type:"complete", code:code, pos:pos},
+ success: function(json, status, request) {
+ func(json.content.matches)
+ }
+ })
}
@@ -40,7 +40,7 @@ function fixConsole(txt) {
txt = txt.replace(re, close + open)
}
if (opened) txt += "</span>"
- return txt
+ return txt.trim()
}
function inspect(obj) {
@@ -58,13 +58,15 @@ Manager.prototype.get = function (msg_id, sess) {
}
return this.messages[msg_id]
}
-Manager.prototype.set = function (msg_id) {
- if (this.ondeck == null)
- alert("Error, nothing ondeck!")
- else {
+Manager.prototype.set = function (msg_id, new_id) {
+ if (typeof(new_id) == "undefined") {
+ this.ondeck.msg_id = msg_id
this.messages[msg_id] = this.ondeck
this.ordering.push(this.ondeck)
this.ondeck = null
+ } else {
+ this.messages[msg_id].msg_id = new_id
+ this.messages[new_id] = this.messages[msg_id]
}
}
Manager.prototype.deactivate = function (current) {
@@ -135,13 +137,17 @@ Message.prototype.remove = function () {
this.outer.remove()
manager.ondeck = null
}
-Message.prototype.setInput = function(value) {
+Message.prototype.setInput = function(msg_id, 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)
+Message.prototype.setOutput = function(msg_id, value, header) {
+ if (this.msg_id != msg_id) {
+ this.in_head.html("In [<span class='cbold'>"+this.num+"</span>]:")
+ this.output.html(value)
+ } else {
+ this.output.append(value)
+ }
if (header)
this.out_head.html("Out [<span class='cbold'>"+this.num+"</span>]:")
}
@@ -170,22 +176,37 @@ InputArea.prototype.activate = function () {
manager.get("+1").activate()
} else if (e.which == 9) {
e.preventDefault()
-
- tabcomplete()
+ var pos = thisObj.text.getSelection().end
+ tabcomplete(thisObj.text.get(0).value, pos, function(matches) {
+ thisObj.complete(matches)
+ })
}
})
$.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()
+ else
+ manager.set(thisObj.msg.msg_id, json.parent_header.msg_id)
})
}
+InputArea.prototype.complete = function (matches) {
+ if (matches.length == 1)
+ this.replace(matches[0])
+ else if (matches.length > 1) {
+ //TODO:Implement me!
+ }
+}
+InputArea.prototype.replace = function (match) {
+ var pos = this.text.getSelection().end
+ var code = this.text.val()
+ var words = code.slice(0,pos).split(' ')
+ words[words.length-1] = match
+ this.msg.code = words.join(' ')+" "+code.slice(pos)
+ this.text.val(this.msg.code)
+}
@@ -51,6 +51,15 @@ def send(self, msg_type, *args):
args = ("",)
self.kernel_manager.xreq_channel.execute(*args)
return self.req_queue.get()
+
+ def complete(self, code, pos):
+ chunk = code[:int(pos)].split()[-1]
+ self.kernel_manager.xreq_channel.complete(chunk, code, pos)
+ return self.req_queue.get()
+
+ def inspect(self, oname):
+ self.kernel_manager.xreq_channel.object_info(oname)
+ return self.req_queue.get()
def addreq(self, msg):
self.req_queue.put(msg)
@@ -105,14 +114,16 @@ def do_POST(self):
msg_type = data["type"].value
if msg_type == "heartbeat":
manager.heartbeat(client_id)
- elif msg_type == "execute":
- response = manager.send("execute_request", data["code"].value)
- json.dump(response, self.wfile)
- elif msg_type == "complete":
- pass
- elif msg_type == "connect":
- response = manager.send("connect_request")
- json.dump(response, self.wfile)
+ else:
+ if msg_type == "execute":
+ resp = manager.send("execute_request", data["code"].value)
+ elif msg_type == "complete":
+ resp = manager.complete(data["code"].value, data["pos"].value)
+ elif msg_type == "inspect":
+ resp = manager.inspect(data['name'].value)
+ elif msg_type == "connect":
+ resp = manager.send("connect_request")
+ json.dump(resp, self.wfile)
class IPyHttpServer(ThreadingMixIn, HTTPServer):
pass

0 comments on commit 97c2417

Please sign in to comment.