##// END OF EJS Templates
history partway there. render_error fixes for cocoa frontend
Barry Wark -
Show More
@@ -29,6 +29,7 b' import uuid'
29 from Foundation import NSObject, NSMutableArray, NSMutableDictionary,\
29 from Foundation import NSObject, NSMutableArray, NSMutableDictionary,\
30 NSLog, NSNotificationCenter, NSMakeRange,\
30 NSLog, NSNotificationCenter, NSMakeRange,\
31 NSLocalizedString, NSIntersectionRange
31 NSLocalizedString, NSIntersectionRange
32
32 from AppKit import NSApplicationWillTerminateNotification, NSBeep,\
33 from AppKit import NSApplicationWillTerminateNotification, NSBeep,\
33 NSTextView, NSRulerView, NSVerticalRuler
34 NSTextView, NSRulerView, NSVerticalRuler
34
35
@@ -181,17 +182,26 b' class IPythonCocoaController(NSObject, FrontEndBase):'
181 if(self.is_complete(self.currentBlock())):
182 if(self.is_complete(self.currentBlock())):
182 self.execute(self.currentBlock(),
183 self.execute(self.currentBlock(),
183 blockID=self.currentBlockID)
184 blockID=self.currentBlockID)
184 self.currentBlockID = self.nextBlockID()
185 self.startNewBlock()
186
185 return True
187 return True
186
188
187 return False
189 return False
188
190
189 elif(selector == 'moveUp:'):
191 elif(selector == 'moveUp:'):
190 self.replaceCurrentBlockWithString(textView, self.get_history_item_previous(self.currentBlock()))
192 prevBlock = self.get_history_previous(self.currentBlock())
193 if(prevBlock != None):
194 self.replaceCurrentBlockWithString(textView, prevBlock)
195 else:
196 NSBeep()
191 return True
197 return True
192
198
193 elif(selector == 'moveDown:'):
199 elif(selector == 'moveDown:'):
194 self.replaceCurrentBlockWithString(textView, self.get_history_item_next(self.currentBlock()))
200 nextBlock = self.get_history_next(self.currentBlock())
201 if(nextBlock != None):
202 self.replaceCurrentBlockWithString(textView, nextBlock)
203 else:
204 NSBeep()
195 return True
205 return True
196
206
197 elif(selector == 'moveToBeginningOfParagraph:'):
207 elif(selector == 'moveToBeginningOfParagraph:'):
@@ -265,6 +275,13 b' class IPythonCocoaController(NSObject, FrontEndBase):'
265 return (completions,0)
275 return (completions,0)
266
276
267
277
278 def startNewBlock(self):
279 """"""
280
281 self.currentBlockID = self.nextBlockID()
282
283
284
268 def nextBlockID(self):
285 def nextBlockID(self):
269
286
270 return uuid.uuid4()
287 return uuid.uuid4()
@@ -312,7 +329,8 b' class IPythonCocoaController(NSObject, FrontEndBase):'
312
329
313
330
314 def render_error(self, failure):
331 def render_error(self, failure):
315 self.insert_text(str(failure))
332 self.insert_text('\n\n'+str(failure)+'\n\n')
333 self.startNewBlock()
316 return failure
334 return failure
317
335
318
336
@@ -344,6 +362,7 b' class IPythonCocoaController(NSObject, FrontEndBase):'
344 def replaceCurrentBlockWithString(self, textView, string):
362 def replaceCurrentBlockWithString(self, textView, string):
345 textView.replaceCharactersInRange_withString_(self.currentBlockRange(),
363 textView.replaceCharactersInRange_withString_(self.currentBlockRange(),
346 string)
364 string)
365 self.currentBlockRange().length = len(string)
347 r = NSMakeRange(textView.textStorage().length(), 0)
366 r = NSMakeRange(textView.textStorage().length(), 0)
348 textView.scrollRangeToVisible_(r)
367 textView.scrollRangeToVisible_(r)
349 textView.setSelectedRange_(r)
368 textView.setSelectedRange_(r)
@@ -20,16 +20,15 b' __docformat__ = "restructuredtext en"'
20 #-------------------------------------------------------------------------------
20 #-------------------------------------------------------------------------------
21 import string
21 import string
22 import uuid
22 import uuid
23 import _ast
23
24
25 import zope.interface as zi
24
26
25 from IPython.kernel.core.history import FrontEndHistory
27 from IPython.kernel.core.history import FrontEndHistory
26 from IPython.kernel.core.util import Bunch
28 from IPython.kernel.core.util import Bunch
27
28 from IPython.kernel.engineservice import IEngineCore
29 from IPython.kernel.engineservice import IEngineCore
29
30
30 import zope.interface as zi
31 from twisted.python.failure import Failure
31
32 import _ast
33
32
34 ##############################################################################
33 ##############################################################################
35 # TEMPORARY!!! fake configuration, while we decide whether to use tconfig or
34 # TEMPORARY!!! fake configuration, while we decide whether to use tconfig or
@@ -115,11 +114,11 b' class IFrontEnd(zi.Interface):'
115 pass
114 pass
116
115
117
116
118 def get_history_item_previous(currentBlock):
117 def get_history_previous(currentBlock):
119 """Returns the block previous in the history."""
118 """Returns the block previous in the history."""
120 pass
119 pass
121
120
122 def get_history_item_next(currentBlock):
121 def get_history_next(currentBlock):
123 """Returns the next block in the history."""
122 """Returns the next block in the history."""
124
123
125 pass
124 pass
@@ -226,38 +225,52 b' class FrontEndBase(object):'
226 Result:
225 Result:
227 Deferred result of self.interpreter.execute
226 Deferred result of self.interpreter.execute
228 """
227 """
229 # if(not isinstance(block, _ast.AST)):
228
230 # block = self.compile_ast(block)
229 if(not self.is_complete(block)):
230 return Failure(Exception("Block is not compilable"))
231
231
232 if(blockID == None):
232 if(blockID == None):
233 blockID = uuid.uuid4() #random UUID
233 blockID = uuid.uuid4() #random UUID
234
234
235 d = self.engine.execute(block)
235 d = self.engine.execute(block)
236 d.addCallback(self._add_block_id, blockID)
236 d.addCallback(self._add_block_id, blockID)
237 d.addCallback(self._add_history, block=block)
237 d.addCallback(self.update_cell_prompt)
238 d.addCallback(self.update_cell_prompt)
238 d.addCallbacks(self.render_result, errback=self.render_error)
239 d.addCallbacks(self.render_result, errback=self.render_error)
239
240
240 return d
241 return d
241
242
243
242 def _add_block_id(self, result, blockID):
244 def _add_block_id(self, result, blockID):
243 """add_block_id"""
245 """Add the blockID to result"""
244
246
245 result['blockID'] = blockID
247 result['blockID'] = blockID
246
248
247 return result
249 return result
248
250
251 def _add_history(self, result, block=None):
252 """Add block to the history"""
253
254 assert(block != None)
255 self.history.add_items([block])
256 self.history_cursor += 1
257
258 return result
259
249
260
250 def get_history_item_previous(self, currentBlock):
261 def get_history_previous(self, currentBlock):
251 """ Returns previous history string and decrement history cursor.
262 """ Returns previous history string and decrement history cursor.
252 """
263 """
264 print self.history
253 command = self.history.get_history_item(self.history_cursor - 1)
265 command = self.history.get_history_item(self.history_cursor - 1)
266 print command
254 if command is not None:
267 if command is not None:
255 self.history.input_cache[self.history_cursor] = currentBlock
268 self.history.input_cache[self.history_cursor] = currentBlock
256 self.history_cursor -= 1
269 self.history_cursor -= 1
257 return command
270 return command
258
271
259
272
260 def get_history_item_next(self, currentBlock):
273 def get_history_next(self, currentBlock):
261 """ Returns next history string and increment history cursor.
274 """ Returns next history string and increment history cursor.
262 """
275 """
263 command = self.history.get_history_item(self.history_cursor + 1)
276 command = self.history.get_history_item(self.history_cursor + 1)
General Comments 0
You need to be logged in to leave comments. Login now