BoxParent.py 1.13 KB
Newer Older
Guido van Rossum's avatar
Guido van Rossum committed
1 2
from TransParent import TransParent

Guido van Rossum's avatar
Guido van Rossum committed
3
class BoxParent(TransParent):
Guido van Rossum's avatar
Guido van Rossum committed
4
	#
5
	def create(self, parent, (dh, dv)):
Guido van Rossum's avatar
Guido van Rossum committed
6 7 8 9 10
		self = TransParent.create(self, parent)
		self.dh = dh
		self.dv = dv
		return self
	#
11
	def getminsize(self, m, (width, height)):
Guido van Rossum's avatar
Guido van Rossum committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
		width = max(0, width - 2*self.dh)
		height = max(0, height - 2*self.dv)
		width, height = self.child.getminsize(m, (width, height))
		return width + 2*self.dh, height + 2*self.dv
	#
	def setbounds(self, bounds):
		(left, top), (right, bottom) = bounds
		self.bounds = bounds
		left = min(right, left + self.dh)
		top = min(bottom, top + self.dv)
		right = max(left, right - self.dh)
		bottom = max(top, bottom - self.dv)
		self.innerbounds = (left, top), (right, bottom)
		self.child.setbounds(self.innerbounds)
	#
	def getbounds(self):
		return self.bounds
	#
30
	def draw(self, d, area):
Guido van Rossum's avatar
Guido van Rossum committed
31 32 33 34 35 36
		(left, top), (right, bottom) = self.bounds
		left = left + 1
		top = top + 1
		right = right - 1
		bottom = bottom - 1
		d.box((left, top), (right, bottom))
37
		TransParent.draw(self, d, area) # XXX clip to innerbounds?
Guido van Rossum's avatar
Guido van Rossum committed
38 39 40
	#
	# XXX should scroll clip to innerbounds???
	# XXX currently the only user restricts itself to child's bounds