##// END OF EJS Templates
Progress on raw_input.
epatters -
Show More
@@ -256,11 +256,12 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
256
256
257 else:
257 else:
258 if key in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
258 if key in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
259 intercepted = True
259 if self._reading:
260 if self._reading:
261 intercepted = False
260 self._reading = False
262 self._reading = False
261 elif not self._executing:
263 elif not self._executing:
262 self.execute(interactive=True)
264 self.execute(interactive=True)
263 intercepted = True
264
265
265 elif key == QtCore.Qt.Key_Up:
266 elif key == QtCore.Qt.Key_Up:
266 if self._reading or not self._up_pressed():
267 if self._reading or not self._up_pressed():
@@ -677,6 +678,19 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
677 self.setReadOnly(True)
678 self.setReadOnly(True)
678 self._prompt_finished_hook()
679 self._prompt_finished_hook()
679
680
681 def _readline(self, prompt=''):
682 """ Read and return one line of input from the user. The trailing
683 newline is stripped.
684 """
685 if not self.isVisible():
686 raise RuntimeError('Cannot read a line if widget is not visible!')
687
688 self._reading = True
689 self._show_prompt(prompt)
690 while self._reading:
691 QtCore.QCoreApplication.processEvents()
692 return self.input_buffer.rstrip('\n\r')
693
680 def _set_position(self, position):
694 def _set_position(self, position):
681 """ Convenience method to set the position of the cursor.
695 """ Convenience method to set the position of the cursor.
682 """
696 """
@@ -691,11 +705,20 b' class ConsoleWidget(QtGui.QPlainTextEdit):'
691
705
692 def _show_prompt(self, prompt=None):
706 def _show_prompt(self, prompt=None):
693 """ Writes a new prompt at the end of the buffer. If 'prompt' is not
707 """ Writes a new prompt at the end of the buffer. If 'prompt' is not
694 specified, uses the previous prompt.
708 specified, the previous prompt is used.
695 """
709 """
710 # Use QTextDocumentFragment intermediate object because it strips
711 # out the Unicode line break characters that Qt insists on inserting.
712 cursor = self._get_end_cursor()
713 cursor.movePosition(QtGui.QTextCursor.Left,
714 QtGui.QTextCursor.KeepAnchor)
715 if str(cursor.selection().toPlainText()) not in '\r\n':
716 self.appendPlainText('\n')
717
696 if prompt is not None:
718 if prompt is not None:
697 self._prompt = prompt
719 self._prompt = prompt
698 self.appendPlainText('\n' + self._prompt)
720 self.appendPlainText(self._prompt)
721
699 self._prompt_pos = self._get_end_cursor().position()
722 self._prompt_pos = self._get_end_cursor().position()
700 self._prompt_started()
723 self._prompt_started()
701
724
@@ -60,7 +60,6 b' class FrontendWidget(HistoryConsoleWidget):'
60
60
61 # ConsoleWidget protected variables.
61 # ConsoleWidget protected variables.
62 self._continuation_prompt = '... '
62 self._continuation_prompt = '... '
63 self._prompt = '>>> '
64
63
65 # FrontendWidget protected variables.
64 # FrontendWidget protected variables.
66 self._call_tip_widget = CallTipWidget(self)
65 self._call_tip_widget = CallTipWidget(self)
@@ -141,6 +140,17 b' class FrontendWidget(HistoryConsoleWidget):'
141 return False
140 return False
142
141
143 #---------------------------------------------------------------------------
142 #---------------------------------------------------------------------------
143 # 'ConsoleWidget' protected interface
144 #---------------------------------------------------------------------------
145
146 def _show_prompt(self, prompt=None):
147 """ Reimplemented to set a default prompt.
148 """
149 if prompt is None:
150 prompt = '>>> '
151 super(FrontendWidget, self)._show_prompt(prompt)
152
153 #---------------------------------------------------------------------------
144 # 'FrontendWidget' interface
154 # 'FrontendWidget' interface
145 #---------------------------------------------------------------------------
155 #---------------------------------------------------------------------------
146
156
@@ -261,6 +271,16 b' class FrontendWidget(HistoryConsoleWidget):'
261
271
262 #------ Signal handlers ----------------------------------------------------
272 #------ Signal handlers ----------------------------------------------------
263
273
274 def _started_channels(self):
275 """ Called when the kernel manager has started listening.
276 """
277 self.clear()
278
279 def _stopped_channels(self):
280 """ Called when the kernel manager has stopped listening.
281 """
282 pass
283
264 def _document_contents_change(self, position, removed, added):
284 def _document_contents_change(self, position, removed, added):
265 """ Called whenever the document's content changes. Display a calltip
285 """ Called whenever the document's content changes. Display a calltip
266 if appropriate.
286 if appropriate.
@@ -272,6 +292,9 b' class FrontendWidget(HistoryConsoleWidget):'
272 if position == self.textCursor().position():
292 if position == self.textCursor().position():
273 self._call_tip()
293 self._call_tip()
274
294
295 def _handle_req(self):
296 print self._readline()
297
275 def _handle_sub(self, omsg):
298 def _handle_sub(self, omsg):
276 if self._hidden:
299 if self._hidden:
277 return
300 return
@@ -323,8 +346,4 b' class FrontendWidget(HistoryConsoleWidget):'
323 if doc:
346 if doc:
324 self._call_tip_widget.show_docstring(doc)
347 self._call_tip_widget.show_docstring(doc)
325
348
326 def _started_channels(self):
349
327 self.clear()
328
329 def _stopped_channels(self):
330 pass
@@ -28,6 +28,64 b' from session import Session, Message, extract_header'
28 from completer import KernelCompleter
28 from completer import KernelCompleter
29
29
30
30
31 class InStream(object):
32 """ A file like object that reads from a 0MQ XREQ socket."""
33
34 def __init__(self, session, socket):
35 self.session = session
36 self.socket = socket
37
38 def close(self):
39 self.socket = None
40
41 def flush(self):
42 if self.socket is None:
43 raise ValueError(u'I/O operation on closed file')
44
45 def isatty(self):
46 return False
47
48 def next(self):
49 raise IOError('Seek not supported.')
50
51 def read(self, size=-1):
52 raise NotImplementedError
53
54 def readline(self, size=-1):
55 if self.socket is None:
56 raise ValueError(u'I/O operation on closed file')
57 else:
58 content = { u'size' : unicode(size) }
59 msg = self.session.msg(u'readline', content=content)
60 return self._request(msg)
61
62 def readlines(self, size=-1):
63 raise NotImplementedError
64
65 def seek(self, offset, whence=None):
66 raise IOError('Seek not supported.')
67
68 def write(self, string):
69 raise IOError('Write not supported on a read only stream.')
70
71 def writelines(self, sequence):
72 raise IOError('Write not supported on a read only stream.')
73
74 def _request(self, msg):
75 self.socket.send_json(msg)
76 while True:
77 try:
78 reply = self.socket.recv_json(zmq.NOBLOCK)
79 except zmq.ZMQError, e:
80 if e.errno == zmq.EAGAIN:
81 pass
82 else:
83 raise
84 else:
85 break
86 return reply[u'content'][u'data']
87
88
31 class OutStream(object):
89 class OutStream(object):
32 """A file like object that publishes the stream to a 0MQ PUB socket."""
90 """A file like object that publishes the stream to a 0MQ PUB socket."""
33
91
@@ -60,7 +118,7 b' class OutStream(object):'
60 self._buffer_len = 0
118 self._buffer_len = 0
61 self._buffer = []
119 self._buffer = []
62
120
63 def isattr(self):
121 def isatty(self):
64 return False
122 return False
65
123
66 def next(self):
124 def next(self):
@@ -113,28 +171,6 b' class DisplayHook(object):'
113 self.parent_header = extract_header(parent)
171 self.parent_header = extract_header(parent)
114
172
115
173
116 class RawInput(object):
117
118 def __init__(self, session, socket):
119 self.session = session
120 self.socket = socket
121
122 def __call__(self, prompt=None):
123 msg = self.session.msg(u'raw_input')
124 self.socket.send_json(msg)
125 while True:
126 try:
127 reply = self.socket.recv_json(zmq.NOBLOCK)
128 except zmq.ZMQError, e:
129 if e.errno == zmq.EAGAIN:
130 pass
131 else:
132 raise
133 else:
134 break
135 return reply[u'content'][u'data']
136
137
138 class Kernel(object):
174 class Kernel(object):
139
175
140 def __init__(self, session, reply_socket, pub_socket):
176 def __init__(self, session, reply_socket, pub_socket):
@@ -319,7 +355,12 b' def main():'
319 pub_port = bind_port(pub_socket, namespace.ip, namespace.pub)
355 pub_port = bind_port(pub_socket, namespace.ip, namespace.pub)
320 print >>sys.__stdout__, "PUB Channel on port", pub_port
356 print >>sys.__stdout__, "PUB Channel on port", pub_port
321
357
358 req_socket = context.socket(zmq.XREQ)
359 req_port = bind_port(req_socket, namespace.ip, namespace.req)
360 print >>sys.__stdout__, "REQ Channel on port", req_port
361
322 # Redirect input streams and set a display hook.
362 # Redirect input streams and set a display hook.
363 sys.stdin = InStream(session, req_socket)
323 sys.stdout = OutStream(session, pub_socket, u'stdout')
364 sys.stdout = OutStream(session, pub_socket, u'stdout')
324 sys.stderr = OutStream(session, pub_socket, u'stderr')
365 sys.stderr = OutStream(session, pub_socket, u'stderr')
325 sys.displayhook = DisplayHook(session, pub_socket)
366 sys.displayhook = DisplayHook(session, pub_socket)
@@ -218,7 +218,6 b' class XReqSocketChannel(ZmqSocketChannel):'
218 -------
218 -------
219 The msg_id of the message sent.
219 The msg_id of the message sent.
220 """
220 """
221 print oname
222 content = dict(oname=oname)
221 content = dict(oname=oname)
223 msg = self.session.msg('object_info_request', content)
222 msg = self.session.msg('object_info_request', content)
224 self._queue_request(msg)
223 self._queue_request(msg)
General Comments 0
You need to be logged in to leave comments. Login now