David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 1 | # Sample extension: zoom a window to maximum height |
| 2 | |
| 3 | import re |
| 4 | import sys |
Ronald Oussoren | 19302d9 | 2006-06-11 14:33:36 +0000 | [diff] [blame^] | 5 | import macosxSupport |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 6 | |
| 7 | class ZoomHeight: |
| 8 | |
| 9 | menudefs = [ |
| 10 | ('windows', [ |
| 11 | ('_Zoom Height', '<<zoom-height>>'), |
| 12 | ]) |
| 13 | ] |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 14 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 15 | def __init__(self, editwin): |
| 16 | self.editwin = editwin |
| 17 | |
| 18 | def zoom_height_event(self, event): |
| 19 | top = self.editwin.top |
| 20 | zoom_height(top) |
| 21 | |
| 22 | def zoom_height(top): |
| 23 | geom = top.wm_geometry() |
| 24 | m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom) |
| 25 | if not m: |
| 26 | top.bell() |
| 27 | return |
| 28 | width, height, x, y = map(int, m.groups()) |
| 29 | newheight = top.winfo_screenheight() |
| 30 | if sys.platform == 'win32': |
| 31 | newy = 0 |
| 32 | newheight = newheight - 72 |
Ronald Oussoren | 19302d9 | 2006-06-11 14:33:36 +0000 | [diff] [blame^] | 33 | |
| 34 | elif macosxSupport.runningAsOSXApp(): |
| 35 | # The '88' below is a magic number that avoids placing the bottom |
| 36 | # of the window below the panel on my machine. I don't know how |
| 37 | # to calculate the correct value for this with tkinter. |
| 38 | newy = 22 |
| 39 | newheight = newheight - newy - 88 |
| 40 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 41 | else: |
Kurt B. Kaiser | d0e2926 | 2002-12-20 01:22:01 +0000 | [diff] [blame] | 42 | #newy = 24 |
| 43 | newy = 0 |
| 44 | #newheight = newheight - 96 |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 45 | newheight = newheight - 88 |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 46 | if height >= newheight: |
| 47 | newgeom = "" |
| 48 | else: |
| 49 | newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy) |
| 50 | top.wm_geometry(newgeom) |