summaryrefslogtreecommitdiffstats
path: root/itemList.py
blob: 625294619db65576abd0ba9c1fe606ed017f63e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-

class itemList:
    def __init__(self, observer):
        self.data = []
        self.observer = observer

    def __len__(self):
        return len(self.data)

    def __getitem__(self, idx):
        return self.data[idx]

    def __setitem__(self, idx, item):
        self.data[idx] = item

    def append(self, item):
        item.observer = self
        self.data.append(item)
        self.observer.notifyChange(item)

    def notifyChange(self, sender):
        self.observer.notifyChange(sender)

    def __add__(self, item):
        self.append(item)
        return self

    def __iter__(self):
        return self.data.__iter__()