-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameLayout.py
More file actions
116 lines (86 loc) · 3.97 KB
/
FrameLayout.py
File metadata and controls
116 lines (86 loc) · 3.97 KB
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
from PyQt4 import QtGui, QtCore
class FrameLayout(QtGui.QWidget):
def __init__(self, parent=None, title=None):
QtGui.QFrame.__init__(self, parent=parent)
self._is_collasped = True
self._title_frame = None
self._content, self._content_layout = (None, None)
self._main_v_layout = QtGui.QVBoxLayout(self)
self._main_v_layout.addWidget(self.initTitleFrame(title, self._is_collasped))
self._main_v_layout.addWidget(self.initContent(self._is_collasped))
self.initCollapsable()
def initTitleFrame(self, title, collapsed):
self._title_frame = self.TitleFrame(title=title, collapsed=collapsed)
return self._title_frame
def initContent(self, collapsed):
self._content = QtGui.QWidget()
self._content_layout = QtGui.QVBoxLayout()
self._content.setLayout(self._content_layout)
self._content.setVisible(not collapsed)
return self._content
def addWidget(self, widget):
self._content_layout.addWidget(widget)
def initCollapsable(self):
QtCore.QObject.connect(self._title_frame, QtCore.SIGNAL('clicked()'), self.toggleCollapsed)
def getWidget(self):
items = (self._content_layout.itemAt(i) for i in range(self._content_layout.count()))
return items
def toggleCollapsed(self):
self._content.setVisible(self._is_collasped)
self._is_collasped = not self._is_collasped
self._title_frame._arrow.setArrow(int(self._is_collasped))
############################
# TITLE #
############################
class TitleFrame(QtGui.QFrame):
def __init__(self, parent=None, title="", collapsed=False):
QtGui.QFrame.__init__(self, parent=parent)
self.setMinimumHeight(24)
self.move(QtCore.QPoint(24, 0))
self.setStyleSheet("border:1px solid rgb(41, 41, 41); ")
self._hlayout = QtGui.QHBoxLayout(self)
self._hlayout.setContentsMargins(0, 0, 0, 0)
self._hlayout.setSpacing(0)
self._arrow = None
self._title = None
self._hlayout.addWidget(self.initArrow(collapsed))
self._hlayout.addWidget(self.initTitle(title))
def initArrow(self, collapsed):
self._arrow = FrameLayout.Arrow(collapsed=collapsed)
self._arrow.setStyleSheet("border:0px")
return self._arrow
def initTitle(self, title=None):
self._title = QtGui.QLabel(title)
self._title.setMinimumHeight(24)
self._title.move(QtCore.QPoint(24, 0))
self._title.setStyleSheet("border:0px")
return self._title
def mousePressEvent(self, event):
self.emit(QtCore.SIGNAL('clicked()'))
return super(FrameLayout.TitleFrame, self).mousePressEvent(event)
#############################
# ARROW #
#############################
class Arrow(QtGui.QFrame):
def __init__(self, parent=None, collapsed=False):
QtGui.QFrame.__init__(self, parent=parent)
self.setMaximumSize(24, 24)
# horizontal == 0
self._arrow_horizontal = (QtCore.QPointF(7.0, 8.0), QtCore.QPointF(17.0, 8.0), QtCore.QPointF(12.0, 13.0))
# vertical == 1
self._arrow_vertical = (QtCore.QPointF(8.0, 7.0), QtCore.QPointF(13.0, 12.0), QtCore.QPointF(8.0, 17.0))
# arrow
self._arrow = None
self.setArrow(int(collapsed))
def setArrow(self, arrow_dir):
if arrow_dir:
self._arrow = self._arrow_vertical
else:
self._arrow = self._arrow_horizontal
def paintEvent(self, event):
painter = QtGui.QPainter()
painter.begin(self)
painter.setBrush(QtGui.QColor(192, 192, 192))
painter.setPen(QtGui.QColor(64, 64, 64))
painter.drawPolygon(*self._arrow)
painter.end()