Add QML UI for displaying the overview
[pywienerlinien] / history.py
1 import os
2
3 class History(list):
4
5     def __init__(self, hist_file, *args, **kwargs):
6         if os.path.isfile(hist_file):
7             f = open(hist_file, 'r')
8             h = map(lambda x: x.strip(), f.readlines())
9             f.close()
10             self._file = open(hist_file, 'a')
11         else:
12             self._file = open(hist_file, 'a')
13             h = []
14
15         list.__init__(self, h, *args, **kwargs)
16
17     def __add__(self, item):
18         if not item in self:
19             super(History, self).__add__(item)
20             self._file.write('%s\n' % item)
21             self._file.flush()
22
23     def insert(self, index, item):
24         if not item in self:
25             super(History, self).insert(index, item)
26             self._file.write('%s\n' % item)
27             self._file.flush()
28
29     def __delitem__(self, item):
30         super(History, self).__deltitem(item)
31         self._file.write('%s\n' % item)
32         self._file.flush()
33         self._file.close()
34
35     def close(self):
36         self._file.close()