summaryrefslogtreecommitdiffstats
path: root/itemList.py
blob: 7dc2944277425eb9b331e4206809ee87327deea7 (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
31
32
33
34
35
36
37
38
39
40
41
# -*- 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 __delitem__(self, key):
        self.date[key].removed = True
        self.data.__delitem__(key)

    def remove(self, item):
        item.removed = True
        self.data.remove(item)
        
    def __contians__(self, item):
        return (item in self.data)

    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__()