def __init__(self, capacity, name=None, parent=None): super(Carrousel, self).__init__(name=name, parent=parent) # Container is empty self._container = [None] * capacity self._capacity = capacity self._pos = 0 # object in the current position self._current = self._container[self._pos] # signals self.changed = Signal() self.moved = Signal()
class Carrousel(ContainerDevice): def __init__(self, capacity, name=None, parent=None): super(Carrousel, self).__init__(name=name, parent=parent) # Container is empty self._container = [None] * capacity self._capacity = capacity self._pos = 0 # object in the current position self._current = self._container[self._pos] # signals self.changed = Signal() self.moved = Signal() def current(self): return self._current def pos(self): return self._pos def put_in_pos(self, obj, pos): if pos >= self._capacity or pos < 0: raise ValueError('position greater than capacity or negative') self._container[pos] = obj self._current = self._container[self._pos] def move_to(self, pos): if pos >= self._capacity or pos < 0: raise ValueError('Position %d out of bounds' % pos) if pos != self._pos: self._pos = pos self._current = self._container[self._pos] self.changed.emit(self._pos) self.moved.emit(self._pos) def select(self, name): # find pos of object with name for idx, item in enumerate(self._container): if item: if isinstance(item, basestring): if item == name: return self.move_to(idx) elif item.name == name: return self.move_to(idx) else: pass else: raise ValueError('No object named %s' % name) def config_info(self): if self._current: if isinstance(self._current, basestring): label = self._current else: label = self._current.name else: label = 'Unknown' return {'name': self.name, 'position': self._pos, 'label': label} def configure(self, meta): self.move_to(meta)