wohlganger | 58fc71c | 2017-09-10 16:19:47 -0500 | [diff] [blame] | 1 | "Zoom a window to maximum height." |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 2 | |
| 3 | import re |
| 4 | import sys |
Guido van Rossum | 36e0a92 | 2007-07-20 04:05:57 +0000 | [diff] [blame] | 5 | |
Terry Jan Reedy | 6fa5bdc | 2016-05-28 13:22:31 -0400 | [diff] [blame] | 6 | from idlelib import macosx |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 7 | |
Terry Jan Reedy | bfbaa6b | 2016-08-31 00:50:55 -0400 | [diff] [blame] | 8 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 9 | class ZoomHeight: |
| 10 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 11 | def __init__(self, editwin): |
| 12 | self.editwin = editwin |
| 13 | |
Terry Jan Reedy | 4d92158 | 2018-06-19 19:12:52 -0400 | [diff] [blame] | 14 | def zoom_height_event(self, event=None): |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 15 | top = self.editwin.top |
| 16 | zoom_height(top) |
Serhiy Storchaka | 213ce12 | 2017-06-27 07:02:32 +0300 | [diff] [blame] | 17 | return "break" |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 18 | |
Terry Jan Reedy | bfbaa6b | 2016-08-31 00:50:55 -0400 | [diff] [blame] | 19 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 20 | def zoom_height(top): |
| 21 | geom = top.wm_geometry() |
| 22 | m = re.match(r"(\d+)x(\d+)\+(-?\d+)\+(-?\d+)", geom) |
| 23 | if not m: |
| 24 | top.bell() |
| 25 | return |
| 26 | width, height, x, y = map(int, m.groups()) |
| 27 | newheight = top.winfo_screenheight() |
| 28 | if sys.platform == 'win32': |
| 29 | newy = 0 |
| 30 | newheight = newheight - 72 |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 31 | |
Terry Jan Reedy | 6fa5bdc | 2016-05-28 13:22:31 -0400 | [diff] [blame] | 32 | elif macosx.isAquaTk(): |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 33 | # The '88' below is a magic number that avoids placing the bottom |
| 34 | # of the window below the panel on my machine. I don't know how |
| 35 | # to calculate the correct value for this with tkinter. |
| 36 | newy = 22 |
| 37 | newheight = newheight - newy - 88 |
| 38 | |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 39 | else: |
Kurt B. Kaiser | d0e2926 | 2002-12-20 01:22:01 +0000 | [diff] [blame] | 40 | #newy = 24 |
| 41 | newy = 0 |
| 42 | #newheight = newheight - 96 |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 43 | newheight = newheight - 88 |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 44 | if height >= newheight: |
| 45 | newgeom = "" |
| 46 | else: |
| 47 | newgeom = "%dx%d+%d+%d" % (width, newheight, x, newy) |
| 48 | top.wm_geometry(newgeom) |
Terry Jan Reedy | 4d92158 | 2018-06-19 19:12:52 -0400 | [diff] [blame] | 49 | |
| 50 | |
| 51 | if __name__ == "__main__": |
| 52 | from unittest import main |
| 53 | main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False) |
| 54 | |
| 55 | # Add htest? |