Changeset 836
- Timestamp:
- 09/13/05 12:05:34 (3 years ago)
- Files:
-
- nbshell/trunk/ChangeLog (modified) (1 diff)
- nbshell/trunk/nbshell/IPythonLog.py (modified) (2 diffs)
- nbshell/trunk/nbshell/PythonPlugin.py (modified) (8 diffs)
- nbshell/trunk/nbshell/PythonWidget.py (modified) (4 diffs)
- nbshell/trunk/nbshell/frame.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nbshell/trunk/ChangeLog
r835 r836 1 2005-09-13 Tzanko Matev <tsanko@gmail.com> 2 3 * IPythonLog.py (IPythonLog.filename_iter): Changed generation of 4 figure names to avoid 'filename.nbk_1.png' names. This resolves 5 ticket #29. 6 7 * PythonPlugin.py (PythonNotebookViewPlugin): 8 * PythonWidget.py (Shell.OnKeyDown): Added history. The user can 9 access it using Ctrl-Up/Alt-P, Ctrl-Down/Alt-N. This resolves 10 ticket #12. 11 12 * PythonPlugin.py (PythonNotebookView.Update, PromptLen, CanEdit): 13 Added a variable self.promptlens, which contains the lenghts of 14 the prompts and is generated when Update is called. This slightly 15 optimizes PromptLen and CanEdit. Added other small optimisations 16 to CanEdit. As a result typing should get a bit faster. See ticket 17 #11 for more info. 18 19 1 20 2005-09-12 Tzanko Matev <tsanko@gmail.com> 2 21 nbshell/trunk/nbshell/IPythonLog.py
r823 r836 13 13 __version__ = Release.version 14 14 15 import os.path 15 16 import sys 16 17 import StringIO … … 114 115 """A generator function used for generating unique figure filenames""" 115 116 counter = 1 116 fn = self.doc.fileinfo['path'] + '/' + self.doc.fileinfo['name']117 fn = self.doc.fileinfo['path'] + '/' + os.path.splitext(self.doc.fileinfo['name'])[0] 117 118 while True: 118 119 yield "%s_%d.png"%(fn,counter) nbshell/trunk/nbshell/PythonPlugin.py
r835 r836 97 97 self.view = None #This plugin is designed for a single view. For 98 98 #multiple views there should be some modifications 99 print "block:"99 #print "block:" #dbg 100 100 #etree.dump(self.element) #dbg 101 101 self.cells = [self.log.log[int(x.attrib['number'])] for x in element] … … 185 185 self.prompt_in_tpl = 'In [%s]: ' 186 186 self.prompt_out_tpl = 'Out[%s]: ' 187 188 self.hist_max_len = 666 #TODO: This must go in some configuration file 189 self.history = [] #FIFO of at most self.hist_max_len strings 190 self.hist_current = None #Index of the curret history item 191 192 def add_to_history(self, line = None): 193 """Adds the line to the history. If line is None gets the current line 194 from the window""" 195 if line is None: 196 linenum = self.window.GetCurrentLine() 197 line = self.window.GetLine(linenum)[self.promptlens[self.line2log[linenum][0]]:] 198 199 if line: #We don't need empty lines 200 self.history.append(line) 201 l = len(self.history) 202 if l > self.hist_max_len: 203 del(self.history[0]) 204 self.hist_current = l-1 205 206 def get_hist_item(self, dir= -1): 207 """Gets the next previous line from the history if dir<0 or the next 208 line if dir>0. If the history is empty return None""" 209 210 dir = dir/abs(dir) 211 if self.hist_current is None: 212 return None 213 self.hist_current+=dir 214 l = len(self.history) 215 if self.hist_current == l: 216 self.hist_current = 0 217 elif self.hist_current < 0: 218 self.hist_current = l-1 219 220 return self.history[self.hist_current] 221 222 def hist_replace(self, dir): 223 """Replaces the current line with prevoius (dir<0) or next (dir>0) 224 line from the history""" 225 226 t = self.get_hist_item(dir) 227 if not t: 228 return 229 230 pos = self.window.GetCurrentPos() 231 linenum = self.window.LineFromPosition(pos) 232 233 if not self.CanEdit(pos = pos, line = linenum): 234 return None 235 236 startpos = self.window.PositionFromLine(linenum) +\ 237 self.promptlens[self.line2log[linenum][0]] 238 endpos = self.window.GetLineEndPosition(linenum) 239 240 self.window.SetTargetStart(startpos) 241 self.window.SetTargetEnd(endpos) 242 self.window.ReplaceTarget(t) 243 187 244 188 245 def SetFocus(self): … … 307 364 # Here we set up the text which will be displayed in the window 308 365 outtext = StringIO.StringIO() 366 #self.promptlen[i] holds the length of the prompt of cell i 367 self.promptlens = [] 309 368 for i, cell in enumerate(cells): 310 369 number = cell.number … … 348 407 for j in range(len(lines)): 349 408 l2l_append((i, j+1)) 409 410 #set up self.promptlens 411 self.promptlens.append(len(prompt)) 350 412 #print "i -> %s, id->%s, type->%s, text->%s"%(str(i), str(id), str(type), str(text)) 351 413 #oldlinecnt = linecnt … … 398 460 if line is None: #a separator line 399 461 return 0 400 462 return self.promptlens[line[0]] 401 463 #if line[1] != 1: #currently only the first line of a block is indented and has a prompt 402 464 # return 0 403 465 404 466 #get the number of digits of the number of the input 405 item = self.doc.element[line[0]]406 type = self.doc.GetStuff(line[0])[0]407 strnumber = item.attrib['number']408 return len(self.GetPrompt(type, strnumber, line[1] == 1))467 #item = self.doc.element[line[0]] 468 #type = self.doc.GetStuff(line[0])[0] 469 #strnumber = item.attrib['number'] 470 #return len(self.GetPrompt(type, strnumber, line[1] == 1)) 409 471 410 472 def UpdateDoc(self): … … 541 603 # return False 542 604 #Check if the current cell is an input cell 543 if self.doc.GetStuff(id)[0] in ['input', 'special']: 544 return True 545 else: 546 return False 547 548 def CanEdit(self, oper = 'insert', pos = None): 605 return self.doc.element[id].attrib['type'] in ['input', 'special'] 606 607 def CanEdit(self, oper = 'insert', pos = None, line = None): 549 608 """Return true if the given editing operation should succeed at the 550 609 given position if pos is None use the current position. oper can be … … 561 620 562 621 pos = pos or self.window.GetCurrentPos() 563 line = self.window.LineFromPosition(pos) 564 565 #Check if the current line is editable 566 if not self.CanEditLine(line): 622 #This is for optimization 623 line = line or self.window.LineFromPosition(pos) 624 l2l = self.line2log 625 #Check if the current line is editable. self.CanEditLine does the same 626 #as the code below. It is not called for optimization 627 id = l2l[line] 628 if id is None: 629 return False 630 id = id[0] 631 if not self.doc.element[id].attrib['type'] in ['input', 'special']: 567 632 return False 568 633 … … 576 641 if oper == 'delete' and self.window.GetCharAt(pos) == ord('\n'): 577 642 #Check if the next line belongs to the same input 578 l = len( self.line2log)579 return (line +1 < l and self.line2log[line+1] is not None and580 self.line2log[line+1][0] == self.line2log[line][0])643 l = len(l2l) 644 return (line +1 < l and l2l[line+1] is not None and 645 l2l[line+1][0] == l2l[line][0]) 581 646 elif oper == 'backspace': 582 647 #Check if this is the first line 583 return pos > startpos + promptlen or self.line2log[line][1] > 1648 return pos > startpos + promptlen or l2l[line][1] > 1 584 649 else: 585 650 return True nbshell/trunk/nbshell/PythonWidget.py
r823 r836 266 266 if not shiftDown and not controlDown and key == wx.WXK_RETURN: 267 267 if self.view.CanEdit(): 268 self.view.add_to_history() 268 269 self.view.InsertLineBreak() 269 270 #Shift-Return, (Shift-Enter) is used to execute the current input … … 271 272 if self.CallTipActive(): 272 273 self.CallTipCancel() 274 self.view.add_to_history() 273 275 self.view.ProcessLine() 274 276 #Ctrl-Return will reexecute the current input and all cells after it … … 276 278 if self.CallTipActive(): 277 279 self.CallTipCancel() 280 self.view.add_to_history() 278 281 self.view.ProcessLine(flag = True) 279 282 … … 351 354 # self.PasteAndRun() 352 355 # Replace with the previous command from the history buffer. 353 #elif (controlDown and key == wx.WXK_UP) \354 #or (altDown and key in (ord('P'), ord('p'))):355 # self.OnHistoryReplace(step=+1)356 elif (controlDown and key == wx.WXK_UP) \ 357 or (altDown and key in (ord('P'), ord('p'))): 358 self.view.hist_replace(dir=-1) 356 359 # Replace with the next command from the history buffer. 357 #elif (controlDown and key == wx.WXK_DOWN) \358 #or (altDown and key in (ord('N'), ord('n'))):359 # self.OnHistoryReplace(step=-1)360 elif (controlDown and key == wx.WXK_DOWN) \ 361 or (altDown and key in (ord('N'), ord('n'))): 362 self.view.hist_replace(dir=+1) 360 363 # Insert the previous command from the history buffer. 361 364 #elif (shiftDown and key == wx.WXK_UP) and self.view.CanEdit(): nbshell/trunk/nbshell/frame.py
r835 r836 128 128 menu.Append(filemenu, "&File") 129 129 menu.Append(insertmenu, "&Insert") 130 menu.Append(nbshellmenu, " &NBShell")130 menu.Append(nbshellmenu, "N&BShell") 131 131 self.SetMenuBar(menu) 132 132
