-
Notifications
You must be signed in to change notification settings - Fork 9
/
SpacerBrick.py
102 lines (79 loc) · 3.31 KB
/
SpacerBrick.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
'''
[Name]
[Description]
This brick ..
[Properties]
----------------------------------------------------------------------
| name | type | description
----------------------------------------------------------------------
| | |
| | |
| | |
----------------------------------------------------------------------
'''
from qt import *
from BlissFramework import BaseComponents
__category__ = 'GuiUtils'
class SpacerBrick(BaseComponents.BlissWidget):
def __init__(self, *args):
BaseComponents.BlissWidget.__init__(self, *args)
self.addProperty('direction', 'combo', ('horizontal', 'vertical'), 'horizontal')
self.addProperty('fixedSize', 'integer', 100)
self.addProperty('autoSize', 'boolean', False)
QHBoxLayout(self)
self.layoutItem = QSpacerItem(100, 100, QSizePolicy.Fixed, QSizePolicy.Fixed)
self.layout().addItem(self.layoutItem)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self._rowStretchFactor = 1000
self._colStretchFactor = 1000
def paintEvent(self, event):
if not self.isRunning():
p = QPainter(self)
p.setPen(QPen(Qt.black, 3))
if self['direction'] == 'horizontal':
h = self.height() / 2
p.drawLine(0, h, self.width(), h)
p.drawLine(0, h, 5, h - 5)
p.drawLine(0, h, 5, h + 5)
p.drawLine(self.width(), h, self.width() - 5, h - 5)
p.drawLine(self.width(), h, self.width() - 5, h + 5)
else:
w = self.width() / 2
p.drawLine(self.width() / 2, 0, self.width() / 2, self.height())
p.drawLine(w, 0, w - 5, 5)
p.drawLine(w, 0, w + 5, 5)
p.drawLine(w, self.height(), w - 5, self.height() - 5)
p.drawLine(w, self.height(), w + 5, self.height() - 5)
def propertyChanged(self, propertyName, oldValue, newValue):
if propertyName == 'autoSize':
self.layout().removeItem(self.layoutItem)
if self['direction'] == 'horizontal':
x = self['fixedSize']
y = 10
else:
x = 10
y = self['fixedSize']
if self['direction'] == 'horizontal':
if newValue:
xs = QSizePolicy.Expanding
else:
xs = QSizePolicy.Fixed
ys = QSizePolicy.Fixed
else:
xs = QSizePolicy.Fixed
if newValue:
ys = QSizePolicy.Expanding
else:
ys = QSizePolicy.Fixed
self.layoutItem = QSpacerItem(x, y, xs, ys)
self.layout().addItem(self.layoutItem)
self.setSizePolicy(xs, ys)
self.updateGeometry()
elif propertyName == 'fixedSize':
if newValue < 10:
self.getProperty('fixedSize').setValue(10)
#force refresh
self['autoSize'] = self['autoSize']
elif propertyName == 'direction':
self['autoSize'] = self['autoSize']
self.update()