-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVerticalBoxView.py
96 lines (72 loc) · 2.59 KB
/
VerticalBoxView.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
# Copyright (C) 2009-2011 AG Projects. See LICENSE for details.
#
from Foundation import (NSView,
NSHeight,
NSZeroSize,
NSWidth)
from AppKit import NSRectFill
from PreferenceOptions import NightVolumeOption
class VerticalBoxView(NSView):
def initWithFrame_(self, frame):
self = super(VerticalBoxView, self).initWithFrame_(frame)
if self:
self.background_color = None
self.spacing = 0
self.border = 0
return self
def setSpacing_(self, spacing):
self.spacing = spacing
def setBorderWidth_(self, border):
self.border = border
def didAddSubview_(self, subview):
self.relayout()
def isFlipped(self):
return True
def setBackgroundColor_(self, color):
self.background_color = color
self.setNeedsDisplay_(True)
def drawRect_(self, rect):
if self.background_color:
self.background_color.set()
NSRectFill(rect)
def minimumHeight(self):
h = self.spacing * (self.subviews().count()-1) + 2 * self.border
for view in self.subviews():
h += NSHeight(view.frame())
return h
def relayout(self):
self.resizeWithOldSuperviewSize_(NSZeroSize)
def resizeWithOldSuperviewSize_(self, oldSize):
sview = self.enclosingScrollView()
frame = self.frame()
if sview:
width = sview.contentSize().width
else:
width = NSWidth(frame) - 2 * self.border
expandCount = 0
minimumHeight = self.minimumHeight()
for view in self.subviews():
if hasattr(view, "expand"):
expandCount += 1
expandedHeight= 0
if expandCount > 0:
expandedHeight= (NSHeight(frame) - minimumHeight) / expandCount
y = self.border
for view in self.subviews():
rect = view.frame()
# position NightVolumeOption to the right of Inbound Ringtone view
if type(view) is NightVolumeOption:
rect.origin.x = 230
rect.origin.y = self.border
else:
rect.origin.x = self.border
rect.origin.y = y
y += NSHeight(rect) + self.spacing
rect.size.width = width
if hasattr(view, "expand"):
rect.size.height = expandedHeight
view.setFrame_(rect)
if sview:
frame.size.width = sview.contentSize().width
frame.size.height = minimumHeight
self.setFrame_(frame)