Changeset 1063


Ignore:
Timestamp:
11/18/08 16:37:46 (5 years ago)
Author:
fma
Message:

Code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/papywizard/model/scan.py

    r1060 r1063  
    6363 
    6464    Scan is the base object for shooting object. 
    65  
    66     >>> scan = Scan() 
    67     >>> for yaw, pitch in scan.iterPositions(): 
    68     ...     print yaw, pitch 
    6965    """ 
    7066    def __init__(self, model): 
     
    9288    totalNbPicts = property(__getTotalNbPicts) 
    9389 
     90    # Helpers 
     91    def _iterPositions(self): 
     92        """ Real iteration over all shooting positions. 
     93        """ 
     94        self._index = 0 
     95        while True: 
     96            try: 
     97                yield self._index + 1, self._positions[self._index] 
     98            except IndexError: 
     99                raise StopIteration 
     100            self._index += 1 
     101 
     102 
    94103    # Interface 
    95104    def iterPositions(self): 
    96105        """ Iterate over all (yaw, pitch) positions. 
     106 
     107        We first generate all positions, and then iterate over that list. 
     108        This way, it is possible to change the current index, to change 
     109        the sequence. 
    97110        """ 
    98111        raise NotImplementedError 
     
    248261    #Interface 
    249262    def iterPositions(self): 
    250         """ Iterate over all (yaw, pitch) positions. 
    251  
    252         We first generate all positions, and then iterate over that list. 
    253         This way, it is possible to change the current index, to change 
    254         the sequence. 
    255         """ 
    256263 
    257264        # Generate all positions 
     
    348355 
    349356        # Iterate over positions 
    350         self._index = 0 
    351         while True: 
    352             try: 
    353                 yield self._index + 1, self._positions[self._index] 
    354             except IndexError: 
    355                 raise StopIteration 
    356             self._index += 1 
     357        return self._iterPositions() 
    357358 
    358359 
     
    387388    # Interface 
    388389    def iterPositions(self): 
     390 
     391        # Generate positions 
     392        self._positions = [] 
    389393        preset = self.__presets.getByName(self.name) 
    390394        Logger().debug("PresetScan.__init__(): preset=%s" % preset) 
    391         positions = preset.getPositions() 
    392         for yaw, pitch in positions: 
    393             yield yaw, pitch 
    394         raise StopIteration 
     395        self._positions = preset.getPositions() 
     396 
     397        # Iterate over positions 
     398        return self._iterPositions() 
Note: See TracChangeset for help on using the changeset viewer.