##// END OF EJS Templates
for code review
Barry Wark -
Show More
@@ -1,15 +1,15 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 FrontEndBase: Base classes for frontends.
3 frontendbase provides an interface and base class for GUI frontends for IPython.kernel/IPython.kernel.core.
4
4
5 Todo:
5 Frontend implementations will likely want to subclass FrontEndBase.
6 - synchronous and asynchronous interfaces
6
7 - adapter to add async to FrontEndBase
7 Author: Barry Wark
8 """
8 """
9 __docformat__ = "restructuredtext en"
9 __docformat__ = "restructuredtext en"
10
10
11 #-------------------------------------------------------------------------------
11 #-------------------------------------------------------------------------------
12 # Copyright (C) 2008 Barry Wark <barrywark at gmail _dot_ com>
12 # Copyright (C) 2008 The IPython Development Team
13 #
13 #
14 # Distributed under the terms of the BSD License. The full license is in
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
15 # the file COPYING, distributed as part of this software.
@@ -42,26 +42,32 b" rc.prompt_out = r'Out [$number]: '"
42
42
43 ##############################################################################
43 ##############################################################################
44
44
45 class IFrontEnd(zi.Interface):
45 class IFrontEndFactory(zi.Interface):
46 """Interface for frontends. All methods return t.i.d.Deferred"""
46 """Factory interface for frontends."""
47
47
48 zi.Attribute("input_prompt_template", "string.Template instance substituteable with execute result.")
48 def __call__(engine=None, history=None):
49 zi.Attribute("output_prompt_template", "string.Template instance substituteable with execute result.")
50 zi.Attribute("continuation_prompt_template", "string.Template instance substituteable with execute result.")
51
52 def __init__(engine=None, history=None):
53 """
49 """
54 Parameters:
50 Parameters:
55 interpreter : IPython.kernel.engineservice.IEngineCore
51 interpreter : IPython.kernel.engineservice.IEngineCore
56 """
52 """
53
57 pass
54 pass
55
56
57
58 class IFrontEnd(zi.Interface):
59 """Interface for frontends. All methods return t.i.d.Deferred"""
60
61 zi.Attribute("input_prompt_template", "string.Template instance substituteable with execute result.")
62 zi.Attribute("output_prompt_template", "string.Template instance substituteable with execute result.")
63 zi.Attribute("continuation_prompt_template", "string.Template instance substituteable with execute result.")
58
64
59 def update_cell_prompt(self, result):
65 def update_cell_prompt(self, result):
60 """Subclass may override to update the input prompt for a block.
66 """Subclass may override to update the input prompt for a block.
61 Since this method will be called as a twisted.internet.defer.Deferred's callback,
67 Since this method will be called as a twisted.internet.defer.Deferred's callback,
62 implementations should return result when finished."""
68 implementations should return result when finished."""
63
69
64 return result
70 pass
65
71
66 def render_result(self, result):
72 def render_result(self, result):
67 """Render the result of an execute call. Implementors may choose the method of rendering.
73 """Render the result of an execute call. Implementors may choose the method of rendering.
@@ -74,16 +80,50 b' class IFrontEnd(zi.Interface):'
74 Output of frontend rendering
80 Output of frontend rendering
75 """
81 """
76
82
77 return result
83 pass
78
84
79 def render_error(self, failure):
85 def render_error(self, failure):
80 """Subclasses must override to render the failure. Since this method will be called as a
86 """Subclasses must override to render the failure. Since this method will be called as a
81 twisted.internet.defer.Deferred's callback, implementations should return result
87 twisted.internet.defer.Deferred's callback, implementations should return result
82 when finished."""
88 when finished."""
83
89
84 return failure
90 pass
91
92
93 def inputPrompt(result={}):
94 """Returns the input prompt by subsituting into self.input_prompt_template"""
95 pass
96
97 def outputPrompt(result):
98 """Returns the output prompt by subsituting into self.output_prompt_template"""
99
100 pass
101
102 def continuationPrompt():
103 """Returns the continuation prompt by subsituting into self.continuation_prompt_template"""
104
105 pass
106
107 def is_complete(block):
108 """Returns True if block is complete, False otherwise."""
109
110 pass
111
112 def compile_ast(block):
113 """Compiles block to an _ast.AST"""
114
115 pass
116
117
118 def get_history_item_previous(currentBlock):
119 """Returns the block previous in the history."""
120 pass
121
122 def get_history_item_next(currentBlock):
123 """Returns the next block in the history."""
124
125 pass
85
126
86 # TODO: finish interface
87
127
88 class FrontEndBase(object):
128 class FrontEndBase(object):
89 """
129 """
@@ -97,6 +137,7 b' class FrontEndBase(object):'
97 """
137 """
98
138
99 zi.implements(IFrontEnd)
139 zi.implements(IFrontEnd)
140 zi.classProvides(IFrontEndFactory)
100
141
101 history_cursor = 0
142 history_cursor = 0
102
143
@@ -204,22 +245,22 b' class FrontEndBase(object):'
204 return result
245 return result
205
246
206
247
207 def get_history_item_previous(self, current_block):
248 def get_history_item_previous(self, currentBlock):
208 """ Returns previous history string and decrement history cursor.
249 """ Returns previous history string and decrement history cursor.
209 """
250 """
210 command = self.history.get_history_item(self.history_cursor - 1)
251 command = self.history.get_history_item(self.history_cursor - 1)
211 if command is not None:
252 if command is not None:
212 self.history.input_cache[self.history_cursor] = current_block
253 self.history.input_cache[self.history_cursor] = currentBlock
213 self.history_cursor -= 1
254 self.history_cursor -= 1
214 return command
255 return command
215
256
216
257
217 def get_history_item_next(self, current_block):
258 def get_history_item_next(self, currentBlock):
218 """ Returns next history string and increment history cursor.
259 """ Returns next history string and increment history cursor.
219 """
260 """
220 command = self.history.get_history_item(self.history_cursor + 1)
261 command = self.history.get_history_item(self.history_cursor + 1)
221 if command is not None:
262 if command is not None:
222 self.history.input_cache[self.history_cursor] = current_block
263 self.history.input_cache[self.history_cursor] = currentBlock
223 self.history_cursor += 1
264 self.history_cursor += 1
224 return command
265 return command
225
266
General Comments 0
You need to be logged in to leave comments. Login now