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() |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 31 | |
Terry Jan Reedy | df9b032 | 2019-05-27 19:16:46 -0400 | [diff] [blame^] | 32 | # The constants below for Windows and Mac Aqua are visually determined |
| 33 | # to avoid taskbar or menubar and app icons. |
| 34 | newy, bot_y = ((0, 72) if sys.platform == 'win32' else |
| 35 | (22, 88) if macosx.isAquaTk() else |
| 36 | (0, 88) ) # Guess for anything else. |
| 37 | newheight = newheight - newy - bot_y |
| 38 | newgeom = '' if height >= newheight else f"{width}x{newheight}+{x}+{newy}" |
David Scherer | 7aced17 | 2000-08-15 01:13:23 +0000 | [diff] [blame] | 39 | top.wm_geometry(newgeom) |
Cheryl Sabella | c1b4b0f | 2018-12-22 01:25:45 -0500 | [diff] [blame] | 40 | return newgeom != "" |
Terry Jan Reedy | 4d92158 | 2018-06-19 19:12:52 -0400 | [diff] [blame] | 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |
| 44 | from unittest import main |
| 45 | main('idlelib.idle_test.test_zoomheight', verbosity=2, exit=False) |
| 46 | |
| 47 | # Add htest? |