Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def splitTop(self, amount):
"""Split a rectangle off of the top side of this one,
returning a (top, remaining) tuple.
"""
return (Rect(self.x, self.y, self.width, amount),
Rect(self.x, self.y + amount, self.width, self.height - amount))
# then remove all widgets from the lowest priority line.
lineprios = []
for line in layoutLines.itervalues():
total = 0
for widget in line.widgets:
total += widget.priority
lineprios.append((total, line))
lineprios.sort()
for widget in lineprios[0][1].widgets:
widgets.remove(widget)
return False
# Sort the layout lines, and assign each a rectangle
lineKeys = layoutLines.keys()
lineKeys.sort()
remaining = Rect(0, 0, self.width, self.height)
for y in lineKeys:
line = layoutLines[y]
if y < 0:
line.rect, remaining = remaining.splitTop(line.height)
lineKeys.reverse()
for y in lineKeys:
line = layoutLines[y]
if y > 0:
line.rect, remaining = remaining.splitBottom(line.height)
if 0 in lineKeys:
layoutLines[0].rect = remaining
# Lay out the widgets on each line
self.widgetRects = {}
for line in lineKeys:
layoutLines[line].layout(self.widgetRects)
def splitBottom(self, amount):
"""Split a rectangle off of the bottom side of this one,
returning a (bottom, remaining) tuple.
"""
return (Rect(self.x, self.y + self.height - amount, self.width, amount),
Rect(self.x, self.y, self.width, self.height - amount))
def splitLeft(self, amount):
"""Split a rectangle off of the left side of this one,
returning a (left, remaining) tuple.
"""
return (Rect(self.x, self.y, amount, self.height),
Rect(self.x + amount, self.y, self.width - amount, self.height))
def splitRight(self, amount):
"""Split a rectangle off of the right side of this one,
returning a (right, remaining) tuple.
"""
return (Rect(self.x + self.width - amount, self.y, amount, self.height),
Rect(self.x, self.y, self.width - amount, self.height))
def splitLeft(self, amount):
"""Split a rectangle off of the left side of this one,
returning a (left, remaining) tuple.
"""
return (Rect(self.x, self.y, amount, self.height),
Rect(self.x + amount, self.y, self.width - amount, self.height))
def splitTop(self, amount):
"""Split a rectangle off of the top side of this one,
returning a (top, remaining) tuple.
"""
return (Rect(self.x, self.y, self.width, amount),
Rect(self.x, self.y + amount, self.width, self.height - amount))
def splitRight(self, amount):
"""Split a rectangle off of the right side of this one,
returning a (right, remaining) tuple.
"""
return (Rect(self.x + self.width - amount, self.y, amount, self.height),
Rect(self.x, self.y, self.width - amount, self.height))