| 92 | | self.heights.append( |
|---|
| 93 | | extents.overall_ascent + extents.overall_descent + 2) |
|---|
| | 99 | height = extents.overall_ascent + extents.overall_descent + 2 |
|---|
| | 100 | # if we don't have enough space for the current item, we cut |
|---|
| | 101 | # the menu, and append a "Plus..." submenu at the first part |
|---|
| | 102 | # with the rest of the menu |
|---|
| | 103 | if not ((i + 1 == len(self.elements) and |
|---|
| | 104 | height + self.height < screen_height) or |
|---|
| | 105 | height + self.height + plus_height < screen_height): |
|---|
| | 106 | plus_index = i |
|---|
| | 107 | break |
|---|
| | 108 | self.heights.append(height) |
|---|
| | 109 | self.height += height |
|---|
| 95 | | self.height = sum(self.heights) |
|---|
| | 111 | # if we have to cut the menu, append the "Plus..." submenu |
|---|
| | 112 | if plus_index > -1: |
|---|
| | 113 | sub_elements = self.elements[plus_index:] |
|---|
| | 114 | self.elements = self.elements[:plus_index] |
|---|
| | 115 | self.elements.append( |
|---|
| | 116 | ('Plus... >', Menu.sub_menu, |
|---|
| | 117 | lambda menu, x, y: Menu(self.wm, parent=self, |
|---|
| | 118 | x=x, y=y, |
|---|
| | 119 | elements=sub_elements))) |
|---|
| | 120 | self.heights.append(plus_height) |
|---|
| | 121 | self.height += plus_height |
|---|
| | 122 | self.width = max(self.width, plus_extents.overall_width) |
|---|
| | 123 | # if menu going out of the bottom of screen, enhance it |
|---|
| | 124 | if self.height + self.y >= screen_height: |
|---|
| | 125 | self.y = screen_height - self.height - 1 |
|---|