Show More
@@ -1,15 +1,10 b'' | |||||
1 | # Standard library imports |
|
|||
2 | from codeop import CommandCompiler |
|
|||
3 | from threading import Thread |
|
|||
4 | import time |
|
|||
5 | import types |
|
|||
6 |
|
||||
7 |
|
|
1 | # System library imports | |
8 | from pygments.lexers import PythonLexer |
|
2 | from pygments.lexers import PythonLexer | |
9 | from PyQt4 import QtCore, QtGui |
|
3 | from PyQt4 import QtCore, QtGui | |
10 | import zmq |
|
4 | import zmq | |
11 |
|
5 | |||
12 | # Local imports |
|
6 | # Local imports | |
|
7 | from IPython.core.blockbreaker import BlockBreaker | |||
13 | from call_tip_widget import CallTipWidget |
|
8 | from call_tip_widget import CallTipWidget | |
14 | from completion_lexer import CompletionLexer |
|
9 | from completion_lexer import CompletionLexer | |
15 | from console_widget import HistoryConsoleWidget |
|
10 | from console_widget import HistoryConsoleWidget | |
@@ -60,8 +55,8 b' class FrontendWidget(HistoryConsoleWidget):' | |||||
60 | def __init__(self, kernel_manager, parent=None): |
|
55 | def __init__(self, kernel_manager, parent=None): | |
61 | super(FrontendWidget, self).__init__(parent) |
|
56 | super(FrontendWidget, self).__init__(parent) | |
62 |
|
57 | |||
|
58 | self._blockbreaker = BlockBreaker() | |||
63 | self._call_tip_widget = CallTipWidget(self) |
|
59 | self._call_tip_widget = CallTipWidget(self) | |
64 | self._compile = CommandCompiler() |
|
|||
65 | self._completion_lexer = CompletionLexer(PythonLexer()) |
|
60 | self._completion_lexer = CompletionLexer(PythonLexer()) | |
66 | self._hidden = True |
|
61 | self._hidden = True | |
67 | self._highlighter = FrontendHighlighter(self) |
|
62 | self._highlighter = FrontendHighlighter(self) | |
@@ -127,36 +122,15 b' class FrontendWidget(HistoryConsoleWidget):' | |||||
127 | shown. Returns whether the source executed (i.e., returns True only |
|
122 | shown. Returns whether the source executed (i.e., returns True only | |
128 | if no more input is necessary). |
|
123 | if no more input is necessary). | |
129 | """ |
|
124 | """ | |
130 | # Use CommandCompiler to determine if more input is needed. |
|
125 | self._blockbreaker.reset() | |
131 | try: |
|
126 | self._blockbreaker.push(source) | |
132 | code = self._compile(source, symbol='single') |
|
127 | executed = self._blockbreaker.interactive_block_ready() | |
133 | except (OverflowError, SyntaxError, ValueError): |
|
|||
134 | # Just let IPython deal with the syntax error. |
|
|||
135 | code = Exception |
|
|||
136 |
|
||||
137 | # Only execute interactive multiline input if it ends with a blank line |
|
|||
138 | lines = source.splitlines() |
|
|||
139 | if interactive and len(lines) > 1 and lines[-1].strip() != '': |
|
|||
140 | code = None |
|
|||
141 |
|
||||
142 | executed = code is not None |
|
|||
143 | if executed: |
|
128 | if executed: | |
144 | self.kernel_manager.xreq_channel.execute(source) |
|
129 | self.kernel_manager.xreq_channel.execute(source) | |
145 | self._hidden = hidden |
|
130 | self._hidden = hidden | |
146 | else: |
|
131 | else: | |
147 | space = 0 |
|
|||
148 | for char in lines[-1]: |
|
|||
149 | if char == '\t': |
|
|||
150 | space += 4 |
|
|||
151 | elif char == ' ': |
|
|||
152 | space += 1 |
|
|||
153 | else: |
|
|||
154 | break |
|
|||
155 | if source.endswith(':') or source.endswith(':\n'): |
|
|||
156 | space += 4 |
|
|||
157 | self._show_continuation_prompt() |
|
132 | self._show_continuation_prompt() | |
158 | self.appendPlainText(' ' * space) |
|
133 | self.appendPlainText(' ' * self._blockbreaker.indent_spaces) | |
159 |
|
||||
160 | return executed |
|
134 | return executed | |
161 |
|
135 | |||
162 | def execute_file(self, path, hidden=False): |
|
136 | def execute_file(self, path, hidden=False): |
General Comments 0
You need to be logged in to leave comments.
Login now