Changeset 910

Show
Ignore:
Timestamp:
10/01/05 17:02:06 (3 years ago)
Author:
tzanko
Message:

Added some tools for automatic testing and wrote some more of the tutorial. More info in the ChangeLog

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nbshell/trunk/ChangeLog

    r860 r910  
     12005-10-02  Tzanko Matev  <tsanko@gmail.com> 
     2 
     3    * testtools.py: Added some tools for automatic testing of 
     4    functions. See the documentation of testtools.reverse_verifier for 
     5    more info and Sheet.InsertCell for an example of how to use them. 
     6    Also fixed a small bug in the xxxNotebookViewPlugin.Close() 
     7    methods of all plugins which was found when I added the 
     8    verification to InsertCell 
     9 
     10    * tutorial.pybk: Changed the tutorial to an ordinary notebook and 
     11    added some more text. The old tutorial is in old_tutorial.pybk. I 
     12    did this because the old tutorial was too confusing for novice 
     13    users (as Robert pointed out). 
     14 
    1152005-09-19  Robert Kern  <robert.kern@gmail.com> 
    216 
  • nbshell/trunk/nbshell/FigurePlugin.py

    r850 r910  
    201201        pass 
    202202     
    203     def Close(self, update=True): 
    204         """ This method is called when the document cell is 
    205         destroyed. It must close all windows. If update is false, do 
    206         not update the view""" 
    207         index = self.view.GetIndex(self.id) 
    208         self.view.DeleteCell(index, update) 
    209          
     203    def Close(self, update = True): 
     204        if self.window is not None: 
     205            index = self.view.GetIndex(self.id) 
     206            self.view.DeleteCell(index, update) 
     207 
    210208    position = property(fget = lambda :0, fset = lambda x:None) 
    211209 
  • nbshell/trunk/nbshell/PlainTextPlugin.py

    r852 r910  
    308308         
    309309    def Close(self, update = True): 
    310         index = self.view.GetIndex(self.id) 
    311         self.view.DeleteCell(index, update) 
     310        if self.window is not None: 
     311            index = self.view.GetIndex(self.id) 
     312            self.view.DeleteCell(index, update) 
    312313     
    313314    def InsertCode(self): 
  • nbshell/trunk/nbshell/PythonPlugin.py

    r850 r910  
    822822         
    823823    def Close(self, update = True): 
    824         index = self.view.GetIndex(self.id) 
    825         self.view.DeleteCell(index, update) 
     824        if self.window is not None: 
     825            index = self.view.GetIndex(self.id) 
     826            self.view.DeleteCell(index, update) 
    826827         
    827828    def Copy(self): 
  • nbshell/trunk/nbshell/Sheet.py

    r852 r910  
    2323from nbshell.utils import * 
    2424from nbshell import SimpleXMLWriter 
     25 
     26from nbshell import testtools 
    2527 
    2628 
     
    7274            cell.view.SetFocus() 
    7375    currentcell = property(fget = __get_current_cell, fset = __set_current_cell) 
     76 
     77    def DeleteCell(self, cell, update = True): 
     78        """Deletes a given element in celllist""" 
     79        #Change the current cell if necessary 
     80        if self.currentcell == cell: 
     81            if cell.index < len(self.celllist) -1: 
     82                self.currentcell = self.celllist[cell.index+1] 
     83            elif cell.index>0: 
     84                self.currentcell = self.celllist[cell.index-1] 
     85            else: 
     86                self.currentcell = None 
     87                                       
     88         
     89        cell.view.Close(update = False) 
     90        index = cell.index 
     91        self.__del_cell(cell.index) 
     92        self.Update(update = False, dicts = True) 
     93 
     94        #Concatenate the prevoius and the next cells if they are of the same 
     95        #type 
     96        if index > 0 and index < len(self.celllist) and\ 
     97           self.celllist[index-1].type == self.celllist[index].type: 
     98            if self.celllist[index-1].Concat(self.celllist[index]): 
     99                self.DeleteCell(self.celllist[index], update =False) 
     100         
     101        self.Update(update) 
    74102     
     103    @testtools.verify 
     104    @testtools.reverse_decorator(DeleteCell, "[x.type for x in self.celllist]", 
     105                                 "{'self':self, 'cell':self.celllist[pos], 'update':update}", 
     106                                 "[x.type for x in self.celllist]") 
    75107    def InsertCell(self, type, pos=-1, update = True, **kwds): 
    76108        """Inserts a cell of the given type with the given data at the given 
     
    93125        return cell 
    94126     
    95     def DeleteCell(self, cell, update = True): 
    96         """Deletes a given element in celllist""" 
    97         #Change the current cell if necessary 
    98         if self.currentcell == cell: 
    99             if cell.index < len(self.celllist) -1: 
    100                 self.currentcell = self.celllist[cell.index+1] 
    101             elif cell.index>0: 
    102                 self.currentcell = self.celllist[cell.index-1] 
    103             else: 
    104                 self.currentcell = None 
    105                                        
    106          
    107         cell.view.Close(update = False) 
    108         index = cell.index 
    109         self.__del_cell(cell.index) 
    110         self.Update(update = False, dicts = True) 
    111  
    112         #Concatenate the prevoius and the next cells if they are of the same 
    113         #type 
    114         if index > 0 and index < len(self.celllist) and\ 
    115            self.celllist[index-1].type == self.celllist[index].type: 
    116             if self.celllist[index-1].Concat(self.celllist[index]): 
    117                 self.DeleteCell(self.celllist[index], update =False) 
    118          
    119         self.Update(update) 
    120  
    121     def __del_text_cell(self,cell,update = False): 
    122         """Deletes the given text cell. Does not check if this is the first or 
    123         last text cell""" 
    124         #TODO: write this 
    125         return 
    126          
    127     def __del_code_cell(self,cell,update = False): 
    128         #TODO: write this 
    129         return 
    130  
    131127    def Update(self, update = True, celllist = False, dicts = False, output = False): 
    132128         
     
    311307                            #This is a simple match, create the block, giving the 
    312308                            #element as a parameter 
     309                            print dir(self) 
    313310                            self.InsertCell(plugin_string, update=False, element = child) 
    314311                            #get the next element 
  • nbshell/trunk/nbshell/textplugin.py

    r850 r910  
    306306            return False 
    307307    modified = property(fget = IsModified) 
    308          
     308 
    309309    def Close(self, update = True): 
    310         index = self.view.GetIndex(self.id) 
    311         self.view.DeleteCell(index, update) 
    312      
     310        if self.window is not None: 
     311            index = self.view.GetIndex(self.id) 
     312            self.view.DeleteCell(index, update) 
     313 
    313314    def InsertCode(self): 
    314315        #self.doc.text = self.window.GetText() 
  • nbshell/trunk/nbshell/utils.py

    r823 r910  
    138138    global oldtime 
    139139    t0 = 0 
     140