/
ItemList.py
156 lines (110 loc) · 4.26 KB
/
ItemList.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from PyQt4 import QtCore, QtGui
class ListCheckBox(QtGui.QCheckBox):
listChkBoxStateChanged = QtCore.pyqtSignal(object)
def __init__(self, modelIndex, chkBoxType):
super(ListCheckBox, self).__init__()
self.modelIndex = modelIndex
self.chkBoxType = chkBoxType
self.stateChanged.connect(self.chkBoxStateChanged)
def chkBoxStateChanged(self, state):
self.listChkBoxStateChanged.emit([self.modelIndex, self.chkBoxType, state])
class ColorButton(QtGui.QPushButton):
colorChanged = QtCore.pyqtSignal(object)
def __init__(self, modelIndex, color = None):
super(ColorButton, self).__init__()
self.modelIndex = modelIndex
self.color = color
if self.color:
self.setColor(self.color)
self.pressed.connect(self.colorDialog)
def setColor(self, color):
if color != self.color:
self.color = color
self.colorChanged.emit([self.modelIndex, 'color', self.color])
if self.color:
self.setStyleSheet('background-color: %s;' % self.color.name())
else:
self.setStyleSheet('')
def colorDialog(self):
dlg = QtGui.QColorDialog()
if self.color:
dlg.setCurrentColor(QtGui.QColor(self.color))
if dlg.exec_():
self.setColor(dlg.currentColor())
class ItemList(QtGui.QTreeWidget):
itemListPick = QtCore.pyqtSignal()
itemConfigChanged = QtCore.pyqtSignal(object)
def __init__(self, screen):
super(ItemList, self).__init__(parent = screen)
self.screen = screen
self.itemClicked.connect(self.itemClickedHandler)
self.setFocusPolicy(QtCore.Qt.NoFocus)
self.initUI()
def initUI(self):
self.setColumnCount(6)
labels = ['Name', 'Draw', 'Graph', 'Traj', 'Tag', 'Color']
self.setHeaderLabels(labels)
self.setFixedWidth(300)
for i in range(1, 6):
self.setColumnWidth(i, 50)
self.setUniformRowHeights(True)
self.setAlternatingRowColors(True)
self.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
self.rootMarker = QtGui.QTreeWidgetItem(self)
self.rootMarker.setText(0, 'Markers')
self.rootGroup = QtGui.QTreeWidgetItem(self)
self.rootGroup.setText(0, 'Groups')
def getRootMarkerIndex(self):
return self.indexFromItem(self.rootMarker)
def clearPick(self):
self.clearSelection()
for i in range(self.rootMarker.childCount()):
self.rootMarker.child(i).setTextColor(0, QtGui.QColor(0, 0, 0, 255))
def setItemData(self, data):
if self.rootMarker.childCount() > 0:
self.clear()
self.rootMarker = QtGui.QTreeWidgetItem(self)
self.rootMarker.setText(0, 'Markers')
self.rootGroup = QtGui.QTreeWidgetItem(self)
self.rootGroup.setText(0, 'Groups')
frameData = data.getCurrentFrameData()
for i in range(frameData.GetItemNumber()):
pt = frameData.GetItem(i)
name = pt.GetLabel()
item = QtGui.QTreeWidgetItem(self.rootMarker)
item.setText(0, name)
index = self.indexFromItem(item)
maskDrawChkBox = ListCheckBox(index, 'draw')
maskDrawChkBox.setCheckState(QtCore.Qt.Checked)
maskGraphChkBox = ListCheckBox(index, 'graph')
maskTrajChkBox = ListCheckBox(index, 'traj')
maskTagChkBox = ListCheckBox(index, 'tag')
colorBtn = ColorButton(index)
maskDrawChkBox.listChkBoxStateChanged.connect(self.itemListStateChanged)
maskGraphChkBox.listChkBoxStateChanged.connect(self.itemListStateChanged)
maskTrajChkBox.listChkBoxStateChanged.connect(self.itemListStateChanged)
maskTagChkBox.listChkBoxStateChanged.connect(self.itemListStateChanged)
colorBtn.colorChanged.connect(self.itemListStateChanged)
self.setItemWidget(item, 1, maskDrawChkBox)
self.setItemWidget(item, 2, maskGraphChkBox)
self.setItemWidget(item, 3, maskTrajChkBox)
self.setItemWidget(item, 4, maskTagChkBox)
self.setItemWidget(item, 5, colorBtn)
self.clearPick()
self.itemListPick.emit()
def itemClickedHandler(self, item, column):
if item == self.rootMarker or item == self.rootGroup:
self.clearPick()
if self.isItemSelected(item):
item.setTextColor(0, QtGui.QColor(0, 180, 50, 150))
else:
item.setTextColor(0, QtGui.QColor(0, 0, 0, 255))
self.itemListPick.emit()
def mousePressEvent(self, event):
item = self.itemAt(event.pos())
if not item:
self.clearPick()
self.itemListPick.emit()
QtGui.QTreeWidget.mousePressEvent(self, event)
def itemListStateChanged(self, item):
self.itemConfigChanged.emit(item)