Show More
@@ -22,6 +22,8 b' __docformat__ = "restructuredtext en"' | |||||
22 | import wx |
|
22 | import wx | |
23 | import wx.stc as stc |
|
23 | import wx.stc as stc | |
24 |
|
24 | |||
|
25 | from wx.py import editwindow | |||
|
26 | ||||
25 | import re |
|
27 | import re | |
26 |
|
28 | |||
27 | # FIXME: Need to provide an API for non user-generated display on the |
|
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 | # The console widget class |
|
67 | # The console widget class | |
66 | #------------------------------------------------------------------------------- |
|
68 | #------------------------------------------------------------------------------- | |
67 |
class ConsoleWidget( |
|
69 | class ConsoleWidget(editwindow.EditWindow): | |
68 | """ Specialized styled text control view for console-like workflow. |
|
70 | """ Specialized styled text control view for console-like workflow. | |
69 |
|
71 | |||
70 | This widget is mainly interested in dealing with the prompt and |
|
72 | This widget is mainly interested in dealing with the prompt and | |
@@ -100,7 +102,8 b' class ConsoleWidget(stc.StyledTextCtrl):' | |||||
100 | 'IPYTHON' show autocompletion the ipython way |
|
102 | 'IPYTHON' show autocompletion the ipython way | |
101 | 'STC" show it scintilla text control way |
|
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 | self.configure_scintilla() |
|
107 | self.configure_scintilla() | |
105 |
|
108 | |||
106 | # FIXME: we need to retrieve this from the interpreter. |
|
109 | # FIXME: we need to retrieve this from the interpreter. |
@@ -22,7 +22,7 b' __docformat__ = "restructuredtext en"' | |||||
22 |
|
22 | |||
23 | import wx |
|
23 | import wx | |
24 | from console_widget import ConsoleWidget |
|
24 | from console_widget import ConsoleWidget | |
25 |
|
25 | import re | ||
26 |
|
26 | |||
27 | import IPython |
|
27 | import IPython | |
28 | from IPython.kernel.engineservice import EngineService |
|
28 | from IPython.kernel.engineservice import EngineService | |
@@ -41,6 +41,14 b' class IPythonWxController(FrontEndBase, ConsoleWidget):' | |||||
41 | output_prompt = \ |
|
41 | output_prompt = \ | |
42 | '\n\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02%i\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02' |
|
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 | # Public API |
|
53 | # Public API | |
46 | #-------------------------------------------------------------------------- |
|
54 | #-------------------------------------------------------------------------- | |
@@ -121,9 +129,34 b' class IPythonWxController(FrontEndBase, ConsoleWidget):' | |||||
121 | """ Called when the return key is pressed in a line editing |
|
129 | """ Called when the return key is pressed in a line editing | |
122 | buffer. |
|
130 | buffer. | |
123 | """ |
|
131 | """ | |
124 |
|
|
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) | |||
125 | self.render_result(result) |
|
139 | self.render_result(result) | |
126 | self.new_prompt(self.prompt % result['number']) |
|
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 | ||||
127 |
|
160 | |||
128 |
|
161 | |||
129 | if __name__ == '__main__': |
|
162 | if __name__ == '__main__': |
General Comments 0
You need to be logged in to leave comments.
Login now