-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.py
53 lines (40 loc) · 1.35 KB
/
item.py
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
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
class Item(object):
def __init__(self, parent_item=None, dictionary={}):
self._dict = dictionary
self._parent_item = parent_item
self._children = []
def child(self, row):
if row > len(self._children):
return None
return self._children[row]
def child_count(self):
return len(self._children)
def children(self):
return self._children
def clear(self, column=None):
if column is None:
self._dict = {}
return
if column in set(self._dict):
del self._dict[column]
def data(self, column):
if column in self._dict:
return self._dict[column]
return None
def insert_children(self, row, count):
self._children[row:row+count-1] = [ Item(self, {}) for i in range(count) ]
def parent(self):
return self._parent_item
def remove_children(self, row, count):
del self._children[row:row+count]
def row(self):
if self._parent_item:
return self._parent_item._children.index(self)
return 0
def set_data(self, column, data):
self._dict[column] = data
def set_dict(self, _dict):
self._dict = _dict
def to_dict(self):
return self._dict