##// END OF EJS Templates
* Fixed regression from last commit: syntax highlighting works robustly again....
epatters -
Show More
@@ -150,6 +150,7 b' class ConsoleWidget(QtGui.QWidget):'
150 self._prompt = ''
150 self._prompt = ''
151 self._prompt_html = None
151 self._prompt_html = None
152 self._prompt_pos = 0
152 self._prompt_pos = 0
153 self._prompt_sep = ''
153 self._reading = False
154 self._reading = False
154 self._reading_callback = None
155 self._reading_callback = None
155 self._tab_width = 8
156 self._tab_width = 8
@@ -282,24 +283,35 b' class ConsoleWidget(QtGui.QWidget):'
282 --------
283 --------
283 A boolean indicating whether the source was executed.
284 A boolean indicating whether the source was executed.
284 """
285 """
285 if not hidden:
286 # WARNING: The order in which things happen here is very particular, in
286 # Do everything here inside an edit block so continuation prompts
287 # large part because our syntax highlighting is fragile. If you change
287 # are removed seamlessly via undo/redo.
288 # something, test carefully!
288 cursor = self._control.textCursor()
289 cursor.beginEditBlock()
290
291 if source is not None:
292 self.input_buffer = source
293
294 self._append_plain_text('\n')
295 self._executing_input_buffer = self.input_buffer
296 self._executing = True
297 self._prompt_finished()
298
289
299 real_source = self.input_buffer if source is None else source
290 # Decide what to execute.
300 complete = self._is_complete(real_source, interactive)
291 if source is None:
301 if complete:
292 source = self.input_buffer
302 if not hidden:
293 if not hidden:
294 # A newline is appended later, but it should be considered part
295 # of the input buffer.
296 source += '\n'
297 elif not hidden:
298 self.input_buffer = source
299
300 # Execute the source or show a continuation prompt if it is incomplete.
301 complete = self._is_complete(source, interactive)
302 if hidden:
303 if complete:
304 self._execute(source, hidden)
305 else:
306 error = 'Incomplete noninteractive input: "%s"'
307 raise RuntimeError(error % source)
308 else:
309 if complete:
310 self._append_plain_text('\n')
311 self._executing_input_buffer = self.input_buffer
312 self._executing = True
313 self._prompt_finished()
314
303 # The maximum block count is only in effect during execution.
315 # The maximum block count is only in effect during execution.
304 # This ensures that _prompt_pos does not become invalid due to
316 # This ensures that _prompt_pos does not become invalid due to
305 # text truncation.
317 # text truncation.
@@ -309,14 +321,18 b' class ConsoleWidget(QtGui.QWidget):'
309 # disable the undo/redo history, but just to be safe:
321 # disable the undo/redo history, but just to be safe:
310 self._control.setUndoRedoEnabled(False)
322 self._control.setUndoRedoEnabled(False)
311
323
312 self._execute(real_source, hidden)
324 self._execute(source, hidden)
313 elif hidden:
325
314 raise RuntimeError('Incomplete noninteractive input: "%s"' % source)
326 else:
315 else:
327 # Do this inside an edit block so continuation prompts are
316 self._show_continuation_prompt()
328 # removed seamlessly via undo/redo.
329 cursor = self._control.textCursor()
330 cursor.beginEditBlock()
317
331
318 if not hidden:
332 self._append_plain_text('\n')
319 cursor.endEditBlock()
333 self._show_continuation_prompt()
334
335 cursor.endEditBlock()
320
336
321 return complete
337 return complete
322
338
@@ -1115,7 +1131,7 b' class ConsoleWidget(QtGui.QWidget):'
1115
1131
1116 if not callback and not self.isVisible():
1132 if not callback and not self.isVisible():
1117 # If the user cannot see the widget, this function cannot return.
1133 # If the user cannot see the widget, this function cannot return.
1118 raise RuntimeError('Cannot synchronously read a line if the widget'
1134 raise RuntimeError('Cannot synchronously read a line if the widget '
1119 'is not visible!')
1135 'is not visible!')
1120
1136
1121 self._reading = True
1137 self._reading = True
@@ -1212,6 +1228,7 b' class ConsoleWidget(QtGui.QWidget):'
1212 self._append_plain_text('\n')
1228 self._append_plain_text('\n')
1213
1229
1214 # Write the prompt.
1230 # Write the prompt.
1231 self._append_plain_text(self._prompt_sep)
1215 if prompt is None:
1232 if prompt is None:
1216 if self._prompt_html is None:
1233 if self._prompt_html is None:
1217 self._append_plain_text(self._prompt)
1234 self._append_plain_text(self._prompt)
@@ -1238,8 +1255,6 b' class ConsoleWidget(QtGui.QWidget):'
1238 self._continuation_prompt = self._append_html_fetching_plain_text(
1255 self._continuation_prompt = self._append_html_fetching_plain_text(
1239 self._continuation_prompt_html)
1256 self._continuation_prompt_html)
1240
1257
1241 self._prompt_started()
1242
1243
1258
1244 class HistoryConsoleWidget(ConsoleWidget):
1259 class HistoryConsoleWidget(ConsoleWidget):
1245 """ A ConsoleWidget that keeps a history of the commands that have been
1260 """ A ConsoleWidget that keeps a history of the commands that have been
@@ -179,7 +179,7 b' class IPythonWidget(FrontendWidget):'
179
179
180 # Show a new prompt and save information about it so that it can be
180 # Show a new prompt and save information about it so that it can be
181 # updated later if the prompt number turns out to be wrong.
181 # updated later if the prompt number turns out to be wrong.
182 self._append_plain_text(input_sep)
182 self._prompt_sep = input_sep
183 self._show_prompt(self._make_in_prompt(number), html=True)
183 self._show_prompt(self._make_in_prompt(number), html=True)
184 block = self._control.document().lastBlock()
184 block = self._control.document().lastBlock()
185 length = len(self._prompt)
185 length = len(self._prompt)
@@ -22,7 +22,12 b' def main():'
22 """
22 """
23 # Parse command line arguments.
23 # Parse command line arguments.
24 parser = ArgumentParser()
24 parser = ArgumentParser()
25 parser.add_argument('-e', '--existing', action='store_true',
25 parser.add_argument('-r', '--rich', action='store_true',
26 help='use a rich text frontend')
27 parser.add_argument('-t', '--tab-simple', action='store_true',
28 help='do tab completion ala a Unix terminal')
29
30 parser.add_argument('--existing', action='store_true',
26 help='connect to an existing kernel')
31 help='connect to an existing kernel')
27 parser.add_argument('--ip', type=str, default=LOCALHOST,
32 parser.add_argument('--ip', type=str, default=LOCALHOST,
28 help='set the kernel\'s IP address [default localhost]')
33 help='set the kernel\'s IP address [default localhost]')
@@ -32,13 +37,13 b' def main():'
32 help='set the SUB channel port [default random]')
37 help='set the SUB channel port [default random]')
33 parser.add_argument('--rep', type=int, metavar='PORT', default=0,
38 parser.add_argument('--rep', type=int, metavar='PORT', default=0,
34 help='set the REP channel port [default random]')
39 help='set the REP channel port [default random]')
40
35 group = parser.add_mutually_exclusive_group()
41 group = parser.add_mutually_exclusive_group()
36 group.add_argument('--pure', action='store_true', help = \
42 group.add_argument('--pure', action='store_true', help = \
37 'use a pure Python kernel instead of an IPython kernel')
43 'use a pure Python kernel instead of an IPython kernel')
38 group.add_argument('--pylab', action='store_true',
44 group.add_argument('--pylab', action='store_true',
39 help='use a kernel with PyLab enabled')
45 help='use a kernel with PyLab enabled')
40 parser.add_argument('--rich', action='store_true',
46
41 help='use a rich text frontend')
42 args = parser.parse_args()
47 args = parser.parse_args()
43
48
44 # Don't let Qt or ZMQ swallow KeyboardInterupts.
49 # Don't let Qt or ZMQ swallow KeyboardInterupts.
@@ -70,6 +75,7 b' def main():'
70 widget = RichIPythonWidget()
75 widget = RichIPythonWidget()
71 else:
76 else:
72 widget = IPythonWidget()
77 widget = IPythonWidget()
78 widget.gui_completion = not args.tab_simple
73 widget.kernel_manager = kernel_manager
79 widget.kernel_manager = kernel_manager
74 widget.setWindowTitle('Python' if args.pure else 'IPython')
80 widget.setWindowTitle('Python' if args.pure else 'IPython')
75 widget.show()
81 widget.show()
General Comments 0
You need to be logged in to leave comments. Login now