Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 1 | # A FormSplit lets you place its children exactly where you want them |
| 2 | # (including silly places!). |
| 3 | # It does no explicit geometry management except moving its children |
| 4 | # when it is moved. |
| 5 | # The interface to place children is as follows. |
| 6 | # Before you add a child, you may specify its (left, top) position |
| 7 | # relative to the FormSplit. If you don't specify a position for |
| 8 | # a child, it goes right below the previous child; the first child |
| 9 | # goes to (0, 0) by default. |
| 10 | # NB: This places data attributes named form_* on its children. |
| 11 | # XXX Yes, I know, there should be options to do all sorts of relative |
| 12 | # placement, but for now this will do. |
| 13 | |
| 14 | from Split import Split |
| 15 | |
Guido van Rossum | ce08448 | 1991-12-26 13:06:29 +0000 | [diff] [blame] | 16 | class FormSplit(Split): |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 17 | # |
| 18 | def create(self, parent): |
| 19 | self.next_left = self.next_top = 0 |
| 20 | self.last_child = None |
| 21 | return Split.create(self, parent) |
| 22 | # |
Guido van Rossum | cadae0f | 1991-08-16 13:16:25 +0000 | [diff] [blame] | 23 | def getminsize(self, (m, sugg_size)): |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 24 | max_width, max_height = 0, 0 |
| 25 | for c in self.children: |
Guido van Rossum | cadae0f | 1991-08-16 13:16:25 +0000 | [diff] [blame] | 26 | c.form_width, c.form_height = c.getminsize(m, (0, 0)) |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 27 | max_width = max(max_width, c.form_width + c.form_left) |
Guido van Rossum | cadae0f | 1991-08-16 13:16:25 +0000 | [diff] [blame] | 28 | max_height = max(max_height, \ |
| 29 | c.form_height + c.form_top) |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 30 | return max_width, max_height |
| 31 | # |
| 32 | def getbounds(self): |
| 33 | return self.bounds |
| 34 | # |
| 35 | def setbounds(self, bounds): |
| 36 | self.bounds = bounds |
| 37 | fleft, ftop = bounds[0] |
| 38 | for c in self.children: |
| 39 | left, top = c.form_left + fleft, c.form_top + ftop |
| 40 | right, bottom = left + c.form_width, top + c.form_height |
| 41 | c.setbounds((left, top), (right, bottom)) |
| 42 | # |
| 43 | def placenext(self, (left, top)): |
| 44 | self.next_left = left |
| 45 | self.next_top = top |
| 46 | self.last_child = None |
| 47 | # |
| 48 | def addchild(self, child): |
| 49 | if self.last_child: |
| 50 | width, height = \ |
Guido van Rossum | cadae0f | 1991-08-16 13:16:25 +0000 | [diff] [blame] | 51 | self.last_child.getminsize(self.beginmeasuring(), \ |
| 52 | (0, 0)) |
Guido van Rossum | 2d844d1 | 1991-04-07 13:41:50 +0000 | [diff] [blame] | 53 | self.next_top = self.next_top + height |
| 54 | child.form_left = self.next_left |
| 55 | child.form_top = self.next_top |
| 56 | Split.addchild(self, child) |
| 57 | self.last_child = child |
| 58 | # |