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