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