Show More
@@ -22,6 +22,8 b' __docformat__ = "restructuredtext en"' | |||
|
22 | 22 | import wx |
|
23 | 23 | import wx.stc as stc |
|
24 | 24 | |
|
25 | from wx.py import editwindow | |
|
26 | ||
|
25 | 27 | import re |
|
26 | 28 | |
|
27 | 29 | # FIXME: Need to provide an API for non user-generated display on the |
@@ -64,7 +66,7 b' _TRACE_STYLE = 17' | |||
|
64 | 66 | #------------------------------------------------------------------------------- |
|
65 | 67 | # The console widget class |
|
66 | 68 | #------------------------------------------------------------------------------- |
|
67 |
class ConsoleWidget( |
|
|
69 | class ConsoleWidget(editwindow.EditWindow): | |
|
68 | 70 | """ Specialized styled text control view for console-like workflow. |
|
69 | 71 | |
|
70 | 72 | This widget is mainly interested in dealing with the prompt and |
@@ -100,7 +102,8 b' class ConsoleWidget(stc.StyledTextCtrl):' | |||
|
100 | 102 | 'IPYTHON' show autocompletion the ipython way |
|
101 | 103 | 'STC" show it scintilla text control way |
|
102 | 104 | """ |
|
103 | stc.StyledTextCtrl.__init__(self, parent, id, pos, size, style) | |
|
105 | #stc.StyledTextCtrl.__init__(self, parent, id, pos, size, style) | |
|
106 | editwindow.EditWindow.__init__(self, parent, id, pos, size, style) | |
|
104 | 107 | self.configure_scintilla() |
|
105 | 108 | |
|
106 | 109 | # FIXME: we need to retrieve this from the interpreter. |
@@ -22,7 +22,7 b' __docformat__ = "restructuredtext en"' | |||
|
22 | 22 | |
|
23 | 23 | import wx |
|
24 | 24 | from console_widget import ConsoleWidget |
|
25 | ||
|
25 | import re | |
|
26 | 26 | |
|
27 | 27 | import IPython |
|
28 | 28 | from IPython.kernel.engineservice import EngineService |
@@ -40,7 +40,15 b' class IPythonWxController(FrontEndBase, ConsoleWidget):' | |||
|
40 | 40 | |
|
41 | 41 | output_prompt = \ |
|
42 | 42 | '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' |
|
43 |
|
|
|
43 | ||
|
44 | # Are we entering multi line input? | |
|
45 | multi_line_input = False | |
|
46 | ||
|
47 | # The added tab stop to the string. It may, for instance, come from | |
|
48 | # copy and pasting something with tabs. | |
|
49 | tab_stop = 0 | |
|
50 | # FIXME: We still have to deal with this. | |
|
51 | ||
|
44 | 52 | #-------------------------------------------------------------------------- |
|
45 | 53 | # Public API |
|
46 | 54 | #-------------------------------------------------------------------------- |
@@ -121,10 +129,35 b' class IPythonWxController(FrontEndBase, ConsoleWidget):' | |||
|
121 | 129 | """ Called when the return key is pressed in a line editing |
|
122 | 130 | buffer. |
|
123 | 131 | """ |
|
124 |
|
|
|
125 | self.render_result(result) | |
|
126 | self.new_prompt(self.prompt % result['number']) | |
|
127 | ||
|
132 | current_buffer = self.get_current_edit_buffer() | |
|
133 | current_buffer = current_buffer.replace('\r\n', '\n') | |
|
134 | current_buffer = current_buffer.replace('\t', 4*' ') | |
|
135 | if ( not self.multi_line_input | |
|
136 | or re.findall(r"\n[\t ]*\n[\t ]*$", current_buffer)): | |
|
137 | if self.is_complete(current_buffer): | |
|
138 | result = self.engine.shell.execute(current_buffer) | |
|
139 | self.render_result(result) | |
|
140 | self.new_prompt(self.prompt % result['number']) | |
|
141 | self.multi_line_input = False | |
|
142 | else: | |
|
143 | if self.multi_line_input: | |
|
144 | self.write(self._get_indent_string(current_buffer[:-1])) | |
|
145 | else: | |
|
146 | self.multi_line_input = True | |
|
147 | self.write('\t') | |
|
148 | else: | |
|
149 | self.write(self._get_indent_string(current_buffer[:-1])) | |
|
150 | ||
|
151 | ||
|
152 | def _get_indent_string(self, string): | |
|
153 | string = string.split('\n')[-1] | |
|
154 | indent_chars = len(string) - len(string.lstrip()) | |
|
155 | indent_string = '\t'*(indent_chars // 4) + \ | |
|
156 | ' '*(indent_chars % 4) | |
|
157 | ||
|
158 | return indent_string | |
|
159 | ||
|
160 | ||
|
128 | 161 | |
|
129 | 162 | if __name__ == '__main__': |
|
130 | 163 | class MainWindow(wx.Frame): |
@@ -143,5 +176,5 b" if __name__ == '__main__':" | |||
|
143 | 176 | frame.SetSize((780, 460)) |
|
144 | 177 | shell = frame.shell |
|
145 | 178 | |
|
146 |
|
|
|
179 | # app.MainLoop() | |
|
147 | 180 |
General Comments 0
You need to be logged in to leave comments.
Login now