Пример #1
0
 def __getitem__(self, key):
     """Adds slicing access to cell code retrieval
     
     The cells are returned as a generator of generators, of ... of unicode.
     
     Parameters
     ----------
     key: n-tuple of integer or slice
     \tKeys of the cell code that is returned
     
     Note
     ----
     Classical Excel type addressing (A$1, ...) may be added here
     
     """
     
     for key_ele in key:
         if is_slice_like(key_ele):
             # We have something slice-like here 
             
             return self.cell_array_generator(key)
             
         elif is_string_like(key_ele):
             # We have something string-like here 
             
             raise NotImplementedError, \
                   "Cell string based access not implemented"
             
     # key_ele should be a single cell
     
     return self.dict_grid[key]
Пример #2
0
 def __setitem__(self, key, value):
     """Accepts index and slice keys"""
     
     single_keys_per_dim = []
     
     for axis, key_ele in enumerate(key):
         if is_slice_like(key_ele):
             # We have something slice-like here 
             
             single_keys_per_dim.append(slice_range(key_ele, 
                                                    length = key[axis]))
             
         elif is_string_like(key_ele):
             # We have something string-like here 
             
             raise NotImplementedError
         
         else:
             # key_ele is a single cell
             
             single_keys_per_dim.append((key_ele, ))
     
     single_keys = product(*single_keys_per_dim)
     
     unredo_mark = False
     
     for single_key in single_keys:
         if value:
             # UnRedo support
             
             old_value = self(key)
             
             # We seem to have double calls on __setitem__
             # This hack catches them
             
             if old_value != value:
             
                 unredo_mark = True
             
                 undo_operation = (self.__setitem__, [key, old_value])
                 redo_operation = (self.__setitem__, [key, value])
     
                 self.unredo.append(undo_operation, redo_operation)
                 
                 # End UnRedo support
             
             self.dict_grid[single_key] = value
         else:
             # Value is empty --> delete cell
             try:
                 self.dict_grid.pop(key)
                 
             except (KeyError, TypeError):
                 pass
                 
     if unredo_mark:
         self.unredo.mark()